Problem trying to do an INSERT with a WHERE condition

Posted on 2011-10-23
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

    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..
    LVL 1

    Author Closing Comment

    Thanks very much.

    Featured Post

    Easy Project Management (No User Manual Required)

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now