jeppers Posted January 1, 2009 Share Posted January 1, 2009 hi again i am working on the same script but trying to update instead of selecting. my problem is that i have 2x sql code and i am not sure if i am hedding down the correct road to victory. the first set of sql code is trying to update and i feel like i am not in corporating the 2 tables need to be updated. and the second is just trying to select the info to show the user. because there is two sets of code i am just not sure where the issues are: // 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); if (mysql_num_rows($result) == 0) { // make query $query = "UPDATE 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); please any advice will help thanks Link to comment https://forums.phpfreaks.com/topic/139112-solved-i-no-this-is-a-long-shot-but-maybe/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.