Jump to content

Trouble Updating via MYSQL


jaybeeb

Recommended Posts

Trying to update a row in a Table, I click on the update icon beside the row and it takes the primary key (User_ID) and it goes to a new php form where I enter new details to update I then click save and it goes back to my table, but it does not save?? Doesnt even give any warnings or errors just doesnt save??

 

Here is the code from each:

 

Code from my table (Update link)

<?php echo "<td><a href=\"selectedit.php?id=$row[user_ID]\"><img border=\"0\" src=\"images/edit.gif\"></a>"; ?>

 

Which then goes to this page , to insert the new details:

<?php
require_once 'library/db.php';
//require_once 'error.php';



if (!($conn = mysql_connect('localhost', 'root', '')))
{
	showError();
}

if (!(mysql_select_db('itsupport', $conn)))
{
	showError();
}

$a = $_GET['User_ID'];

if (!($result = mysql_query("select * from itsupport where User_ID = '$a'", $conn)))
{
	$conn = mysql_connect('localhost', 'root', '') OR DIE (mysql_error());
}

$row =mysql_fetch_array($result); 
mysql_close($conn);


?>

<html>
<head>

<title>

</title>
</head>
<body>
<p>
	Editing Details: 
	<?php echo $row['User_Name']; ?>
<p>
<form action="saveedit.php" method="post">
<table border="0">
	<tr>
		<td>
			User ID
		</td>
		<td>
			<?php echo $row['User_ID']; ?>
			<input type="hidden" name="User_ID" value = "<?php echo $row['User_ID']; ?>">
		</td>
	</tr>

	<tr>
		<td>
			User Name
		</td>
		<td>
			<input type="text" name="User_Name" value = "<?php echo $row['User_Name']; ?>">
		</td>
	</tr>

	<tr>
		<td>
			Problem
		</td>
		<td>
			<input type="integer" name="Problem" value = "<?php echo $row['Problem']; ?>">
		</td>
	</tr>

	<tr>
		<td>
		User Email
		</td>
		<td>
			<input type="text" name="User_email" value = "<?php echo $row['User_email']; ?>">
		</td>
	</tr>

	<tr>
		<td>
			Office Number
		</td>
		<td>
			<input type="integer" name="Office_Number" value = "<?php echo $row['Office_Number']; ?>">
		</td>
	</tr>

	<tr>
		<td>
			Phone Number
		</td>
		<td>
			<input type="integer" name="Phone_Number" value = "<?php echo $row['Phone_Number']; ?>">
		</td>
	</tr>

	<tr>


</table>
<input type="submit" value="Save">
</form>
</body>
</html>

 

Which then goes to the save page to save the new details, with the include down the bottom to bring me back to my table.

<?php
require_once 'library/db.php';
//require_once 'error.php';

$User_ID = $_GET['id'];

if (!($conn = mysql_connect('localhost', 'root', '')))
{
	showError();
}

if (!(mysql_select_db('itsupport', $conn)))
{
	showError();
}


if (!($result = mysql_query("UPDATE itsupport SET 
User_Name=\"$_POST[user_Name]\", 
Problem=\"$_POST[Problem]\" 
Problem_ID=\"$_POST[Problem_ID]\", 
User_email=\"$_POST[user_email]\" 
        Office_Number=\"$_POST[Office_Number]\", 
Phone_Number=\"$_POST[Phone_Number]\" 


WHERE User_ID =\"$_POST[user_ID]\"", $conn)))



{
	$conn = mysql_connect('localhost', 'root', '') OR DIE (mysql_error());
}

mysql_close($conn);
include 'currentissues.php';
?>

 

Any help would be great as I cannot figure this out!!!

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/101282-trouble-updating-via-mysql/
Share on other sites

So, any errors?

 

Also, clean up your code.

 

if (!($result = mysql_query("UPDATE itsupport SET 
User_Name=\"$_POST[user_Name]\", 
Problem=\"$_POST[Problem]\" 
Problem_ID=\"$_POST[Problem_ID]\", 
User_email=\"$_POST[user_email]\" 
        Office_Number=\"$_POST[Office_Number]\", 
Phone_Number=\"$_POST[Phone_Number]\" 

 

Should be:

 

$result = mysql_query("UPDATE itsupport SET
User_Name = '{$_POST[user_Name]}',
Problem = '{$_POST[Problem]}',
Problem_ID = '{$_POST[Problem_ID]}',
User_email = '{$_POST[user_email]}',
        Office_Number = '{$_POST['Office_Number']}',
Phone_Number = '{$_POST['Phone_Number']'}
        WHERE User_ID = '{$_POST[user_ID]}'", $conn)))

There was no errors, but it didnt update. After I swapped that bit of code you gave me I get this error

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '}' in C:\wamp\www\saveedit.php on line 25

 

Line 25

<?php WHERE User_ID = '{$_POST[user_ID]}'", $conn)))?>

 

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.