chillininvt Posted June 15, 2007 Share Posted June 15, 2007 I dont know why this this update query wont execute. All the rest of the script works fine. When you get to the update query it will not execute. First one with the solution to the problem $10 paypal. if( isset($_POST['btnSubmit']) ) { $department_id = $_GET['department_id']; if( $department_id == "" ) { // ADD NEW Addition By Chillininvt@Yahoo.com // Insert New Department into cityhalldepartment table. mysql_query("INSERT INTO CityHallDepartment (department_name) VALUES ('" . $_POST['department_name'] . "');"); $departmentname = $_POST['department_name']; //If there is a value for department name in the post array do if($departmentname != NULL){ //Grab The insert id from the last query $departmentid = mysql_insert_id(); //Grab the insert id of the last query // Insert Values to Pagelocations Table mysql_query("INSERT INTO PageLocations (parentID, title, display, displayNavCMS, department_id) VALUES ('2', '$departmentname', '1', '1', '$departmentid');"); if(mysql_errno() != 0) { echo "INSERT INTO PageLocations<BR><BR>"; echo $sqlTemp . "<BR>"; echo "<BR><BR>" . mysql_errno() . ": " . mysql_error() . "<BR>\n"; exit; } $pageID = mysql_insert_id(); $page = "generalpage.php?page=".$pageID.""; mysql_query("UPDATE PageLocations SET location = '" .$page. "' WHERE id = '" . $pageID . "';"); //Insert values into the PageGeneric table mysql_query("INSERT INTO PageGeneric (pid, bannerID, title, subtitle, content, metadesc, layoutID) VALUES ('$pageID', '19', '$departmentname', 'This is Subtitle', 'Comming Soon', '$departmentname', '3');"); //error check if(mysql_errno() != 0) { echo "INSERT INTO PageGeneric<BR><BR>"; echo $sqlTemp . "<BR>"; echo "<BR><BR>" . mysql_errno() . ": " . mysql_error() . "<BR>\n"; exit; } Quote Link to comment https://forums.phpfreaks.com/topic/55682-solved-update-query-will-not-exectue/ Share on other sites More sharing options...
ShoeLace1291 Posted June 15, 2007 Share Posted June 15, 2007 Major syntax problems... Change mysql_query("UPDATE PageLocations SET location = '" .$page. "' WHERE id = '" . $pageID . "';"); to mysql_query("UPDATE PageLocations SET location='$page' WHERE id = '$pageID'"); No payment is required if this fixes your problem. Quote Link to comment https://forums.phpfreaks.com/topic/55682-solved-update-query-will-not-exectue/#findComment-275129 Share on other sites More sharing options...
chillininvt Posted June 15, 2007 Author Share Posted June 15, 2007 No that didnt work. Everything else works it will run all of the insert statements. The problem is that when I put the entry into the PageLocations table I need to grab the insert id then store that value back down into the same row of data in another column see This value here $page = "generalpage.php?page=".$pageID.""; needs to go into the Pagelocations table after its created. You cannot put it in before had because the value of page id connot be determined until the row its self is created. Essentially. What I need it to do is grab the insert id number and store in the the column locations Which house a value in this format generalpage.php?page=300 The page number is the equivelent to the value of the auto_increment column on the same row. Quote Link to comment https://forums.phpfreaks.com/topic/55682-solved-update-query-will-not-exectue/#findComment-275142 Share on other sites More sharing options...
trq Posted June 15, 2007 Share Posted June 15, 2007 This line.... $page = "generalpage.php?page=".$pageID.""; Has one too many " on the end. Have you got any error reporting switched on? That should throw a syntax error. As for your query, try some error catching / debugging. <?php $sql = "UPDATE PageLocations SET location = '" .$page. "' WHERE id = '" . $pageID . "';" if (mysql_query($sql)) { echo "Success"; } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } ?> You should always wrap your queries within an if statement to catch errors. Quote Link to comment https://forums.phpfreaks.com/topic/55682-solved-update-query-will-not-exectue/#findComment-275145 Share on other sites More sharing options...
chillininvt Posted June 15, 2007 Author Share Posted June 15, 2007 I tried that but this will not do anything with that. I dont get it. The code looks perfect. $pageID = mysql_insert_id(); echo "".$pageID.""; $page = "generalpage.php?page=".$pageID.""; $sql = "UPDATE PageLocations SET location = '" .$page. "' WHERE id = '" . $pageID . "';"; if (mysql_query($sql)) { echo "Success"; } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } Quote Link to comment https://forums.phpfreaks.com/topic/55682-solved-update-query-will-not-exectue/#findComment-275155 Share on other sites More sharing options...
chillininvt Posted June 15, 2007 Author Share Posted June 15, 2007 Ok I solved my own problem. Looks like the column id that that I was trying to check in the WHERE clause didnt exist and the column was actually PageID !!! DUH!!!! Quote Link to comment https://forums.phpfreaks.com/topic/55682-solved-update-query-will-not-exectue/#findComment-275163 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.