Jump to content

Updating Database via PHP


jaybeeb

Recommended Posts

Hi,

Sorry my first post here is a question. Just started PHP  :-[

 

Basically want to update a database using PHP, I have my form in my main html file and this is my PHP code. Keep getting the error "Update Query Failed"

 

<?php
if(isset($_POST['edit']))
{
include 'config.php';
include 'opendb.php';

if(isset($_POST['edit']))

$User_Name = $_POST['User_Name'];
$User_ID = $_POST['User_ID'];
$Staff_ID = $_POST['Staff_ID'];
$Problem = $_POST['Problem'];
$Problem_ID = $_POST['Problem_ID'];
$User_email = $_POST['User_email'];
$Staff_email = $_POST['Staff_email'];


$query = "UPDATE itsupport SET User_Name='$User_Name', Staff_ID=$Staff_ID, Problem='$Problem', Problem_ID=$Problem_ID,User_email='$User_email',Staff_email='$Staff_email' WHERE User_ID=$User_ID)"; 

mysql_query($query) or die ('Update Query Failed');


include 'closedb.php';
echo "Updated";


}
else
{
?>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr> 
      <td width="100">User name</td>
<td><input name="User_Name" type="text" id="User_Name"></td>
</tr>
<tr> 
      <td width="100">User ID</td>
<td><input name="User_ID" type="integer" id="User_ID"></td>
</tr>
<tr> 
      <td width="100">Staff ID</td>
<td><input name="Staff_ID" type="integer" id="Staff_ID"></td>
</tr>
<tr> 
  <td width="100">Problem</td>
<td><input name="Problem" type="text" id="Problem"></td>
</tr>
<tr> 
  <td width="100">Problem_ID</td>
<td><input name="Problem_ID" type="integer" id="Problem_ID"></td>
</tr>
<tr> 
  <td width="100">User_email</td>
<td><input name="User_email" type="text" id="User_email"></td>
</tr>
<tr> 
  <td width="100">Staff_email</td>
<td><input name="Staff_email" type="text" id="Staff_email"></td>
</tr>
<tr> 


<td width="100"> </td>
<td><input name="add" type="submit" id="add" value="Update"></td>
</tr>
</table>
</form>

<?php
}
?>
</BODY>

Link to comment
https://forums.phpfreaks.com/topic/99888-updating-database-via-php/
Share on other sites

Avoid pointless error messages while testing. Have a useful error message - and post it here unless it points to an obvious solution:

 

Change:

mysql_query($query) or die ('Update Query Failed');

 

To:

mysql_query($query) or die ('Update Query Failed. Error '. mysql_error(). ' with query '. $query);

Sorry about that, bit silly of me.

Still dont understand this error though

 

Update Query Failed. 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 with query UPDATE itsupport SET User_Name='James', Staff_ID=111, Problem='Screening', Problem_ID=999,User_email='[email protected]',Staff_email='[email protected]' WHERE User_ID=4554)

 

Thanks

Um...

 

I think it's because on the line with your query

 

$query = blah blah blah

 

 

You have a ) at the end of it... I don't see a beginning one, and you don't need a beginning one anyways.

 

See if that works :P

 

Well done buddy. Works a treat. Cheers. I really should have spotted that  ???  THANKS

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.