HI Guys , I appreciate if somebody could tell what mistakes do i have in the following code :
[B]Contents Table
[code=php]<?php
// Set Mysql Connection info
$host =”localhost”;
$username=”root”;
$password=””;
$db_name=”mail”;
$table_name=”emails”;
// Connect to database
mysql_connect(“$host”, “$username”, “$password”)or die(mysql_error());
mysql_select_db(“$db_name”) or die(“Couldn’t find mysql database”);
$sql = “SELECT * FROM $table_name ORDER BY id” or die(mysql_error());
$result = mysql_query($sql); ?>
<table width=”50%” border=”1″>
<tr>
<td width=”25%” bgcolor=”#cccccc”> ID </td> <td width=”25%”> Name </td> <td width=”50%”>Email</td>
</tr>
<?php while($rows=mysql_fetch_array($result))
{ ?>
<tr>
<td width=”25%” bgcolor=”#cccccc”><?php echo $rows[‘id’];?></td>
<td width=”25%”><?php echo $rows[‘name’]; ?></td>
<td width=”50%”><?php echo $rows[’email’]; ?></td>
<td width=”50%”><a href=edit.php?id=<?php echo $rows[‘id’];?>>Edit</a></td>
</tr>
<?php
}
mysql_close
?>
</table>
[B]Edit Form
[code=php]<?php
// Set Mysql Connection info
$host =”localhost”;
$username=”root”;
$password=””;
$db_name=”mail”;
$table_name=”emails”;
// Connect to database
mysql_connect(“$host”, “$username”, “$password”)or die(mysql_error());
mysql_select_db(“$db_name”) or die(“Couldn’t find mysql database”);
// get the value id
$id = $_GET[‘id’];
// get data from mysql database
$sql= ” SELECT * FROM $table_name WHERE id=’$id’ “;
$result = mysql_query($sql);
$rows = mysql_fetch_array($result);
?>
<form name=”update” method=”post” action=”update.php”>
<p>Name: <br />
<input type=”text” name=”name” id=”name” value=”<?php echo $rows[‘name’];?>” /> </p>
<p>E-mail:<br />
<input type=”text” name=”email” id=”email” value=”<?php echo $rows[’email’];?>” />
<br />
<input name=”id” type=”hidden” value=”<?php echo $rows[‘id’];?>”/>
<input type =”submit” name=”submit” value=”submit” />
</form>
<?php
// close connection
mysql_close();
?>
[B]The file That Update Table in mysql
[code=php]<?php
// Set Mysql Connection info
$host =”localhost”;
$username=”root”;
$password=””;
$db_name=”mail”;
$table_name=”emails”;
// 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 $table_name SET name=’$name’, email=’$email’ WHERE id=’$id'”;
$result=mysql_query($sql);
// if successfull
if($result) {
echo “Subscriber Updated Successfully!”;
}
else { echo “ERROR”;
}
?>
when i hit submit to update info , it says Updated Successfully , No erros , but actually Nothing updated!
Thank you in advance