<?php
$host="xxxxx.xxxxxx.com"; // Host name 
$username="xxxxxx"; // Mysql username 
$password="xxxxx"; // Mysql password 
$db_name="xxxxxxxx"; // Database name 
$tbl_name="xxxxxx"; // 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 name BY id='$id'";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($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 filename</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>Name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="name" type="text" id="name" value="<? echo $row['name']; ?>"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" id="id" value="<? echo $row['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();

?>

The error is like this:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/xxxxx/web068/b681/xxxxxx/xxxxxx/update.php on line 19
>

Got a clue?

Your query is invalid:

SELECT * FROM $tbl_name WHERE name BY id='$id'

I think you mean this:

SELECT * FROM $tbl_name WHERE id='$id'

I need to select a name from a given id

That's what $row['name'] does on line 42.

Now you made me look stupid haha!
Could you help me on this too? i get "ERROR" on the update_ac.php

//removed db connection for daniweb view
// 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 name='$name' BY 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 "ERROR";
}

?>
UPDATE $tbl_name SET name='$name' WHERE id='$id'

Make sure $tbl_name is set too. I'd advise a basic SQL tutorial to get your syntax right, or have a look at this reference.

commented: Organized Problem Killer +1

yeah solved it before i updated this page, thanks allot for the help sir. Appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.