问候好人,
我是使用php / mysql进行编码的新手,当我正在完成一项基本任务时,我遇到了将文本字段和复选框状态的值保存到mysql数据库的问题。
这是我能够做的,但我仍然无法在数据库中保存记录。
我做错了什么或我失踪了什么?
使用Macromedia Dreamweaver 8,Apache / 2.2.12(Win32)DAV / 2 mod_ssl / 2.2.12 OpenSSL / 0.9.8k mod_autoindex_color PHP / 5.3.0 mod_perl / 2.0.4 Perl / v5.10.0 MySQL客户端版本:5.1.37 PHP扩展:mysqli
$con = mysqli_connect("localhost", "root", "");
if (!$con) {
exit('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
if ($_POST['textfield'] == "") {
$FieldsEmpty= true;
}
else {
if ($FieldsEmpty) echo "Please enter all the fields<br/>";
}
if($_POST['Submit2'] == "Submit")
{
$VarName = $_POST['textfield'];
$VarOrg = $_POST['textfield2'];
$VarAddress = $_POST['textfield3'];
$VarPhone=$_POST ['textfield4'];
$VarEmail=$_POST['textfield5'];
$VarAccomodation=$_POST['checkbox'];
$VarEntertainment=$_POST['checkbox2'];
$VarTourOP=$_POST['checkbox3'];
$VarDomesticTourism=$_POST['checkbox4'];
$VarTourism=$_POST['checkbox5'];
$VarTravelmgt=$_POST['checkbox6'];
$VarSupport=$_POST['checkbox7'];
$VarMedia=$_POST['checkbox8'];
$VarDoc1=$_POST[$_FILES["file"]["name"]];
$VarDoc2=$_POST[$_FILES["file2"]["name"]];
$VarDoc3=$_POST[$_FILES["file3"]["name"]];
$Vardoc4=$_POST[$_FILES["file4"]["name"]];
$sql = "Insert into nominatons_tbl(name,org,address,phone,email,best_accomodation,best_entertainment,best_touroperator,best_domestictourism,best_tourism,best_travelmgt,best_support,best_media,doc1,doc2,doc3,doc4) VALUES (".PrepSQL($VarName) . ", " .PrepSQL($VarOrg) . ", " .PrepSQL($VarAddress) . ", " .PrepSQL($VarPhone) . ", " .PrepSQL($VarEmail) . ", " .PrepSQL($VarAccomodation) . ", " .PrepSQL($VarEntertainment) . ", " .PrepSQL($VarTourOP) . ", " .PrepSQL($VarDomesticTourism) . ", " .PrepSQL($VarTourism) . ", " .PrepSQL($VarTravelmgt) . ", " .PrepSQL($VarSupport) . ", " .PrepSQL($VarMedia) . ", " .PrepSQL($VarDoc1) . ", " .PrepSQL($VarDoc2) . ", " .PrepSQL($VarDoc3) . ", " .PrepSQL($Vardoc4) . ")";
mysql_query($sql);
echo "Nomination submited <br />";
}
function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
答案 0 :(得分:0)
保持这样的单引号
VALUES('“。。PrepSQL($ VarName)。”','“。PrepSQL($ VarOrg)。”');
答案 1 :(得分:0)
始终保持练习以进行此类查询。
$sql = "Insert into nominatons_tbl(`name`,`org`,`address`,`phone`,`email`,`best_accomodation`,`best_entertainment`,`best_touroperator`,`best_domestictourism`,`best_tourism`,`best_travelmgt`,`best_support`,`best_media`,`doc1`,`doc2`,`doc3`,`doc4`) VALUES
(".PrepSQL($VarName) . ", " .PrepSQL($VarOrg) . ", " .PrepSQL($VarAddress) . ", " .PrepSQL($VarPhone) . ", " .PrepSQL($VarEmail) . ", " .PrepSQL($VarAccomodation) . ", " .PrepSQL($VarEntertainment) . ", " .PrepSQL($VarTourOP) . ", " .PrepSQL($VarDomesticTourism) . ", " .PrepSQL($VarTourism) . ", " .PrepSQL($VarTravelmgt) . ", " .PrepSQL($VarSupport) . ", " .PrepSQL($VarMedia) . ", " .PrepSQL($VarDoc1) . ", " .PrepSQL($VarDoc2) . ", " .PrepSQL($VarDoc3) . ", " .PrepSQL($Vardoc4) . ")";