Jump to content

Recommended Posts

Hi

 

I have a form, which i want to update a row's details in a mysql database

 

My form is:

 

			echo '<form action="save.php" name="insert_priority" METHOD="post">';
		echo '<table>';
		echo '<input type="hidden" name="briefed"'; {echo "value=\"" . $_POST['catid'] . "\"";}echo ' />';
		echo '<td><input class="briefed" type="text" name="briefed"'; if(isset($_POST['briefed'])){echo "value=\"" . $_POST['briefed'] . "\"";}echo ' /></td>';
		echo '<td><input class="job" type="text" name="job"'; if(isset($_POST['job'])){echo "value=\"" . $_POST['job'] . "\"";}echo ' /></td>';
		echo '<td><input class="category" type="text" name="category"'; if(isset($_POST['category'])){echo "value=\"" . $_POST['category'] . "\"";}echo ' /></td>';
		echo '<td><input class="needed" type="text" name="needed"'; if(isset($_POST['needed'])){echo "value=\"" . $_POST['needed'] . "\"";}echo ' /></td>';
		echo '<td><input class="status" type="text" name="status"'; if(isset($_POST['status'])){echo "value=\"" . $_POST['status'] . "\"";}echo ' /></td>';
		echo '<td class="gap"></td>';
		echo '<td class="gap"></td>';
		echo '<td class="save"><input type="image" style="margin-top: 4px;" src="images/sm-tick-box.jpg" height="20" class="save" alt="Submit ">
</td>';
		echo '</table>';
		echo '</form>';

 

and the code to update the row is:

 

$sql = "UPDATE Categories SET (briefed = '$briefed', job ='$job', category ='$category', needed ='$needed', status ='$status', orderid ='') WHERE catid = $catid )";
mysql_query($query);

 

I get the following errors:

 

string(145) "UPDATE Categories SET (briefed = 'PP', job ='PP', category ='PPPPPPPPPPPPPPPPPPPPPPPP', needed ='PP', status ='PP', orderid ='') WHERE catid = )" 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 '(briefed = 'PP', job ='PP', category ='PPPPPPPPPPPPPPPPPPPPPPPP', needed ='PP', ' at line 1

 

Do I need to change both the way the form accepts input and my SQL statement to achieve this?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/114250-updating-row-details-from-form-input/
Share on other sites

Hi,

 

You seem to have 2 problems here.

 

First remove all of the brackets from your SQL query, they don't need to be there.

 

Second, the SQL error seems to be caused by the fact that $catid is empty, hence WHERE catid = ) in your SQL error.

 

Robin

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.