Odd MySQL Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
edg
Forum Newbie
Posts: 11
Joined: Wed Aug 28, 2002 12:58 pm

Odd MySQL Problem

Post by edg »

I've used

Code: Select all

mysql_result($result, 0, "lesson")
To get the lesson column value, but I always get the error "Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 6". What does this mean? I can't seem to find any way to fix it?! Help please!

edg
User avatar
Rook
Forum Newbie
Posts: 10
Joined: Thu Aug 21, 2003 10:40 am
Location: Euless, Tx.
Contact:

Post by Rook »

Hmm... i've never used mysql_result since I usually want more than just one field returned.

try using something like:

Code: Select all

<?php
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$lesson = $row['lesson'];
?>
- Rook.
edg
Forum Newbie
Posts: 11
Joined: Wed Aug 28, 2002 12:58 pm

Post by edg »

Thanks rook. I seem to have a problem writing to the DB, despite being connected etc. (Queries going through too) Here is my full code, I don't see any problems with it but someone else might :?

Code: Select all

<?php
$date = $HTTP_POST_VARS['date'];
$month = $HTTP_POST_VARS['month'];
$year = $HTTP_POST_VARS['year'];
$period = $HTTP_POST_VARS['period'];
$username = $_COOKIE['usercookie'];
$db = mysql_connect("localhost", "blanked", "blanked");

mysql_select_db("test", $db);
$current_epoch = date("U");
$selected_date = date("U", mktime(0,0,0,$month,$date,$year));
if ($current_epoch>$selected_date) {
echo("<strong>Date selected is in the Past.</strong><br /><g5>Unfortunatley, you cannot book a room in the past, please select another date.</g5>");
} else {
$query = "SELECT * FROM booking WHERE day='".$date."' AND month='".$month."' AND year='".$year."' AND lesson='".$period."'";
$result = mysql_query($query, $db);
$row = mysql_fetch_array($result ,MYSQL_ASSOC); 
$lesson =$row['lesson'];
echo($lesson);
if ($lesson==$period) {
echo("<strong>Period selected is already booked.</strong><br /><g5>Unfortunatley that period has already been allocated. Please go back and select another.</g5>");
} else {
if ($username != "") {
mysql_query("INSERT INTO booking VALUES ('', '$date', '$month', '$year', '$period', '$username'", $db);
echo("<strong>Booking Entered.</strong><br /><g5>Your booking entry was successful.</g5>");
} else {
echo("<strong>You must be logged in to book a date</strong><br /><g5>It appears you aren't logged in. To Log In <a href="index.php?page=login_form.php">Click Here</a></g5>");
}
}
}
?>
Thanks :)

edg
User avatar
Rook
Forum Newbie
Posts: 10
Joined: Thu Aug 21, 2003 10:40 am
Location: Euless, Tx.
Contact:

Post by Rook »

mysql_query("INSERT INTO booking VALUES ('', '$date', '$month', '$year', '$period', '$username'", $db);
echo("<strong>Booking Entered.</strong><br /><g5>Your booking entry was successful.</g5>");
Is the problem that you are getting the "Booking Entered" success message, but it's not actually inserting into the database?

You might consider modifying your insert query:

Code: Select all

<?php
mysql_query("INSERT INTO `booking` (ID, DATE, MONTH, YEAR, PERIOD, USERNAME) VALUES ('', '".$date."', '".$month."', '".$year."', '".$period."', '".$username."'", $db) or die (mysql_error());
?>
If you'll notice, the insert query is now listing each field name then the values that should go into them. This means you no longer have to write the insert query in the proper table column order. Also the `or die (mysql_error())` will kick out whatever error you are getting.

Hope this helps...

- Rook.
edg
Forum Newbie
Posts: 11
Joined: Wed Aug 28, 2002 12:58 pm

Post by edg »

Sorry for waisting your time rook, it was a bloody spelling error :( I'm very tired, but happy it's sorted. Thanks again Rook - Top man :)

edg
Post Reply