Jump to content

why won't this update???


timmah1

Recommended Posts

I cannot figure out for the life of me why this isn't updating the database

 

if(isset($_POST['update1'])){

	$id1 = mysql_real_escape_string($_POST['id1']);
	$parentid = mysql_real_escape_string($_POST['parentid']);
	$title = mysql_real_escape_string($_POST['title']);

			$result1 = mysql_query("UPDATE subcat SET parentid='$parentid', name='$title' WHERE id='$id1'")
			or die(mysql_error()); 			

echo "<p>Sub Category <b><em>$title</em></b> has been updated</p>";
}

 

and here is the form

    <form action="page-subs.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <input name="id1" type="hidden" value="<?php echo $id; ?>">
    <table width="100%" border="0" cellspacing="0" cellpadding="5" class='table_border'>
    <tr>
      <td align="left" valign="top">Brand</td>
      <td align="left" valign="top"><input name="title" type="text" id="title" value="<?php echo $title; ?>" /></td>
    </tr>
    <tr>
      <td>Category</td>
      <td><select name="parentid" id="parentid" >
  <option>Please Select</option>
               <option value="<?php echo $parent; ?>" <?php if($parent=="1") { echo "selected"; }?>>Blubird</option>
               <option value="<?php echo $parent; ?>" <?php if($parent=="2") { echo "selected"; }?>>Carpenter</option>
               <option value="<?php echo $parent; ?>" <?php if($parent=="3") { echo "selected"; }?>>Thomas</option>
               <option value="<?php echo $parent; ?>" <?php if($parent=="4") { echo "selected"; }?>>Wayne</option>
               <option value="<?php echo $parent; ?>" <?php if($parent=="5") { echo "selected"; }?>>Inter-Amtran</option>
               <option value="<?php echo $parent; ?>" <?php if($parent=="6") { echo "selected"; }?>>Misc</option>
</select></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="update1" id="update1" value="Update Sub Catgegory" /></td>
    </tr>
    </table>
    </form>

 

I get this error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

Can anybody see what is wrong??

 

Thanks in advance

 

Link to comment
Share on other sites

You need to investigate what the actual query statement is that is failing. Form the query statement in a php variable and output it as part of the die() statement so that you can see exactly what the whole query is and exactly what is at the point where the error is being reported.

Link to comment
Share on other sites

I understand.

 

Tell me something, why when I comment everything out

if(isset($_POST['update1'])){

	//$id1 = mysql_real_escape_string($_POST['id1']);
	//$parentid = mysql_real_escape_string($_POST['parentid']);
	//$title = mysql_real_escape_string($_POST['title']);

			//$result1 = mysql_query("UPDATE subcat SET parentid='$parentid', name='$title' WHERE id='$id1'")
			//or die(mysql_error($result1)); 			

echo "<p>Sub Category <b><em>$title</em></b> has been updated</p>";
}

 

I get the same error?

Sub Category has been updated

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Link to comment
Share on other sites

Is that the entire code?

 

Did you remember to save and upload it if you need to do so?

Are you asking me if I saved and uploaded the file? Really?

No, you're imagining it.

 

Why do YOU think if you comment out a section of code it would still execute?

Link to comment
Share on other sites

Is that the entire code?

 

Did you remember to save and upload it if you need to do so?

 

Are you asking me if I saved and uploaded the file? Really?

No, you're imagining it.

 

Why do YOU think if you comment out a section of code it would still execute?

 

No, I don't think it would execute, I was just testing something out, and obviously that wasn't working.

I'm was trying to see if the $_POST was correct, and I'm seeing that it's not, if I'm getting the same error

Link to comment
Share on other sites

debuggin more is the only option.

 

var_dump($_POST);

 

move query to a variable

$strSql = "UPDATE subcat SET parentid='$parentid', name='$title' WHERE id='$id1'";
echo  $strSql;
$result1 = mysql_query($strSql) or die(mysql_error());

 

From the error it looks like one of the post variables are not set correctly.

 

 

Link to comment
Share on other sites

Thank you samshel,

the db is updating, but it still shows the error

UPDATE subcat SET parentid='2', name='MISCELLANEOUS REPAIR PARTS' WHERE id='103'
array(4) {
  ["id1"]=>
  string(3) "103"
  ["title"]=>
  string(26) "MISCELLANEOUS REPAIR PARTS"
  ["parentid"]=>
  string(1) "2"
  ["update"]=>
  string(20) "Update Sub Catgegory"
}
Sub Category MISCELLANEOUS REPAIR PARTS has been updated

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Link to comment
Share on other sites

If the var dump is of $_POST then the variables names are not matching.

 

you are checking for $_POST['update1'] and $_POST has update.

 

Also is the code you posted only code with query in your page?

 

Is there any query below the code which might be breaking?

Link to comment
Share on other sites

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.