Jump to content

Recommended Posts

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;
	}

Link to comment
https://forums.phpfreaks.com/topic/55682-solved-update-query-will-not-exectue/
Share on other sites

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.

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.

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.

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";
       }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.