?
Solved

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

Posted on 2012-08-13
3
Medium Priority
?
674 Views
Last Modified: 2012-08-13
Can anybody tell me what is wrong with this query?  
<?php
$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"));
mysql_close($con);
?>

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/citstime.com/public_html/qryCommit.php on line 77.

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

Expert Comment

by:Dave Baldwin
ID: 38289799
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().
0
 
LVL 24

Accepted Solution

by:
johanntagle earned 2000 total points
ID: 38289811
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");

mysql_query($my_query);

Open in new window


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

Author Closing Comment

by:ssailer
ID: 38289901
The example you provided was perfect and flawless!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 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