Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Problem trying to do an INSERT with a WHERE condition

Posted on 2011-10-23
Medium Priority
Last Modified: 2012-06-27
I'm sure I'm going about this wrong but I'm trying to do an INSERT that has a conditional WHERE clause. If I take out the WHERE,  the statement works fine, but I'm trying to ensure the insert doesn't affect any records other than the ones that meet the WHERE condition.

When I run it with the WHERE in, I get nothing being affected.

Do you see something wrong in it?

$sql="INSERT INTO callers(ContestId, account_id, CallTo, CallSid, CallerName, CallerCity, CallerState, FromCaller, FromCallerDisplay, CallStatus, SubscribeStatus)VALUES('$contestid', '$account_id','$CallTo', '$CallSid','$CallerName', '$CallerCity', '$CallerState', '$FromCaller','$FromCallerDisplay', '$CallStatus', '$subscribestatus' WHERE account_id = '$account_id')";

Open in new window

Question by:tjyoung
LVL 11

Accepted Solution

maeltar earned 2000 total points
ID: 37014854
Needs to be an update statement, as an insert is just that, inserting a new record, and inserting a new record means there is nothing to search by...

Where as an update, means you update a row where you can search for an existing value..

Author Closing Comment

ID: 37014859
Thanks very much.

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this article, we’ll look at how to deploy ProxySQL.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question