Click to See Complete Forum and Search --> : Edit/update record using php&mysql


ila
02-22-2010, 01:39 AM
HI..
i'm designing a web page as my assignment and i'm having a problem in editing and updating data in the database...basically here i already come up with the scripts but it does not update the data in the database..could anyone help me since i need it urgently..your kind help is appreciated....

EDITING AND DELETING LINKS

</head>

<body>
<form action="index.php" method="post">
<br /><input type="submit" value="HOME" ;/></form><br />



<?php

$con = mysql_connect("localhost","anis","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Maintenance", $con);

$result = mysql_query("SELECT * FROM Informations order by Country");

echo "<table border='1'>

<tr>
<th>Country</th>
<th>Customer Name</th>
<th>Software/Modules</th>
<th>LAC</th>

</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";

echo "<td>" .$row['Country'] . "</td>";
echo "<td>" .$row['CustomerName'] . "</td>";
echo "<td>" .$row['Software_Module']. "</td>";
echo "<td>" .$row['LAC']. "</td>";
echo "<td>" . "<a href=delete_maintenance3.php?Customer_id=$row[Customer_id]> Delete </a></td>";
echo "<td>" . "<a href=kemaskini4.php?Customer_id=$row[Customer_id]> Edit </a></td>";

echo "</tr>";
}

echo "</table>";
mysql_close($con);
?>

<br />
<form action="info_maintenance.php" method="post">
<input type="submit" value="Add Data" ;/></form>


EDITING FORMS

<body>

<?php

$con = mysql_connect("localhost","anis","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Maintenance", $con);
$Customer_id=$_GET['Customer_id'];
$result = mysql_query("SELECT * FROM Informations where Customer_id= ".(int)$Customer_id."");
while($row = mysql_fetch_array($result))
{
?>
<form name="form" method="post" action="updated_maintenance.php">

<table border="1">
<tr>
<th > <div align="center">Country</div></th>
<th > <div align="center">Customer Name</div></th>
<th > <div align="center">Software/Modules</div></th>
<th > <div align="center">LAC </div></th>
</tr>
<tr>
<?php echo "<td>" .$row['Country'] . "</td>"; ?>
<?php echo "<td>" .$row['CustomerName'] . "</td>"; ?>
<td><input type="text" name="softwareM" value="<?php echo $row["Software_Module"]?>"></td>
<td><input type="text" name="lac" value="<?php echo $row["LAC"]?>"></td>
</tr>
</table>

<?php
} ?>

<br /><br />
<input type="submit" value="Update!!!!!" ;/>
<input type="hidden" name"customerid " value="<?php echo customerid?>" ;/></form>

</body>


SAVING THE UPDATING DATA

</head>


<form action="index.php" method="post">
<br /><input type="submit" value="HOME" ;/></form><br />
<body>
<?php
$con = mysql_connect("localhost","anis","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Maintenance", $con);



$SoftwareM=$_POST['softwareM'];
$Lac=$_POST['lac'];

$query = "UPDATE Informations SET Software_Module='$SoftwareM', LAC='$Lac'
WHERE Customer_id= ".(int)$Customer_id." " ;


if (!mysql_query($query,$con))
{
die('Error: ' . mysql_error());
}

else
{
echo "<br />"."1 record updated!!!"."<br />";}

?>

<br />
<form action="data_maintenance.php" method="POST">
<input type="submit" value="Update Again">
</form> <br />
</body>
</html>