PHP/MySQL query producing errors - problems with multiple query parameters

Posted on 2012-08-13
Last Modified: 2012-08-13
Can anybody tell me what is wrong with this query?  
$con = mysql_connect("localhost","username","password");
if (!$con)
  die('Could not connect: ' . mysql_error());
$startDate_getData = "-1";
if (isset($_POST['startDate'])) {
  $startDate_getData = date("Y-m-d", strtotime($_POST["startDate"]));
if (isset($_POST['endDate'])) {
  $endDate_getData = date("Y-m-d", strtotime($_POST["endDate"]));
mysql_select_db("timesheets", $con);
mysql_query("UPDATE employeesxjobsxlaborcodes SET employeesxjobsxlaborcodes.committed = 1
WHERE dateWorked >= $startDate_getData AND dateWorked <= $endDate_getData", GetSQLValueString($startDate_getData, "date"),GetSQLValueString($endDate_getData, "date"));

When I load the page with the query on it, I get the following error:
Warning: mysql_query() expects at most 2 parameters, 3 given in /home/citstime/domains/ on line 77.

Line 77 is this line:  WHERE dateWorked >= $startDate_getData AND dateWorked <= $endDate_getData", GetSQLValueString($startDate_getData, "date"),GetSQLValueString($endDate_getData, "date"));
Question by:ssailer
    LVL 82

    Expert Comment

    by:Dave Baldwin
    The 'parameters' are comma delimited and you have three sections.  The second two..

    , GetSQLValueString($startDate_getData, "date"),GetSQLValueString($endDate_getData, "date")

    Open in new window

    don't make any sense in that context.  "GetSQLValueString" appears to be a routine from Dreamweaver.  While it might work to do a substitution in a different function, it's not going to work in mysql_query().
    LVL 24

    Accepted Solution

    mysql_query only accepts the SQL string and the optional connection information (if not specified, it uses current connection).  The problem here is you are sending GetSQLValueString($startDate_getData, "date"),GetSQLValueString($endDate_getData, "date") as additional parameters.  You should form your SQL string and store it to a variable first then just pass that variable to mysql_query.  Something like:

    $my_query = "UPDATE employeesxjobsxlaborcodes SET employeesxjobsxlaborcodes.committed = 1 WHERE dateWorked >= ". GetSQLValueString($startDate_getData, "date") ." AND dateWorked <= ". GetSQLValueString($endDate_getData, "date");

    Open in new window

    Note: untested.  I don't really code in PHP but I understand it a bit.

    Author Closing Comment

    The example you provided was perfect and flawless!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    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 dynamically set the form action using jQuery.

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now