我无法理解为什么这不会更新从文本输入中收到的数据:
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';");
答案 0 :(得分:1)
表单的数据不会自动转换为变量。数据应位于$_POST[ 'name' ]
,其中“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
答案 1 :(得分:0)
尝试这样的事情。只需确保添加适当的卫生设施以防止注射
include "config.php"
if(isset('submit'){
$Phoneid= $_POST['PhoneID'];
$Phone_name= $_POST['PhoneName'];
$Phone_type = $_POST['PhoneType'];
$screen_type= $_POST['ScreenType'];
$camera = $_POST['Camera'];
$Quantity = $_POST['Quantity'];
$price = $_POST['Price'];
$outofstock = $_POST['outofstock'];
$dbc = mysqli_connect( data info)
or die ('Error connecting');
$query = "UPDATE PhonesPriceList SET PhoneName = '$PhoneName', Price = '$price',
Quantity = '$Quantity', Outofstock = '$outofstock' WHERE PhoneID = '$PhonID' ";
msqli_query( $dbc, $query) or die (' failed to query');
echo ' Update successful';
mysqli_close($dbc);
}