0
<?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?

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Sorcher
0

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'

Edited by pritaeas: n/a

0

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";
}

?>
2
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.

Edited by pritaeas: n/a

Votes + Comments
Organized Problem Killer
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.