0

I am using the following codes to update my SQL records but these arent working. Please help me.

HTML To select which Data to update

<?php
$connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");

mysql_select_db("shipments") or die("cannot select DB");

$sql="SELECT * FROM info";
$result=mysql_query($sql);
?>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="5"><strong>List data from mysql </strong> </td>
</tr>

<tr>
<td width="28%" align="center"><strong>Name (UID)</strong></td>
<td width="26%" align="center"><strong>Address</strong></td>
<td width="13%" align="center"><strong>Date Sent On</strong></td>
<td width="18%" align="center"><strong>Tracking</strong></td>
<td width="15%" align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['user']; ?></td>
<td><?php echo $rows['to']; ?></td>
<td><?php echo $rows['datesent']; ?></td>
<td><?php echo $rows['tracking']; ?></td>
 
<td align="center"><a href="update.php?id=<?php echo $rows['id']; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>

Page which let you edit the data

<title>Update Tracking</title>
<?php
$connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");

mysql_select_db("shipments") or die("cannot select DB");

$sql="SELECT * FROM info";
$result=mysql_query($sql);


$id=$_GET['id'];


// Retrieve data from database 
$sql="SELECT * FROM info WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="4"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Name (UID)</strong></td>
<td align="center"><strong>Address</strong></td>
<td align="center"><strong>Tracking</strong></td>
<td align="center"><strong>Date Sent On</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="user" type="text" id="user" value="<?php echo $rows['user']; ?>"></td>
<td align="center"><input name="to" type="text" id="to" value="<?php echo $rows['to']; ?>" size="15"></td>
<td><input name="tracking" type="text" id="tracking" value="<?php echo $rows['tracking']; ?>" size="15"></td>
<td><input name="datesent" type="text" id="datesent" value="<?php echo $rows['datesent']; ?>" size="15"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" id="id" value="<?php echo $rows['id']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?php

// close connection 
mysql_close();

?>

Update Script

<?php
$connect = mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");

mysql_select_db("shipments") or die("cannot select DB");
$id=$_POST['id'];
$user=$_POST['user'];
$to=$_POST['to'];
$tracking=$_POST['tracking'];
$datesent=$_POST['datesent'];

$sql="SELECT * FROM info";
$result=mysql_query($sql);



// update data in mysql database 
$sql="UPDATE info SET user = '$user', to = '$to', tracking = '$tracking', datesent = '$datesent' WHERE id='$id'";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}

else {
echo mysql_error ();
}

?>
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Sarao
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.