When I clink on the edit link it is suppose to open up a form with the particulars of that entry already populating the form fields. Here I should be able to make whatever changes and click submit to update the database.
But I'm getting empty fields with this error message:
Code: Select all
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hsphere/local/home/... editlink.php on line 74What's wrong here?
Here is line 74 (at bottom) as it appears in the qyuery string:
Code: Select all
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM links WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>Code: Select all
<?php
include("dbinfo.inc.php");
$conn = mysql_connect("$host", "$username", "$password") or die(mysql_error());
mysql_select_db("$database",$conn) or die(mysql_error());
if(!isset($cmd))
{
//display all the links
$result = mysql_query("select * from links order by id");
//run the while loop that grabs all the links
while($r = mysql_fetch_array($result))
{
//grab the items to be displayed
$id=$r["id"];
$name=$r["name"];
$link=$r["link"];
?>
<!--<tr><td width="5%" align=right><font face=arial size=2><b>Id #</b>: </font></td><td width="80%"><font face=arial size=2>$id</font></td></tr>-->
<tr>
<td width="25%"><font face=arial size=2>
<b>Name of Website</b>: </font></td>
<td width="40%"><font face=arial size=2><? echo "$name"; ?></font></td>
<td width="30%" ><font face=arial size=2><a href='editlink.php?cmd=edit&id=$id'>Edit</a></font></td>
</tr>
<tr><td colspan=3 style="border-top:1px solid #666666"><font face=arial size=2> </font></td></tr>
<?php
}
}
?>
</table>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM links WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<center>
<table width="95%" cellspacing=0 cellpadding=3 border=0>
<tr>
<td>
<form action="editlink.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow['id'] ?>">
Name of Website:<br />
<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow['name'] ?>" SIZE=65><br /><br />
Link:<br />
<INPUT TYPE="TEXT" NAME="link" VALUE="<?php echo $myrow['link'] ?>" SIZE=65><br /><br />
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
</td>
</tr>
</table>
</center>
<?php } ?>
<?php
if ($_POST["$submit"])
{
$name = $_POST['name'];
$link = $_POST['link'];
$sql = "UPDATE links SET name='$name', link='$link' WHERE id=$id";
$result = mysql_query($sql);
echo "<br /><br /><p align=\"center\"><span style=\"color:red\">Link updated.</span></p><br /><br />";
echo "<p align=\"center\"><a href=\"editlink.php\">Edit another Website Link</a></p><br /><br />";
}
}
?>