For some reason i get an error when i run this script. It works fine, but when i try to add a link to the databse, it adds it but gives me an error (Warning: Use of undefined constant id - assumed 'id' in c:\phpdev\www\ilya\index.php on line 21)
what i want it to do is add a link to the databse with the while increasing the ID every time a new one is added (so the first one yo uadd will be 1, the 2nd is 2 etc. but, say, if you ahve 100 links, and delete 5 of them, the next id will be 101, not 96 - total+1).
also, after adding the links, when the ID gets to 10, the next one doesn't get 11, it still gets 10!
here's the entire code:
<?php
mysql_pconnect("localhost","root","")
or die("Unable to connect to SQL server");
mysql_select_db("ilya") or die("Unable to select database");
global $action;
if ($action=="add") {
if ($name=="") {
echo "You forgot to enter the name of your site<br>\n";
}
if ($link=="") {
echo "You forgot to enter the URL of your site<p>\n";
exit;
}
else {
$query = "SELECT * FROM links order by id Desc";
$links = mysql_query($query) or die("Select Failed!");
$record = mysql_fetch_array($links);
$id=$record[id];
$id++;
$query = "INSERT INTO links ";
$query .= "(id, name, link)";
$query .= " values('$id', '$name','$link')";
mysql_query($query) or die("Insert Failed!");
echo "Added!<br>\n";
echo "ID: $id<br>Name: $name<br>URL: $link\n";
echo "<br><a href=index.php>Main Page</a>\n";
exit;
}
}
echo "<form action=\"index.php\" method=\"post\"><input type=\"hidden\" name=\"action\" value=\"add\">
Page Name: <input type=text name=name size=30><br>
Page URL: <input type=text name=link size=30><br>
<input type=submit></form>
<hr>\n";
$query = "SELECT * FROM links";
$links = mysql_query($query) or die("Select Failed!");
$total = mysql_num_rows($links);
echo "Total: $total<br>\n";
while ($record = mysql_fetch_array($links)) {
echo "ID: $record[id]<br><a href=$record[link]>$record[name]</a><p>
\n";
}
?>
any help will be appreciated!