I’m trying to add a number to a column called ID in my database. What should happen is when there no data in the database this script will insert the first line with the ID numbered as 1 but the issue is it’s not working.
I think my checking of null data is the issue can one of you help me by pointing out what should I do.
My code
<?php
/**
* @author SiNUX
* @copyright 2013
*/
include ('connect.php');
$lastId = mysql_query("SELECT ID FROM poiinfo");
$row = mysql_fetch_array($lastId);
if (is_null($row['ID'])){
$nId = $row['ID'];
$nId = 0;
$nId = $nId++;
$addId = "INSERT INTO poiinfo(`ID`) VALUES ('$nId')";
mysql_query($addId);
}else {
$lId = $row['ID'];
$lId = $lId + 0;
$lId++;
}
?>
this query which you are executing
will most likely fail because the
columnnamewas enclosed by single quote. The quote should be reomved or replace it with backtick, egor
and so the question is, when do I use backtick? It’s you are using a name which is on the list of MySQL’s reserved keyword,
and lastly, you must pass the variable containing the query in
mysql_query()