please i am trying to update a database,firstly i want a form to loop through the database so as to show the present value, and make it editable(which i have done)but after the value has been changed and the form is submited , the database is not updated, the form code and update code is below
form
[php]<?php require_once("include/session.php");?>
<?php require_once("include/dataconnect.php");?>
<?php require_once("include/functions.php");?>
<?php include("include/basicheader.php");?>
"Your account"<?php echo $_SESSION['username'];?>
|
shopping list
<?php
$submit = $_POST['Add'];
//form data
$Sname = mysql_real_escape_string(htmlentities(strip_tags($_POST[‘Sname’])));
$Pname = mysql_real_escape_string(htmlentities(strip_tags($_POST[‘Pname’])));
$Pidno = mysql_real_escape_string(htmlentities(strip_tags($_POST[‘Pidno’])));
$Psize = mysql_real_escape_string(htmlentities(strip_tags($_POST[‘Psize’])));
$Pcolour = mysql_real_escape_string(htmlentities(strip_tags($_POST[‘Pcolour’])));
$Pquantity = $_POST[‘Pquantity’];
$Weblink = mysql_real_escape_string(htmlentities(strip_tags($_POST[‘Weblink’])));
$Price = mysql_real_escape_string(htmlentities(strip_tags($_POST[‘Price’])));
$date = date(“Y-m-d”);
//echo " (’’,’$Sname’,’$Pname’,’$Pidno’,’$Psize’,’$Pcolour’,’$Pquantity’,’$Weblink’,’$Price’,’$Uname’)";
if(‘POST’ === $_SERVER[‘REQUEST_METHOD’])
{
if ($Sname&&$Pname&&$Pidno&&$Weblink&&$Price)
{
if (is_numeric($Price))
{
$queryreg = mysql_query("
INSERT INTO repplac VALUES (’’,’$Sname’,’$Pname’,’$Pidno’,’$Psize’,’$Pcolour’,’$Pquantity’,’$Weblink’,’$Price’,’$date’,’{$_SESSION[‘username’]}’)
");
}
else
echo ‘price field requires numbers’;
}
else
echo 'please fill in all required * fields ';
}
?>
* Shop name
* Product name
* Product id no /ad reference
Product size
Product colour
Product quantity
1
2
3
4
5
6
7
8
9
10
* Web link
* Price GBP
<div class='buttonarea'>
<p>
<input type='submit' name='submit' value='Add'>
</p>
</div>
</p>
</form>
bookmarks
<?php
// Output start of table and form
echo "
SHOP NAME |
PRODUCT NAME |
PRODUCT SIZE |
PRODUCT COLOUR |
PRODUCT QUANTITY |
PRICE |
|
";
// Get DB results and loop, outputting table rows with counter
$pplresult = mysql_query("SELECT * FROM repplac") or die(mysql_error());
for ($i = 0; $row = mysql_fetch_assoc($pplresult); $i++) {
echo "
".htmlspecialchars($row['Sname'])." |
".htmlspecialchars($row['Pname'])." |
".htmlspecialchars($row['Psize'])." |
".htmlspecialchars($row['Pcolour'])." |
|
".htmlspecialchars($row['Price'])." |
delete |
";
}
// Close table and form
echo "
";
?>
<?php include("include/footer.php");?>[/php]
update code
[php]
<?php
require_once("include/session.php");
require_once("include/dataconnect.php");
require_once("include/functions.php");
if(array_key_exists('item', $_POST)){
$items = $_POST['item'];
//Loop through $_POST items, updating the database for each item
foreach ($items as $item) {
echo $item[0] . "\n";
$Pquantity = intval($item[0]);
echo $Pquantity;exit;
$Pidno = intval($item[1]);
$queryreg ="
UPDATE repplac
SET Pquantity = {$Pquantity}
WHERE
Pidno = {$Pidno}
AND
Uname = '{$_SESSION['username']}'
";
mysql_query($queryreg) or die(mysql_error());
}
//Get Email Address
$emails = mysql_query("SELECT reusers.email FROM reusers INNER JOIN repplac ON reusers.username = repplac.Uname AND reusers.username = '{$_SESSION['username']}'")or die(mysql_error());
//$emails = mysql_query("SELECT reusers.email FROM reusers INNER JOIN repplac ON reusers.username = repplac.Uname AND reusers.username = '".$_SESSION['username']."'")or die(mysql_error());
$results = (mysql_fetch_assoc($emails)) or die(mysql_error());
$email= $results['email'];
//echo "$email";
//die();
if(mysql_num_rows($emails) == 0){
exit("No email addresses found for user '{$_SESSION['username']}'");
}
$email = mysql_result($emails, 0);
//Get list to email user
$list = '';
$pplresult = mysql_query("SELECT * FROM repplac");
while($row = mysql_fetch_assoc($pplresult)){
$list .= $row['Sname'] .$row['Pname'] .$row['Psize'] .$row['Pcolour'] .$row['Pquantity'] .$row['Price']."\n";
}
//Send email
$to = $email;
$subject = "YOUR ORDER LIST FROM REACHEASY";
$headers = "From:
[email protected]";
$body = "$list";
mail($to,$subject,$body,$headers);
//Transfer records to wishlist
$transfer = mysql_query("INSERT INTO wishlist (SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}')");
// Delete temporary records if the above query was successful:
if($transfer !== false){
$deletetable = mysql_query("DELETE FROM repplac WHERE Uname = '{$_SESSION['username']}'");
}
}
redirect_to('youraccount.php');
?>
[/php]