-1

Hi I have the following code which works fine on one server but I get the following error on a free server I have used

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/a9645958/public_html/tteeth/staffslot.php on line 75

my code is as follows:

// Starting of top line showing name of the day's slots
echo "<form method='post' name='time' action='timeinsert.php'>
<table align='center' width='380' border='1'>
<tr>
<th>Select</th>
<th>Appointment Times</th>
</tr>";

// Starting of the slots
for($i=0;$i<=31;$i++){ // this shows 32 x 15 minute slots from 9:00am - 17:00pm
$shr=9+floor($i/4); //calculates the start hour of a slot
$smin=($i%4)*15; //calculates the start minutes of a slot
$time=mktime($shr,$smin,00,0,0,0); //creates full php time from hours and minutes above
$displayTime2=date("H:i:s",$time); // creates correct time format for MySQL database hrs, mins, seconds

$pagetime = date("H:i a", strtotime($displayTime2)); //converts the time to just hours and minutes
$timenow = date('H:i'); // get's the current time

$chosendate = date(mktime(0,0,0,$month,$day,$year)); // converts the date picked to php time (seconds since 01 01 1971)
$todayDate = date(mktime()); // converts today's date to php time so it can be compared with the chosen date

while ($myrow = mysql_fetch_row($result)) {
        printf("<tr><td>%s</td><td>%s</td></tr>\n",
        $myrow[0]);
}
$result=mysql_query("SELECT * FROM appointment where Appointment_Time='$displayTime2' AND Appointment_Date='$insertdate' AND Practice_ID='$practice'");
$myrow = mysql_fetch_row($result);
    if($pagetime<$timenow AND $chosendate<$todayDate) //if the display time is less than the time now, and the date is less than todays date
        { //do not display a row 
        }
    elseif($myrow)// if the values in the database match the row slot time
        {
        echo "<td></td><td align='center'>$pagetime</td>";//just display the slot as a time
        }
    else
        {
        echo    "<td align='center'><input type='checkbox' name='$displayTime2' onclick='KeepCount()'></td>
                <td align='center'>$pagetime</td>";
        }
    echo "</td></tr>";          
        }
    echo "</table><br>
        <input type='submit' value='Submit'>
</form>";

I'm pretty cofident that the problem is with the print f function because it asks to print the table header for however many values there are in $myrow, but it hasn't got the valuue of it yet...but if I move it to after the select statement, it messes up the rest of my code (it doesnt compare the time with whats in the db, and there are problems inserting into the db on the following page)

  • 1
    You are not putting the code here because the error is on line 75 and that code only has 44 lines. If the error is in the code you posted, it is because the query failed. Use: if(!$result = mysql_query("your query...")) print mysql_error(); – kainaw Mar 19 '13 at 15:24

1 Answers1

1

Here you are trying fetch result whicht not exist in that moment.

while ($myrow = mysql_fetch_row($result)) {
        printf("<tr><td>%s</td><td>%s</td></tr>\n",
        $myrow[0]);
}

You should put that while loop after this

$result=mysql_query("SELECT * FROM appointment where Appointment_Time='$displayTime2' AND Appointment_Date='$insertdate' AND Practice_ID='$practice'");
  • I have already mentioned that... when I put it after the select statement the next part doesnt work properly: $myrow = mysql_fetch_row($result); if($pagetime<$timenow AND $chosendate<$todayDate) //if the display time is less than the time now, and the date is less than todays date { //do not display a row } – Tim Butterfield Mar 19 '13 at 15:37
  • Why is this in loop: while ($myrow = mysql_fetch_row($result)) { printf("%s%s\n", $myrow[0]); }. mysql_fetch_row() return only 1 row from table. How many rows can this return ("SELECT * FROM appointment where Appointment_Time='$displayTime2' AND Appointment_Date='$insertdate' AND Practice_ID='$practice')? One or more? – Miroslav Stopka Mar 19 '13 at 15:42
  • it can return as many appointments as there are in the database which match that criteria... in theory there should only be 1 record! – Tim Butterfield Mar 19 '13 at 16:51
  • If it can return more than record, you should use mysql_fetch_array() instead of mysql_fetch_row(). Next order should be first result = mysql_query(...), second row = mysql_fetch_row() / _array(). If this doesnt work properly so your problem is somewhereelse. – Miroslav Stopka Mar 19 '13 at 17:03