Can u help me guys im a newbie in php...i want u 2 check my Update code because they not function. is there something wrong in my code?

<?php
$con = mysql_connect("localhost","root","");
$sql = mysql_select_db("luweegee",$con);

?>
<html>
	  <body>
	  <table border=1 align='center' width=800 cellpadding=20 cellspacing=0>
	  <tr><td colspan=2><h1>Edit Record</h1></td></tr>

<tr>
<td valign='top'>
<ul>
<a href='View.php'><li>View Record</li></a>
<a href='Add.php'><li>Add Record</li></a>	
<a href='Edit.php'><li>Edit Record</li></a>
<a href='Delete.php'><li>Delete Record</li></a>
</u>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</td>


<td valign='top'>
<table border=1 width=550 cellpadding=3 cellspacing=0>

<?php
echo"
<tr>
		<td><center>Name</center></td>
		<td><center>Age</center></td>
		<td><center>Sex</center></td>
		<td><center>Mobile</center></td>
		<td><center>Action</center></td>
</tr>
        <form method='post' action='Edit.php'>";
	$sel = mysql_query("SELECT * FROM resume");
	while($data=mysql_fetch_array($sel))
		{
		echo "<tr>
<td><center>$data[name]</center></td>
<td><center>$data[age]</center></td>
<td><center>$data[sex]</center></td>
<td><center>$data[mobile]</center></td>
<td><center><input type='submit' value='Update' name='updateButt$data[id]'></center></td>
			  </tr>";
		}
	
echo "</form>";

for($x=0;$x<=100;$x++)
	{
	if($_POST[updateButt.$x])
		{
		$select = mysql_query("SELECT * FROM resume WHERE id=$x");
		while($data=mysql_fetch_array($select))
				{
echo "<form name='myform' method='post' action='Edit.php'>
      <table border=1 align='center' cellspacing=0>
      <tr><td colspan=2>Editing: <span class='underline'>$data[name]</span></td></tr>
      <tr><td>Name: </td><td><input type='text' size=20 name='name'/></td></tr>
      <tr><td>Age: </td><td><input type='text' size=20 name='age'/></td></tr>
      <tr><td>Sex: </td><td><input type='text' size=20 name='sex'/></td></tr>
      <tr><td>Mobile: </td><td><input type='text' size=20 name='mobile'/></td></tr>
      <tr><td colspan=2><input type='submit' value='Submit' name='submitEditForm'/></td></tr>
</form>";		
		}
	}
}
		
	if($_POST['submitEditForm'])
		{
$update = mysql_query("UPDATE 'resume' SET name=$_POST[name], age=$_POST[age], sex=$_POST[sex], mobile=$_POST[mobile] WHERE id=$_POST[id]");

			echo "Record successfully updated.";
		}
	
?>

</table>
<tr>
<td colspan=2 align='center'>
Copyright&copy;2011,
</tr>
</td>
</table>
</body>
</html>

Recommended Answers

All 16 Replies

$update = mysql_query("UPDATE resume SET name='{$_POST['name']}', age='{$_POST['age']}', sex='{$_POST['sex']}', mobile='{$_POST['mobile']}' WHERE id={$_POST['id']}");

It is dangerous to insert $_POST'ed values without checking.

Thanks for helping me sir but i try this code but nothings happen

$update = mysql_query("UPDATE resume SET name='{$_POST['name']}', age='{$_POST['age']}', sex='{$_POST['sex']}', mobile='{$_POST['mobile']}' WHERE id={$_POST['id']}");
$update = mysql_query("UPDATE resume SET name='{$_POST['name']}', age='{$_POST['age']}', sex='{$_POST['sex']}', mobile='{$_POST['mobile']}' WHERE id={$_POST['id']}") or die(mysql_error());

Post the error that will show.

ive tried ur code and here's the message i got...

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

$sql = "UPDATE resume SET name='{$_POST['name']}', age='{$_POST['age']}', sex='{$_POST['sex']}', mobile='{$_POST['mobile']}' WHERE id={$_POST['id']}";
$update = mysql_query($sql) or die(mysql_error() . '<br/>' . $sql);

Try again, and paste the query too.

Nothings Happen...

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
UPDATE resume SET name='sdf', age='sf', sex='sdf', mobile='sdfdsf' WHERE id=

try this - if something goes wrong u can still go forward - 1st try to connect and keep the rest of the code indented .

$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>"

$selected = mysql_select_db("examples",$dbhandle)
or die("Could not select examples");

Instead of putting the SQL Statement in the mysql_query() function, put it into a variable and echo out that string so you can see the actual SQL statement that is being passed.

$sqlStmt = "UPDATE resume SET name='{$_POST['name']}', age='{$_POST['age']}', sex='{$_POST['sex']}', mobile='{$_POST['mobile']}' WHERE id={$_POST['id']}";
echo $sqlStmt;
mysql_query(sqlStmt);

If you cannot see the statement on the web page, do a View Source and you should be able to see the SQL statement somewhere in the HTML source.

@anilashanbhag sir i already connected in mysql server....in this part of code is my problem i dont know if this code is have an err0r..

$update = mysql_query("UPDATE 'resume' SET name=$_POST[name], age=$_POST[age], sex=$_POST[sex], mobile=$_POST[mobile] WHERE id=$_POST[id]");

Instead of putting the SQL Statement in the mysql_query() function, put it into a variable and echo out that string so you can see the actual SQL statement that is being passed.

$sqlStmt = "UPDATE resume SET name='{$_POST['name']}', age='{$_POST['age']}', sex='{$_POST['sex']}', mobile='{$_POST['mobile']}' WHERE id={$_POST['id']}";
echo $sqlStmt;
mysql_query(sqlStmt);

If you cannot see the statement on the web page, do a View Source and you should be able to see the SQL statement somewhere in the HTML source.

Nothings Happen...

:(

shouldnt it be $_POST u missed the '

Theres nothing happen again @anilashanbhag

First check your posted values by using the following statement.
print_r($_POST);

If posted values are OK, then execute the query in the following manner.

$update = mysql_query("UPDATE resume SET name='$_POST[name]', age='$_POST[age]', sex='$_POST[sex]', mobile='$_POST[mobile]' WHERE id='$_POST[id]' ");

And check if $_POST[id] contains anything.

First check your posted values by using the following statement.
print_r($_POST);

If posted values are OK, then execute the query in the following manner.

$update = mysql_query("UPDATE resume SET name='$_POST[name]', age='$_POST[age]', sex='$_POST[sex]', mobile='$_POST[mobile]' WHERE id='$_POST[id]' ");

ive tried this code there's no err0r when i submit but nothings update my name

First check your posted values by using the following statement.
print_r($_POST);

If posted values are OK, then execute the query in the following manner.

$update = mysql_query("UPDATE resume SET name='$_POST[name]', age='$_POST[age]', sex='$_POST[sex]', mobile='$_POST[mobile]' WHERE id='$_POST[id]' ");

ive tried this code theres no err0r when i click the submit button theres nothing happen in my previous data...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.