Reputation: 3
I can't figure why this doesn't update my data, received from text inputs:
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';");
Upvotes: 0
Views: 593
Reputation: 913
try something like this . Just make sure you add the appropriate sanitation to prevent injection
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);
}
Upvotes: 0
Reputation: 33163
The form's data doesn't automatically get converted into variables. The data should be in $_POST[ 'name' ]
where "name" is the name attribute of the input field.
Remember to sanitize incoming data before doing any database operations with it (look up mysql_real_escape_string()
).
And a small tip: instead of using printf()
to output large blocks of text, you can drop back to pure HTML. The code will look much cleaner.
include "config.php"
// go back to pure HTML
?>
Update PriceList
<form method="post" action="price_red.php">
...
<?php // back to PHP
Upvotes: 1