需要帮助将默认文本值插入mysql(need help inserting a default text value into mysql)
结束网络开发人员,我从另一个团队完成了CMS,我必须与我的前端链接。 我做了一些修改,但由于我缺乏PHP知识,我在这里有一些问题。
我的用户可以填写表单,其中1个文本字段要求他们的照片链接。 我想检查输入的值是否不等于我想要的,然后我将查询插入一个默认的头像照片链接到mysql进行处理。
我在php上试过的代码
// check if the variable $photo is empty, if it is, insert the default image link if($photo = ""){ $photo="images/avatarDefault.png"; }
似乎没有用
<?php if($_SERVER["REQUEST_METHOD"] === "POST") { //Used to establish connection with the database include 'dbAuthen.php'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } else { //Used to Validate User input $valid = true; //Getting Data from the POST $username = sanitizeInput($_POST['username']); $displayname = sanitizeInput($_POST['displayname']); $password = sanitizeInput($_POST['password']); //hash the password using Bcrypt - this is to prevent //incompatibility from using PASSWORD_DEFAULT when the default PHP hashing algorithm is changed from bcrypt $hashed_password = password_hash($password, PASSWORD_BCRYPT); //Determining Type of the User //if B - User is student //if A - User is adin if($_POST['type'] == 'true') $type = 'B'; else $type = 'A'; $email = sanitizeInput($_POST['email']); $tutorGroup = sanitizeInput($_POST['tutorGroup']); $courseID = sanitizeInput($_POST['courseID']); $description = sanitizeInput($_POST['desc']); $courseYear = date("Y"); $website = sanitizeInput($_POST['website']); $skillSets = sanitizeInput($_POST['skillSets']); $specialisation = sanitizeInput($_POST['specialisation']); $photo = sanitizeInput($_POST['photo']); // this is what i tried, checking if the value entered is empty, but doesn't work if($photo = ""){ $photo="images/avatarDefault.png"; } $resume = sanitizeInput($_POST['resume']); //Validation for Username $sql = "SELECT * FROM Users WHERE UserID= '$username'"; if (mysqli_num_rows(mysqli_query($con,$sql)) > 0){ echo 'User already exists! Please Change the Username!<br>'; $valid = false; } if($valid){ //Incomplete SQL Query $sql = "INSERT INTO Users VALUES ('$username','$displayname','$hashed_password','$type','$email', '$tutorGroup', "; //Conditionally Concatenate Values if(empty($courseID)) { $sql = $sql . "NULL"; } else { $sql = $sql . " '$courseID' "; } //Completed SQL Query $sql = $sql . ", '$description', '$skillSets', '$specialisation', '$website', '$courseYear', '$photo', '$resume', DEFAULT)"; //retval from the SQL Query if (!mysqli_query($con,$sql)) { echo '*Error*: '. mysqli_error($con); } else { echo "*Success*: User Added!"; } } //if student create folder for them if ($type == 'B') { //Store current reporting error $oldErrorReporting = error_reporting(); //Remove E_WARNING from current error reporting level to prevent users from seeing code error_reporting($oldErrorReporting ^ E_WARNING); //Set current reporting error(); error_reporting($oldErrorReporting); } mysqli_close($con); } } function sanitizeInput($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
我试图在mysql上找到一种方法来插入默认值,但似乎不可能,所以我别无选择,只能通过php查询插入。
我有逻辑,但我不知道如何在PHP上实现我缺乏知识,我想要检查1)如果照片链接没有单词.png / .jpg,
$photo != ".png"
2)如果照片链接长度太低$.photo.length < 10
有人可以帮助我查看代码并告诉我我做错了什么? 谢谢!
end web developer, i was given a CMS done from another team and i have to link with my front-end. I have made some modifications, but due to my lack of php knowledge i have some issue here.
My users are able to fill up a form, where 1 text field is asking for their photo link. I want to check for if the value entered is not equal to what i want, then i will query insert a default avatar photo link to mysql to process.
code that i tried on php
// check if the variable $photo is empty, if it is, insert the default image link if($photo = ""){ $photo="images/avatarDefault.png"; }
doesn't seem to work
<?php if($_SERVER["REQUEST_METHOD"] === "POST") { //Used to establish connection with the database include 'dbAuthen.php'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } else { //Used to Validate User input $valid = true; //Getting Data from the POST $username = sanitizeInput($_POST['username']); $displayname = sanitizeInput($_POST['displayname']); $password = sanitizeInput($_POST['password']); //hash the password using Bcrypt - this is to prevent //incompatibility from using PASSWORD_DEFAULT when the default PHP hashing algorithm is changed from bcrypt $hashed_password = password_hash($password, PASSWORD_BCRYPT); //Determining Type of the User //if B - User is student //if A - User is adin if($_POST['type'] == 'true') $type = 'B'; else $type = 'A'; $email = sanitizeInput($_POST['email']); $tutorGroup = sanitizeInput($_POST['tutorGroup']); $courseID = sanitizeInput($_POST['courseID']); $description = sanitizeInput($_POST['desc']); $courseYear = date("Y"); $website = sanitizeInput($_POST['website']); $skillSets = sanitizeInput($_POST['skillSets']); $specialisation = sanitizeInput($_POST['specialisation']); $photo = sanitizeInput($_POST['photo']); // this is what i tried, checking if the value entered is empty, but doesn't work if($photo = ""){ $photo="images/avatarDefault.png"; } $resume = sanitizeInput($_POST['resume']); //Validation for Username $sql = "SELECT * FROM Users WHERE UserID= '$username'"; if (mysqli_num_rows(mysqli_query($con,$sql)) > 0){ echo 'User already exists! Please Change the Username!<br>'; $valid = false; } if($valid){ //Incomplete SQL Query $sql = "INSERT INTO Users VALUES ('$username','$displayname','$hashed_password','$type','$email', '$tutorGroup', "; //Conditionally Concatenate Values if(empty($courseID)) { $sql = $sql . "NULL"; } else { $sql = $sql . " '$courseID' "; } //Completed SQL Query $sql = $sql . ", '$description', '$skillSets', '$specialisation', '$website', '$courseYear', '$photo', '$resume', DEFAULT)"; //retval from the SQL Query if (!mysqli_query($con,$sql)) { echo '*Error*: '. mysqli_error($con); } else { echo "*Success*: User Added!"; } } //if student create folder for them if ($type == 'B') { //Store current reporting error $oldErrorReporting = error_reporting(); //Remove E_WARNING from current error reporting level to prevent users from seeing code error_reporting($oldErrorReporting ^ E_WARNING); //Set current reporting error(); error_reporting($oldErrorReporting); } mysqli_close($con); } } function sanitizeInput($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
i've tried finding a way on mysql to insert default values but it seem impossible, so i have no choice but to query insert through php.
I have the logic but i'm not sure how to implement on the php with my lack of knowledge, i was thinking of checking either 1) if the photo link does not have the word .png/.jpg,
$photo != ".png"
2) if the photo link length is too low$.photo.length < 10
can someone help me look into the code and tell me what i'm doing wrong? Thanks!
原文:https://stackoverflow.com/questions/27100528
最满意答案
在XE7和XE8中如下
public { Public declarations } /// <comments>Some comments<para/>comments on a second line</comments> procedure SetUp;
在Help Insight弹出窗口的新行中将文本“注释放在第二行”。 一个小怪癖是第二行缩进了几个空格,但如果我这样做
/// <comments>Some comments<para>comments on a second line</para>third line</comments>
“第三行”没有缩进。 通过执行以下操作,可以屏蔽缩进不一致(以将所有内容缩进两个空格为代价):
///<comments><para>Some comments</para><para>comments on a second line</para><para>third</para></comments> procedure SetUp;
从实验来看,
<p/>
XML标记曾经在XE4中工作,但在XE7中停止工作,就像在我的初始测试中一样:
TForm1 = class(TForm) CDS: TClientDataSet; DataSource1: TDataSource; DBGrid1: TDBGrid; Button1: TButton; procedure CDSCalcFields(DataSet: TDataSet); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private ///<comments>Some comments<p/>more</comments> procedure AddHLIndex;
在XE4中,上面显示了XE4中新行的“more”,但与XE8中的“Some comments”在同一行。
我想知道XE8的差异是否与Castalia的存在有关,但是XE4和XE8之间的区别是XE8与/ NOCASTALIA开关一样。
我没有详尽地测试,但XE8忽略了我尝试过的所有“HTML”格式标签(除了
<c>
提问者提到的标签,当然可能是故意改变或意外的结果。 另一方面,它确实似乎处理HTML转义,如
>
和
<
但不幸的是,
,它只是忽略了。
In XE7 and XE8 the following
public { Public declarations } /// <comments>Some comments<para/>comments on a second line</comments> procedure SetUp;
puts the text 'comments on a second line' on a new line in the Help Insight pop-up. A minor quirk is the second line is indented a couple of spaces, but if I do
/// <comments>Some comments<para>comments on a second line</para>third line</comments>
the 'third line' isn't indented. The indentation inconsistency can by masked (at the expense of indenting everything by two spaces) by doing:
///<comments><para>Some comments</para><para>comments on a second line</para><para>third</para></comments> procedure SetUp;
Judging by experiments, the
<p/>
XML tag used to work in XE4, but stopped working by XE7, as in my initial test:
TForm1 = class(TForm) CDS: TClientDataSet; DataSource1: TDataSource; DBGrid1: TDBGrid; Button1: TButton; procedure CDSCalcFields(DataSet: TDataSet); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private ///<comments>Some comments<p/>more</comments> procedure AddHLIndex;
In XE4 the above displays the 'more' on a new line in XE4 but on the same line as 'Some comments' in XE8.
I wondered whether the difference in XE8 was anything to do with the presence of Castalia, but I get the same difference between XE4 and XE8 with XE8 started with the /NOCASTALIA switch.
I haven't tested exhaustively but XE8 ignores all the 'HTML' formatting tags I've tried (except the
<c>
tag mentioned by the questioner), which might be the result of a deliberate change or an accident, of course. On the other hand, it does seem to process HTML escapes such as
>
and
<
but not, unfortunately,
, which it just ignores.
相关问答
更多-
我相信,二进制文件不应该与其源代码一起存储在版本控制中。 缺点: 它鼓励大型项目中的糟糕构建实践。 最佳实践是完全自动化完整构建(不仅仅是源代码编译,还包括运行自动化测试,文档打包,设置等等)。 提交二进制文件使您能够忽略:“只需手动完成已更改部分的构建”。 更新和提交更慢 每次在构建完成后更新时都需要处理二进制文件的冲突 提交哪些更改源代码但不包含相应的二进制文件会导致开发人员混淆。 你如何检测出不匹配? svn update会更新你的二进制文件的时间戳,混淆你的构建工具会错误地认为二进制文件比源代码更新 ...
-
Javascript函数没有触发,控制台没有提供任何洞察力(Javascript function not firing and console not offering any insight)[2023-07-05]
尝试这个: $('.history-button').click(function() { graphShowHide('.BMI'); }); Try this: $('.history-button').click(function() { graphShowHide('.BMI'); }); -
是的,据我所知,这是预览。 请参阅https://dev.applicationinsights.io/ 。 Yes, but it is in preview as far as I know. See https://dev.applicationinsights.io/.
-
为什么在Eclipse STS上没有Grails和Groovy的代码洞察力?(Why no code insight for Grails and Groovy on Eclipse STS?)[2023-11-22]
我确信STS实际上可以为你做这件事,它基本上是它的Grails支持的全部内容。 你确定你已经安装了正确的插件吗? 关于这个主题的文档就在这里:[1]: http : //www.grails.org/STS+Integration 旁注:虽然STS做得不错,但我一直是IntelliJ IDEA Ultimate版的快乐用户,并且在切换后我再也没有回头看过eclipse :) I am sure that STS can in fact do this for you, it is basically wha ... -
看起来end_time需要设置为12AM PST / PDT(取决于夏令时)unix时间或查询返回空。 示例:1330588800 编辑:切换到'/ insights'并传递'since'参数,这里的时间并不严格。 Looks like end_time needs to set to 12AM PST/PDT (depending on daylights saving time) unix time exactly or the query returns empty. Example: 1330588 ...
-
个性见解需要至少100个单词才能工作。 但是在大约1,200个单词(IIRC)之前,你不会得到真正的见解。 它告诉你,你只提供了两个单词。 如果不是这种情况,请确保正确转义JSON数据。 Personality insights requires a minimum of 100 words to work. But you won’t get a true insight until around 1,200 words (IIRC). It’s telling you that you only sup ...
-
除非我误解了这个问题,否则您只需删除一个扩展名,并且可能需要一个nuget包。 卸载用于Visual Studio扩展的应用程序洞察工具,并删除应用程序Telemetry SDK for Services nuget软件包。 遥测包与Application Insights一起安装,但必须单独删除。 在我的经验中,如果您希望继续使用Application Insights的其他功能,则不需要遥测包。 删除遥测包将停止所有遥测记录,但应用洞察将继续报告非遥测信息。 Unless I'm misundersta ...
-
帮助洞察力的新线(New line in help insight)[2024-01-21]
在XE7和XE8中如下 public { Public declarations } ///Some comments procedure SetUp; 在Help Insight弹出窗口的新行中将文本“注释放在第二行”。 一个小怪癖是第二行缩进了几个空格,但如果我这样做 ///comments on a second line Some comments comments on a sec ... -
Francis-- 您的文件很可能在行结尾时遇到一些问题。 文件是否曾在Delphi以外的其他编辑器中打开过? 您可以这样检查:将所有代码复制到剪贴板上,将其粘贴到记事本中,将其全部复制到记事本中,然后将其粘贴回编辑器中。 这应该清理所有的行结束。 看看是否有所作为。 Francis-- It is very likely that your files have some issues with their line endings. Has the file ever been opened in an ...
-
MapQuest方向api中没有返回路由状态列表的函数。 但是如果stateBoundaryDisplay参数设置为true,则响应将包含机动文本中的“穿越内布拉斯加”等详细信息。 操纵器将按正确的顺序排列。 There is no function in the MapQuest directions api that returns a list of states for a route. But if the stateBoundaryDisplay parameter is set to true ...