Hi guys,
I just joined this list today, and I'm already seeking for
advice :)
So,
I'm working on a project for my university. The project
consists in a web interface (php) and a mysql database.
The purpose of this project is to let teachers make room
reservations for specific classes at specific times.
I have been working with C and some other programming
languages before, and found php to be similar, although I
still have some small things to clarify here and there.
At the present moment, I have already implemented the most
part of this project, but I got stuck with the error
handling. (Most likely because I do not know a lot about
php -> mysql connectivity)
I need to make a check at the time the user submits a new
entry, that the new entry won't overlap timewise with other
entries already in the database.
The only thing that needs to be checked is the time, in a
certain day/month/year. (Reservations cannot be carried
over to a different day).
Here's how my "selected" table looks like:
$tables = "CREATE TABLE selected (
id int(3) ZEROFILL unsigned auto_increment NOT NULL,
month tinyint(3) unsigned NOT NULL DEFAULT '0',
date tinyint(3) unsigned NOT NULL DEFAULT '0',
year smallint(4) unsigned NOT NULL DEFAULT '0',
time_start smallint(4) unsigned NOT NULL DEFAULT '0',
time_end smallint(4) unsigned NOT NULL DEFAULT '0',
class tinytext,
special_request blob,
PRIMARY KEY (id),
UNIQUE id (id),
INDEX id_2 (id)
)";
And below is a piece of code with my attempts to do the
check. (mysql does not like it, so I'm assuming it's not
correct).
-------BEGIN-------
<?php
if($submit) {
if(!$db = mysql_connect("xxxx", "xxxx", "lxxxx"))
die("<font color=\"#FF0000\">Error, I could not
connect to the database at $dbserver. Using username
$dbuser and password $dbpass.<BR>Please go back and try
again.");
$x = mysql_select_db("lcdb", $db);
flush();
$sql="Select * FROM selected WHERE
(( start_time < $start_time) && ( end_time < $end_time ) &&
( start_time < $end_time ) && ( end_time < $start_time )) ||
(( start_time > $start_time) && ( end_time > $end_time ) &&
( start_time > $end_time ) && ( end_time > $start_time ))";
$r = mysql_query($sql, $db);
if ($row = mysql_num_rows($r))
{
$sql = "INSERT INTO selected (time_start, time_end, date,
month, year, class, special_request) VALUES
('$start_time', '$end_time', '$day', '$month', '$year','$cla
ss','$special_needs')";
if(!mysql_query($sql, $db)) {
echo $sql . " : " . mysql_error() . "<br>";
die("$!");
}
echo "<br><TABLE BORDER=\"0\" CELLPADDING=\"1\"
CELLSPACEING=\"0\" ALIGN=\"CENTER\" VALIGN=\"TOP\"
WIDTH=\"100%\">";
echo "<TR><TD BGCOLOR=\"$table_bgcolor\"><TABLE
BORDER=\"0\" CALLPADDING=\"1\" CELLSPACEING=\"1\"
WIDTH=\"100%\">";
echo "<TR BGCOLOR=\"FFFFFF\" ALIGN=\"LEFT\"><TD><font
face=\"Verdana\" size=\"2\"><P>";
echo "<P><BR><center>Your Reservation has been
made.<P>Click here to go back to the listing.</a></font>";
echo "</TD></TR></TABLE></TD></TR></TABLE><br>";
}
else
die("Error!");
} else {
---------END--------
So... If any of you could help me out, I would GREATLY
appreciate it.
Thanks in advance,
Ion
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]