gpt4 book ai didi

PHP MYSQL 插入命令不起作用

转载 作者:行者123 更新时间:2023-11-29 14:02:09 26 4
gpt4 key购买 nike

我正在努力处理这段代码。为什么不起作用?它确实接收了变量,但 sql 命令不起作用。

 if ($action=='create')
{

$Surname=$_REQUEST['Surname'];
$Name=$_REQUEST['Name'];
$Fathername=$_REQUEST['Fathername'];
$Dateofbirth=$_REQUEST['Dateofbirth'];
$Afm=$_REQUEST['Afm'];
$Landline=$_REQUEST['landline'];
$Mobile=$_REQUEST['Mobile'];
$Address=$_REQUEST['Adrs'];
$Addressnum=$_REQUEST['Adrsnm'];
$Location=$_REQUEST['Location'];
$ZIP=$_REQIEST['Zip'];
$Bankaccount=$_REQUEST['Bankaccount'];

$createuser=mysql_query("INSERT INTO `Customers` (`Surname`,`CName`,`Fathername`,`Birthdate`,`AFM`,`Landline`,`Mobile`,`Address`,`Adressnum`,`Location`,`ZIP`,`Bankaccount`) VALUES ('$Surname','$Name','$Fathername','$Dateofbirth','$Afm','$Landline','$Mobile','$Address','$Addressnum','$Location','$ZIP','$Bankaccount')");
}

最佳答案

mysql_query("INSERT INTO `Customers` (`Surname`,`CName`,`Fathername`,`Birthdate`,`AFM`,`Landline`,`Mobile`,`Address`,`Adressnum`,`Location`,`ZIP`,`Bankaccount`) VALUES ('$Surname','$Name','$Fathername','$Dateofbirth','$Afm','$Landline','$Mobile','$Address','$Addressnum','$Location',
'$ZIP','$Bankaccount')")or die(mysql_error());

会给你答案。

并确保转义您的数据:

 $Surname=mysql_real_escape_string($_REQUEST['Surname']);
$Name=mysql_real_escape_string($_REQUEST['Name']);
$Fathername=mysql_real_escape_string($_REQUEST['Fathername']);
[...]

更好的是,使用准备好的语句:

$q =  $sql->prepare("INSERT INTO `Customers` SET `Surname` = ? [...]");
$q->execute( array( $_REQUEST['Surname'], [...] ) );

关于PHP MYSQL 插入命令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14905208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com