Page 1 of 1

php MYSQL INSERT query error!

Posted: Wed Apr 01, 2009 6:49 am
by pavanpuligandla
hi all..

i'm generating a KEY and trying to insert it into the database, but it is not being inserted. my table has already 12 columns, i added another column "KEY" of type VARCHAR and of size 100.

the query is :

Code: Select all

$key = substr(base64_encode(crypt('', '')), 0, 32);
     $key = mysql_real_escape_string($key);
     $query1="INSERT INTO ss_customers (key) VALUES '".$key."' WHERE customerID='".$_SESSION['customerID'] ."'";
     $result1=mysql_query($query1);
     echo $query1;
     exit();
when i print the query, i can see the KEY value. but i cannot see any row filled up in my database..
can anyone please help me.. can we use WHERE clause in INSERT query?
PS: The KEY is dynamically generated, it is not coming from any other form..

Re: php MYSQL INSERT query error!

Posted: Fri Apr 10, 2009 6:18 am
by novice4eva
You should do UPDATE not insert if the value already exists for that customerID, if not then go for INSERT.
No you can't have WHERE in INSERT sql.