Array Problem
Posted: Mon Nov 03, 2003 7:17 am
Hey
I am having a problem with an array.
I have a restaurant advert that has 5 listing of it food that it offers.
THe database has 2 tables. One for the advert and one for the food menu
so e.g.
Advert table:
Advert_id = 233
Menu table
Menu_id 1, Advert_id = 233, item= chips, Price=1.00
Menu_id 2, Advert_id = 233, item=fish, Price 2.00
Adding into these tables work fine. THe problem I am having if i want to edit the food menu. I use input type to display the food items, so i can edit them, but when i click on "sumbit" button (change menu), it just updates the last record, but does not update the rest.
Hard to explain, code is below.
Hope someone can help me
Many thanks
I am having a problem with an array.
I have a restaurant advert that has 5 listing of it food that it offers.
THe database has 2 tables. One for the advert and one for the food menu
so e.g.
Advert table:
Advert_id = 233
Menu table
Menu_id 1, Advert_id = 233, item= chips, Price=1.00
Menu_id 2, Advert_id = 233, item=fish, Price 2.00
Adding into these tables work fine. THe problem I am having if i want to edit the food menu. I use input type to display the food items, so i can edit them, but when i click on "sumbit" button (change menu), it just updates the last record, but does not update the rest.
Hard to explain, code is below.
Code: Select all
<?php
<?php
ob_start();
//start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
//check to make sure the session variable is registered
if(session_is_registered('username')){
//the session variable is registered, the user is allowed to see anything that follows
}
else{
//the session variable isn't registered, send them back to the login page
header( "Location: ../../login/login.php" );
}
//get database info
require('../../../dbinfo.php');
//extra checking system
$checkuser="select member_id,member_type from members where username = '$username'";
$ch=mysql_query($checkuser,$db) or die ("Getting member info failed" . mysql_error());
while ($c = mysql_fetch_array($ch))
{
$id=$c["member_id"];
$member_type=$c["member_type"];
}
if ($id==$check && $member_type =="restaurant") {
//get advert info
$sql="select member_id,username from members where username = '$username'";
$rs=mysql_query($sql,$db);
while ($r = mysql_fetch_array($rs))
{
$member_id=$r["member_id"];
$advert="select advert_id from advert where member_id = '$member_id' and advert_id = '$ad'
order by date desc";
$ad=mysql_query($advert,$db)or die ("select failed" . mysql_error());
while ($a=mysql_fetch_array($ad))
{
$advert_id = $a['advert_id'];
}
}
//If the user clicks on the sumbit button check for the following
if (isset($_POST['submit'])){
$valid=true;
if ( !item | !$price )
{$errmsg.="You have a blank field.<br>"; $valid=false;}}
//if everything is filled in then update the database
if ($valid!=true)
{echo ( $errmsg.$form);} else {
$item=ucfirst($item);
$updatead="update menu set item = '$item'
, price = '$price'
where menu_id = '$menu_id'";
mysql_query($updatead,$db) or die ("Select Failed ");
if (mysql_affected_rows()==1){
header("location: ../restaurant_advert.php?check=$member_id"); }
else
{echo "You did not change any settings";}
}
?>
<table width="60%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr bgcolor="#9999FF">
<td width="79%"><strong>Menu</strong></td>
<td width="21%"><strong>Price</strong></td>
</tr>
<?php
//need to get the listing from the menu
$menu="select advert.advert_id, menu.menu_id,menu.advert_id, menu.item, menu.price from advert, menu
where advert.advert_id = menu.advert_id and advert.advert_id='$advert_id'";
$ms=mysql_query($menu,$db) or die ("select failed" . mysql_error());
while ($m=mysql_fetch_array($ms)) {
$item=$m["item"];
$price=$m["price"];
$menu_id=$m["menu_id"];
?>
<form name="menu" method="post" action="<?php $PHP_SELF ?>">
<tr>
<td><input type="hidden" name="menu_id" value="<?php echo $menu_id ?>">
<input type="text" name="item" value="<?php echo $item ; ?>" size="40" maxlength="59"></td>
<td>£<input type="text" name="price" value="<?php echo $price ; ?>" size="5"></td>
</tr>
<?php } ?>
</table>
<input type="submit" name="submit" value="Change list">
?>Hope someone can help me
Many thanks