Dear all, i am new to php and i am trying to update db table through php form ...
there is a form that takes inputs from php form and then update the db ...
Below is the update php page ...
<?php
$host="localhost"; // Host name
$username="lpr"; // Mysql username
$password="njeriop123"; // Mysql password
$db_name="give_test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name 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="ndrysho_akcioni.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<tr>
<td> </td>
<td align="center">
<input name="name" type="text" id="name" value="<? echo $rows['targa']; ?>">
</td>
<td align="center">
<input name="lastname" type="text" id="lastname" value="<? echo $rows['shteti']; ?>" size="15">
</td>
<td>
<input name="email" type="text" id="email" value="<? echo $rows['pershkrimi']; ?>" size="15">
</td>
</tr>
<tr>
<td> </td>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php
// close connection
mysql_close();
?>
And here is update_action or in my lang ndrysho_akcioni.php ...
<?php
$host="localhost"; // Host name
$username="lpr"; // Mysql username
$password="njeriop123"; // Mysql password
$db_name="give_test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="UPDATE $tbl_name SET targa='$targa', shteti='$shteti', pershkrimi='$pershkrimi' WHERE id='$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='listo.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
I dont know what the problem might be but it says succsesfully updated but it doesnt update anything ... If anybody could help me i would really appreciate it ... Thanks