php MYSQL INSERT query error!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

php MYSQL INSERT query error!

Post 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..
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: php MYSQL INSERT query error!

Post 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.
Post Reply