I've tried this code on a web server and it worked, but on my localhost server it did
not work. It just looped the "ADD RECORD" text (not including database infomation).
My code is below:
<HTML>
<BODY>
<?php
$register_globals;
$db = mysql_connect("localhost","root");
mysql_select_db("kangaroo",$db);
if ($submit) {
if ($id) {
$sql = "UPDATE edit SET
sub='$sub',msg='$msg',name='$name',email='$email',newday='$newday' WHERE id=$id";
} else {
$sql = "INSERT INTO edit (sub,msg,name,email,date,time,newday) VALUES
('$sub','$msg','$name','$email','$date','$time','$newday')";
}
$result = mysql_query($sql);
echo "Record updated/edited!<p>Return to <A href=\"edit.php\">$sub</a>.";
} elseif ($delete==areyousure) {
$sql = "SELECT * FROM edit WHERE id=$id";
$result = mysql_query($sql);
echo "Are you sure you want to delete $sub?<p><a
href=$PHP_SELF?id=$id&delete=true>Yes</a> | <a href=$PHP_SELF>No</a>";
} elseif ($delete==true) {
$sql = "DELETE FROM edit WHERE id=$id";
$result = mysql_query($sql);
echo "$sub Record deleted!<p><a href=edit.php>Return</a>";
} else {
if (!$edit) {
$result = mysql_query("SELECT * FROM edit",$db);
while ($myrow = mysql_fetch_array($result)) {
$newday = $myrow['newday'];
if ($newday) {
printf("<TABLE border=0 cellpadding=0 cellspacing=2 width=%s><TR><TD align=right
class=newsdate width=%s><P style=text-align: right><b>%s</b></TD></TD></TABLE>",
$myrow["width"], $myrow["width"], $myrow["date"]);
}
printf("<font class=newstitle><b><a href=\"%s?edit=yes&id=%s\">%s</a></b></font><font
class=newsnfo> - <a href=mailto:%s>%s</A> @ %s AEST</font><br>", $PHP_SELF,
$myrow["id"], $myrow["sub"], $myrow["email"], $myrow["name"], $myrow["time"]);
printf("%s<br><br>", $myrow["msg"]);
printf("<a href=\"edit.php?id=%s&delete=areyousure\">(DELETE)</a><br>", $myrow["id"]);
}
echo "<P><a href=edit.php?edit=yes>ADD A RECORD</a><P>";
}
}
?>
<?php
if ($edit) {
?>
<form method="post" action="edit.php">
<?php
if ($id) {
$sql = "SELECT * FROM edit WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$name = $myrow["name"];
$email = $myrow["email"];
$sub = $myrow["sub"];
$msg = $myrow["msg"];
$newday = $myrow["newday"];
$width = $myrow["width"];
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
<input type=hidden name="date" value="<?php echo date("l, F, jS Y"); ?>">
<input type=hidden name="time" value="<?php echo date("H:i:s"); ?>">
<input type=hidden name="width" value="100%">
Name:<input type="Text" name="name" value="<?php echo $name ?>"><br>
E-Mail:<input type="Text" name="email" value="<?php echo $email ?>"><br>
Subject:<input type="Text" name="sub" width=50 value="<?php echo $sub ?>">New
Day?<input type="radio" name="newday" value="1">Yes<input type="radio" name="newday"
value="0">No<br>
Message:<textarea name="msg" rows="7" cols="80" wrap="virtual"><?php echo $msg
?></TEXTAREA><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</BODY>
</HTML>
The !$id && !$edit are the cause but I don't know how to fix it.
I've tried id<0 and so, and they did not work.
So could somebody please help me out?
Thank you for you're time
-Ben