tags:

views:

55

answers:

2
$result = mysql_query("INSERT INTO project (clientname, salesperson, prospect)
                       VALUES ('$clientName','$salesPer','$prospectVal')");

      while ($row = mysql_fetch_assoc($result)) {

       $projectID = $row['projectid'];


      return $projectID;

     }

I am not getting the projectID from the database. The field name is a dynamic one which increments on each insertion.

+5  A: 

You are trying to select items with an INSERT statement. That wont work.

Try this.

SELECT projectid, clientname, salesperson, prospect FROM project

You could also be looking for the Insert ID, the ID this insert statment got. Then this would work.

$result = mysql_query("INSERT INTO project (clientname, salesperson, prospect)
    VALUES ('$clientName','$salesPer','$prospectVal')");

if($result)
{
     $insert_id = mysql_insert_id();
}

3rdly, please look into some input sanitation (it could be that you are sanitizing the values above this snippet but just to be sure. Look at this function.

mysql_real_escape_string();

Ólafur Waage
Thanks for reminding me the use of SELECT Statement, i was totally lost somewhere
You're welcome :)
Ólafur Waage
+2  A: 
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error.

Are you looking for mysql_insert_id()?

deceze
Thanks for mysql_insert_id... i learnt something new.