Hi, Im having a few problems, im quite new to php coding, and im just trying to write a simple script to edit a row in my database, I've used a few tutorials to come up with this script, but i cant seem to get it to let me edit the details. I can get it to come up with the radio options, but then it says "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr163/home/r/e/rebublic/public_html/roster/edit.php on line 31
" Using the or die("Error: ".mysql_error()." in query: ".$query); it comes up saying "Error: Unknown column 'Test' in 'where clause' in query:"
Any help would be greatly appreciated 😃
<form action="<? echo $PHP_SELF ?>" method="post">
<?
mysql_pconnect("localhost","******","******"); //enter name and password
mysql_select_db("rebublic"); //select the database
if(!$cmd)
{
$result = mysql_query("select * from members"); //replace news with your table name
while($r=mysql_fetch_array($result))
{
$rank=$r["rank"];
$handle=$r["handle"];
$email=$r["email"];
$icon=$r["icon"];
$position=$r["position"];
?>
<INPUT TYPE="RADIO" NAME="handle" VALUE="<?php echo $handle;?>"><? echo $rank;?> <? echo $handle; $handle; ?><br>
<? } ?>
<input type="submit" name="cmd" value="edit"></form>
<? } ?>
<?
if($cmd=="edit")
{
if (!$submit)
{
$sql = "SELECT * FROM members WHERE handle=$handle";
//replace news with your table name above
$result = mysql_query($sql) or die("Error: ".mysql_error()." in query: ".$query);
$myrow = mysql_fetch_array($result) or die("Error: ".mysql_error()." in query: ".$query);
?>
<input type=hidden name="handle" value="<?php echo $myrow[handle] ?>">Handle :<? $myrow[handle];?><br>
Rank:<INPUT TYPE="TEXT" NAME="rank" VALUE="<?php echo $myrow[rank] ?>" SIZE=30><br>
Email:<INPUT TYPE="TEXT" NAME="email" VALUE="<?php echo $myrow[email] ?>" SIZE=30><br>
Icon:<INPUT TYPE="TEXT" NAME="icon" VALUE="<?php echo $myrow[icon] ?>" SIZE=30><br>
Position:<INPUT TYPE="TEXT" NAME="position" VALUE="<?php echo $myrow[position] ?>" SIZE=30><br>
<input type="hidden" name="cmd" value="edit">
<input type="Submit" name="submit" value="Edit Member">
</form>
<? } ?>
<?
if($submit)
{
$sql = "UPDATE members SET rank='$rank',email='$email',icon='$icon',position='$position' WHERE handle=$handle";
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>