jeppers Posted January 1, 2009 Share Posted January 1, 2009 i am not sure if the update query i am using is correct as i am not able to find the error any chance you coul have a look $result = mysql_query($query)or die(mysql_error());; if (mysql_num_rows($result) == 0) { // make query $query = "UPDATE menu SET title='$t', description='$t', price='$p' AS f, food_associations AS fa WHERE f.food_id = fa.food_id AND food_cat_id=$id"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()==1) {// if ran ok //print message echo '<h1> Edit Food</h1> <p>The food has been updatted</p><p><br /><br /></p>'; all help welcome Link to comment https://forums.phpfreaks.com/topic/139113-is-this-update-script-correct/ Share on other sites More sharing options...
bubbasheeko Posted January 1, 2009 Share Posted January 1, 2009 I started a response to this and then I started to wonder if the syntax of your update was correct. What is the update script doing here? Link to comment https://forums.phpfreaks.com/topic/139113-is-this-update-script-correct/#findComment-727585 Share on other sites More sharing options...
jeppers Posted January 1, 2009 Author Share Posted January 1, 2009 i have 2 tables which need to be updated 1 called food and another food_associations. i want to update the fields in both so when the user views the info they will see there update. sorry i am very tired i will show you the whole script <?php require_once ('mysql_connect.php'); //connect to the database // check the form has been submitted if (isset($_POST['submitted'])) { //check for title if (!empty($_POST['title'])) { $t = ($_POST['title']); } else { $t = FALSE; echo '<p><font color="red">Please enter a food name.</font></p>'; } //check for food description if (!empty($_POST['description'])) { $d =($_POST['description']); } else { $d = FALSE; echo '<p><font color="red">Please enter a description of the food.</font></p>'; } //check for food category if (isset($_POST['types']) && (is_array($_POST['types']))) { $type = TRUE; } else { $type = FALSE; echo '<p><font color="red"> Please select one category.</font></p>'; } //check food price if (!empty($_POST['price'])) { $p = ($_POST['price']); } else { $p = FALSE; echo '<p><font color="red">Please enter a price</font></p>'; } $result = mysql_query($query)or die(mysql_error());; if (mysql_num_rows($result) == 0) { // make query $query = "UPDATE menu SET title='$t', description='$t', price='$p' AS f, food_associations AS fa WHERE f.food_id = fa.food_id AND food_cat_id=$id"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_affected_rows()==1) {// if ran ok //print message echo '<h1> Edit Food</h1> <p>The food has been updatted</p><p><br /><br /></p>'; } else { //if it did not run ok echo '<h1> System error</h1> <p>Sorry there has been a system error and the food could not be updated. sorry</p>'; echo '<p>' . mysql_error() .'<br /><br />Problem:' . $query . '</p>';// debugging message //include ('footer.php') exit(); } } else { //report the errors echo '<h1>Error!</h1> <p>The follow errors have occurred:<br />'; foreach ($errors as $msg){//print each message echo "-$msg<br />\n"; } echo'</p><p>Please try again.</p><p><br /></p>'; }//end of if } //always show the form //retrive the users information $query = "SELECT f.food_id, title, description, price FROM foods AS f, food_associations AS fa WHERE f.food_id = fa.food_id AND fa.food_cat_id=$type"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 1){//valid id show form //get the users information $row = mysql_fetch_array($result, MYSQL_NUM); //create the form echo '<h2> Edit Food. <form action="edit_food.php" method="post"> <p>Title: <input type="text" name="title" size="20" maxlength="20" value="". $row[0] ."" /></p> <p>Description: <input type="text" name="description" size="15" maxlength="30" value="' . $row[1] . '" /></p> <p>Price: <input type="text" name="price" size="20" maxlength="40" value="' . $row[2] . '" /> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } else { // Not a valid user ID. echo '<h1>Page Error</h1> <p>This page has been accessed in error.</p><p><br /><br /></p>'; } mysql_close(); // Close the database connection. ?> i want it to display the info that they are tring to change and then once its changed to update the database. Link to comment https://forums.phpfreaks.com/topic/139113-is-this-update-script-correct/#findComment-727592 Share on other sites More sharing options...
jeppers Posted January 1, 2009 Author Share Posted January 1, 2009 please can anyone help. Link to comment https://forums.phpfreaks.com/topic/139113-is-this-update-script-correct/#findComment-727620 Share on other sites More sharing options...
bubbasheeko Posted January 4, 2009 Share Posted January 4, 2009 I may have a solution....but I need to see both tables. Link to comment https://forums.phpfreaks.com/topic/139113-is-this-update-script-correct/#findComment-729064 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.