php - Why won't my page refresh? -


i have small time slot booking system, can click link called: reserve, , reserve given time.

however, page doesn't refresh after i've clicked on reserve. therefore it's possible user click same reserve link twice. whitch shouldn't able to.

if (isset ( $_get ['reserved'] )) {      $sqlreserve = "insert calendar (eventdate, timeslot) values ('" . $datetocompare . "','" . intval($_get['t']) . "');";     $resultreserve = mysqli_query ( $mysqli1, $sqlreserve );     if ($resultreserve) {         header('location: '.$_server['php_self']);     } else {         echo "event failed add";     } } 

if insert works, call: header('location: '.$_server['php_self']);

i'm working on localhost, if has say?

edit:

the way create links , text saying slot booked this:

    if (mysqli_num_rows ( $result ) == 0) {         echo "<a href='" . $_server ['php_self'] . "?month=" . $month . "&day=" . $day . "&year=" . $year . "&t={$time}&v=true&f=true&reserved=true'><h3 style='color: rgb(255,0,0);'>reserve</h3></a>";     } else {         echo "<h3>not available, taken by:</h3>";         while ( $row = mysqli_fetch_array ( $result ) ) {             echo "<br />";         }  } 

edit. error:

cannot modify header information - headers sent (output started.....)

for($i = 1; $i < $numdays; $i ++, $counter ++) {                 $timestamp = strtotime ( "$year-$month-$i" );                 if ($i == 1) {                     $firstday = date ( "w", $timestamp );                     for($j = 0; $j < $firstday; $j ++, $counter ++) {                         echo "<td>&nbsp;</td>";                     }                 }                 if ($counter % 7 == 0) {                     echo "</tr><tr>";                 }                 $monthstring = $month;                 $monthlength = strlen ( $monthstring );                 $daystring = $i;                 $daylength = strlen ( $daystring );                 if ($monthlength <= 1) {                     $monthstring = "0" . $monthstring;                 }                 if ($daylength <= 1) {                     $daystring = "0" . $daystring;                 }                  $todaysdate = date ( "m/d/y" );                 $datetocompare = $monthstring . '/' . $daystring . '/' . $year;                 echo "<td align='center' ";                 if ($todaysdate == $datetocompare) {                     echo "class='today'";                 } else {                     $sqlcount = "select * calendar eventdate='" . $datetocompare . "'";                     $noofevent = mysqli_num_rows ( mysqli_query ( $mysqli1, $sqlcount ) );                     if ($noofevent >= 1) {                         echo "class='event'";                     }                 }                 echo "><a href='" . $_server ['php_self'] . "?month=" . $monthstring . "&day=" . $daystring . "&year=" . $year . "&v=true'>" . $i . "</a></td>";             } 

the line affected is:

echo "><a href='" . $_server ['php_self'] . "?month=" . $monthstring . "&day=" . $daystring . "&year=" . $year . "&v=true'>" . $i . "</a></td>";

it in file have calendar, in have links specific day wan't book timeslots fore:

enter image description here

try this..

header('location: '.$_server['php_self']); exit; 

i think code continuing...

a more in-depth explanation can found here: why have call 'exit' after redirection through header('location..') in php?

edit

it's clear milen georgiev answer correct. output content browser before reach header(); need move if statement in top part of php code avoid header content error.

if (isset ( $_get ['reserved'] )) {      $sqlreserve = "insert calendar (eventdate, timeslot) values ('" . $datetocompare . "','" . intval($_get['t']) . "');";     $resultreserve = mysqli_query ( $mysqli1, $sqlreserve );     if ($resultreserve) {         header('location: '.$_server['php_self']);         exit;     } else {         echo "event failed add";     } } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -