我不明白为什么这不更新我从文本输入接收到的数据:
include "config.php"
printf ("Update PriceList\n");
printf ("<form method=\"post\" action=\"price_red.php\">");
printf ("Select PhoneID: <input type = \"Text\" name = \"PhonID\"><br>");
printf ("PhoneName:<input type = \"Text\" name = \"PhoneName\"><br>");
printf ("PhoneType:<input type = \"Text\" name = \"PhoneType\"><br>");
printf ("ScreenType:<input type = \"Text\" name = \"ScreenType\"><br>");
printf ("Camera: <input type = \"Text\" name = \"Camera\"><br>");
printf ("Quantity: <input type = \"Text\" name = \"Quantity\"><br>");
printf ("Price:<input type = \"Text\" name = \"Price\"><br>");
printf ("Out of stock:<input type = \"Text\" name = \"outofstock\"><br>");
printf ("<input type=\"Submit\" name=\"submit\" value=\"Update\">");
printf ("</form>");
$sql = mysql_query("UPDATE PhonesPriceList SET PhoneName = '$PhoneName', Price = '$Price', Quantity = '$Quantity', Outofstock = '$outofstock' WHERE PhoneID = '$PhonID';");
$sql1 = mysql_query("UPDATE PhonesDetails SET PhoneType = '$PhoneType', ScreenType = '$ScreenType', Camera ='$Camera' WHERE PhoneID = '$PhonID';");
最佳答案
表单的数据不会自动转换为变量。数据应位于 $_POST[ 'name' ]
中,其中“name”是输入字段的名称属性。
请记住在使用传入数据进行任何数据库操作之前先对其进行清理(查找 mysql_real_escape_string()
)。
还有一个小提示:您可以回到纯 HTML,而不是使用 printf()
输出大块文本。代码看起来会干净得多。
include "config.php"
// go back to pure HTML
?>
Update PriceList
<form method="post" action="price_red.php">
...
<?php // back to PHP
关于php - 文本类型的输入不会在 mysql 表中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8388274/