473,508 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP & MySQL (by acousticmarc)

ronverdonk
4,258 Recognized Expert Specialist
Sorry acousticmarc, I accidentally removed your thread!! - Ronald

Hello, first time post here and novice php user.

Man, this is frustrating the hell out of me. I've got a timecard database that goes way back, to the early 90's. I've created a form that will select the employee_id as well as any particular contract_id associated with that employee, hours and billing date. What I really want to do is be able to select a date range "starting on" date and "finishing on" this date. All attempts have been thwarted. Could someone please lend a hand?
[php]
<HTML>
<HEAD>
<script language="javascript" src="cal2.js"> <--Java popup calendar to select the date

</script>
<script language="javascript" src="z3.js"></script>
<TITLE>Query the timecard database</TITLE>
</HEAD>
<BODY>
<form name="form1" method="POST" action="z2.php">
<p> Select Employee<select name="Employee_ID" id="Employee_ID">

<option value="3">Steve</option>
<option value="14">Marc</option>

</select>

<p>Select Contract<select name="Contract_ID" id="Contract_ID">

<option value="Contract_ID">All</option>
<option value="10510">C</option>
<option value="10600">A</option>
</select>
<br>

<input type="text" name="firstinput" size=20>
<a href="javascript:showCal('Calendar1')">
<IMG SRC="/small.gif" border=0></IMG></a><br>

<p><input type="submit" name="submit" value="submit">
</form>

</BODY>
</HTML>


Then everything gets passed to z2.php


<?
$host = "localhost";
$user = "user";
$pass = "password";
$dbname = "database";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."");
mysql_select_db($dbname);

$sql = "select * from time_billed where Employee_ID=" . $_POST['Employee_ID'] . " AND Contract_ID=" . $_POST['Contract_ID'] . " AND firstinput>=" . $_POST['firstinput'] . " ORDER BY BILLING_DATE DESC";


$query = mysql_query($sql);

echo "<table border='1'>";
echo "<tr> <th>Contract</th> <th>Employee</th> <th>Date</th> <th>Hours</th> </tr>";

while ($row = mysql_fetch_array($query)) {
echo "<tr><td>";
echo $row['Contract_ID'];
echo "</td><td>";
echo $row['Employee_ID'];
echo "</td><td>";
echo $row['Billing_Date'];
echo "</td><td>";
echo $row['Billing_Hours'];
echo "</td></tr>";

}
echo "</table>";

?>
[/php]
The data format is yyyy-mm-dd....how can I retrieve the $sql statement and have it return the results that are > the firstinput range I specified?

Thank you in advance.
Nov 14 '06 #1
4 1384
ronverdonk
4,258 Recognized Expert Specialist
Are you sure that all database fields are numeric?? E.g. the date field is most probably not, it will have a DATE or a DATETIME data type.

When a table field is not numeric you have to enclose it within quotation marks (in your code single ones). So your sql statement becomes like:
[php]"SELECT ..... WHERE field = '".$_POST['var'] . "' AND ..... "[/php]

Ronald :cool:
Nov 14 '06 #2
acousticmarc
2 New Member
Are you sure that all database fields are numeric?? E.g. the date field is most probably not, it will have a DATE or a DATETIME data type.

When a table field is not numeric you have to enclose it within quotation marks (in your code single ones). So your sql statement becomes like:
[php]"SELECT ..... WHERE field = '".$_POST['var'] . "' AND ..... "[/php]

Ronald :cool:

Ronald,

Thanks for the quick reply!

Correct, I am actually using the DATETIME data type, which is what I'm trying to select from the database to determine the range of dates for output.

so, I changed the portion that wasn't numeric(firstinput) to double quotes:

[PHP]$sql = "select * from time_billed where Employee_ID=" . $_POST['Employee_ID'] . " AND Contract_ID=" . $_POST['Contract_ID'] . " AND firstinput='".$_POST['firstinput']"' ORDER BY BILLING_DATE DESC";[/PHP]

And I received an error message:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\ceci\z2.php on line 10

Apologies for what I'm sure is going to be a simple solution!

Cheers, Marc
Nov 14 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
You forgot the second period (before the ORDER BY), must be like this:
[php]..... $_POST['firstinput'] . "' ORDER BY ......[/php]
You sure the other fields are all numeric data type?

Ronald :cool:
Nov 14 '06 #4
acousticmarc
2 New Member
Ronald,

Success! I added the double quotes and also realized an error in my query. Within the select statement I was actually attempting to select one of the variables, not the column from my table. Silly me.

Thank you so much for your help, it was greatly appreciated!

acousticmarc
Nov 15 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2707
by: Google Mike | last post by:
To my surprise last month, my dad wanted to start dabbling in PHP and MySQL or pgSQL. I've been helping him out a bit. He's into athletic medicine and wants to have a website to help athletes and...
1
2128
by: Ken | last post by:
First time I have installed mysql. I have not been able to connect to the server/database with a new php installation. I have installed IIS. Do I need this for mysql? The php works fine. ...
7
3357
by: AF | last post by:
I am a real novice to php and MySQL, with about a week's worth of reading and self tutoring. I have an urgent need to publish a database of information and need some guidance on how to do this. ...
0
2202
by: dohnut | last post by:
Here's one for some bored problem solver :) I ran across this earlier today and fixed it, but don't exactly know why. (that usually only happens in C :) I'm using Perl version 5.8.0 btw. ...
0
2205
by: taras.di | last post by:
Hi everyone, I've come across an extremely strange problem. The exact same query in both mysql command line client, and mysql query browser gives entirely different results. I was hoping someone...
4
1378
by: AJ | last post by:
Hi all, Is using ASP.NET with MYSQL a plausible option?? Do you loose a lot of functionality??? Is it combersome?? Buggy?? My company is considering migrating to .NET and MYSQL may very ...
1
1764
by: Lennie De Villiers | last post by:
Hi, I'm running PHP 4.4.2 and mySQL on MS Windows XP Home Edition in IIS 6.0. When I try to connect to mySQL from PHP I get the following error message: Warning: mysql_connect(): Client does...
3
767
by: Toni | last post by:
I want to use asp.net & mysql. I am trying to download mysql db and tools from www.mysql.com but i can find everything what I need. Can somebody tell me where I can download DB, Tools, OleDB...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.