0

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>

Edited by luweegee: n/a

6
Contributors
16
Replies
17
Views
6 Years
Discussion Span
Last Post by luweegee
0
$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.

0

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']}");
0
$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.

0

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

Edited by luweegee: n/a

0
$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.

0

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=

0

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");

0

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.

Edited by svilla: n/a

0

@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]");
0

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

:(

0

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]' ");

0

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

0

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

Edited by luweegee: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.