Need Help On Updating MySql with PHP script

I have what i thought was a simple form to update 3 values in my database,
been trying now for 13 hours and im about to go nuts, can anyone find a problem
why this script is not updating the 3 values ?

// listrecords.php
''****************************************************************

<?php 
$hostname="private"; // Host name 
$username="dbmikesecure"; // Mysql username 
$password="private"; // Mysql password 
$database="dbmikesecure"; // Database name 
$tbl_name="Data"; // 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"); 

$sql="SELECT * FROM $tbl_name"; 
$result=mysql_query($sql); 
?> 
<table width="400" border="0" cellspacing="1" cellpadding="0"> 
<tr> 
<td> 
<table width="400" border="1" cellspacing="0" cellpadding="3"> 
<tr> 
<td colspan="4"><strong>Data List </strong> </td> 
</tr> 
<tr> 
<td align="center"><strong>Word1</strong></td> 
<td align="center"><strong>Word2</strong></td> 
<td align="center"><strong>Word3</strong></td> 
<td align="center"><strong>Update</strong></td> 
</tr> 
<?php 
while($rows=mysql_fetch_array($result)){ 
?> 
<tr> 
<td><? echo $rows['word1']; ?></td> 
<td><? echo $rows['word2']; ?></td> 
<td><? echo $rows['word3']; ?></td> 

// link to update.php and send value of id 
<td align="center"><a href="update.php?Id=<? echo $rows['Id']; ?>">update</a></td> 
</tr> 
<?php 
} 
?> 
</table> 
</td> 
</tr> 
</table> 
<?php 
mysql_close(); 
?> 



// update.php
''****************************************************************

<?php
$hostname="private"; // Host name 
$username="dbmikesecure"; // Mysql username 
$password="private"; // Mysql password 
$database="dbmikesecure"; // Database name 
$tbl_name="Data"; // 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="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update Data</strong> </td>
</tr>
<tr>
<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>Word1</strong></td>
<td align="center"><strong>Word2</strong></td>
<td align="center"><strong>Word3</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="word1" type="text" id="word1" value="<? echo $rows['word1']; ?>"></td>
<td align="center"><input name="word2" type="text" id="word2" value="<? echo $rows['word2']; ?>" size="15"></td>
<td><input name="word3" type="text" id="word3" value="<? echo $rows['word3']; ?>" size="15"></td>
</tr>
<tr>
<td>&nbsp;</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>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?

// close connection 
mysql_close();

?>



// update_ac.php
''****************************************************************

<?php
$hostname="private"; // Host name 
$username="dbmikesecure"; // Mysql username 
$password="private"; // Mysql password 
$database="dbmikesecure"; // Database name 
$tbl_name="Data"; // Table name 


// Connect to the database 
mysql_connect($hostname, $username, $password) OR DIE("Unable to connect"); 
mysql_select_db("$database") or die("Unable to select database");

$query="UPDATE Date SET word1='" . $_POST['word1'] . "', word2='" . $_POST['word2'] . "', word3='" . $_POST['word3'] . "' WHERE id='" . $_POST['$Id'] . "'"; 
$checkresult = mysql_query($query); 
if ($checkresult) echo 'update query succeeded'; 
else echo 'update query failed';

mysql_close(); 
?> 

$hostname + $host are two different entities totally unrelated.
same applies to $database + $db_name

Change them to one or the other so they are matching…

Hope that helps,
Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service