Jump to content

Editing data problem....


tshing70

Recommended Posts

I was trying to edit form data using php, when i click the edit text, it show me the edit form, but the input text show me <? echo and does't show me the information that i wish to edit....what is the error below the code?? listing.php code<CENTER><?php$con = mysql_connect ("localhost","root","");if (!$con){die('Could not connect: ' .mysql_error());}mysql_select_db("member_db", $con); $result = mysql_query("SELECT * FROM newmember"); echo "<table border='1'><tr><th>Id</th><th>Name</th><th>Gender</th><th>DOB</th><th>Address</th><th>State</th><th>Is Member</th></tr>"; while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td>" . $row['P_Id'] ."</td>";echo "<td>" . $row['Name'] ."</td>";echo "<td>" . $row['Gender'] ."</td>";echo "<td>" . $row['Dob'] ."</td>";echo "<td>" . $row['Address'] . "</td>";echo "<td>" . $row['State'] . "</td>";echo "<td>" . $row['Ismember'] . "</td>";echo ("<td><a href=\"edit.php?id=$row[P_Id]\">Edit</a></td>");echo ("<td><a href=\"delete.php?id=$row[P_Id]\">Delete</a></td></tr>");}echo "</table>"; mysql_close($con);?></CENTER> Edit.php code<html><head><title>Edit Form</title></head><body><table><tr><td align="center">EDIT DATA</td></tr><tr><td><table border="1"><?$con = mysql_connect("localhost","root","");if (!$con){die('Could not connect: ' . mysql_error());} mysql_select_db("member_db", $con); $id=$_GET['id'];$order = "SELECT * FROM newmember WHERE P_Id=$id";$result = mysql_query($order);$row = mysql_fetch_array($result);?> <form method="Post" action="update.php"><input type="hidden" name="id" value="<? echo "row['P_Id']"?><tr><td>Name</td><td><input type="text" name="name" value="<? echo "$row['Name']"?></td></tr><tr><td>Gender</td><td><input type="text" name="gender" value="<? echo "$row['Gender']"?></td></tr><tr><td>Address</td><td><input type="text" name="address" value="<? echo "$row['Address']"?></td></tr><tr><td>DOB</td><td><input type="text" name="dob" value="<? echo "$row['Dob']"?></td></tr><tr><td>State</td><td><input type="text" name="state" value="<? echo "$row['State']"?></td></tr><tr><td align="right"><input type = "submit" name="submit value" value="Edit"></td></tr></form></table></td></tr></table></body></html> UPDATE.php<? $con = mysql_connect ("localhost","root","");if (!$con){die('Could not connect: ' .mysql_error());}mysql_select_db("member_db", $con); $order = "UPDATE newmember SET name='$name', gender='$gender', address='$address', dob='$dob', state='$state', WHERE P_Id=$id";mysql_query($order);header("location:listing.php");?> i sorry about the long code, appreciated you guys finish reading it....thank a lot :Pleased:

Edited by tshing70
Link to comment
Share on other sites

<input type="hidden" name="id" value="<? echo "row['P_Id']"?>
<input type="hidden" name="id" value="<?php echo row['P_Id'];?>">you should use <?php rather than <? short hand syntax is not enabled in all server.also there is problem with quotes,you should terminate each statement using semicolon not relate to your problem but you should change it:when you echo a variable you need not to quote ityou should not use tables to layout. use table to show only tabular data. use box modeling to layout a page Edited by birbal
Link to comment
Share on other sites

Well.....when i add <?php echo row['P_Id'];?>"> full of this.....it show me this funny wordParse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\edit.php on line 33

Link to comment
Share on other sites

did you make change in all of the code? you have to close all the statements whereever you left it open. same with short hand syntax.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...