php - Does submitting to database change the results from query being shown? -


here code generating table person see (defaults $date todays date, $date changes based on url variable if select future date or past date. $time $row[time])

$query = mysql_query("select * times", $db); while ($row = mysql_fetch_array($query)){ //grab available times     $time = $row[time];     $query2 = mysql_query("select * appts time = '$time' , date = '$date' ", $db); //select appointments match current date , available times     $aptid = $apt[id];      while($apt = mysql_fetch_array($query2))     {     $mem = $apt[mem];         if($mem != ''){         $class = 'green';     }     $ns = $apt[ns];     $x = $apt[x];     if($ns || $x != ''){         $class = 'yellow';     }     echo "<tr><td class='$class'>$apt[date_set]</td><td class='$class'>";     echo date('h:i a', strtotime($row[time]));     echo "</td>";     $aptid = $apt[id];     echo "<td class='$class'>$apt[name]</td>     <td class='$class'>$apt[phone]</td>     <td class='$class'>$apt[phone2]</td>     <td class='$class'>$apt[src]</td>     <td class='$class'>$apt[coach]</td>     <td class='$class'>$apt[v1]</td>     <td class='$class'>$apt[v2]</td>     <td class='$class'>$apt[mem]</td>     <td align='center' class='$class'>$apt[x]</td>     <td align='center' class='$class'>$apt[ns]</td>     <td class='$class'>$apt[comments]</td>     <td align='center'>";     if($aptid != ''){//i dont want display options on blank rows         echo "<a href='index.php?date=$date&apptid=$aptid&action=edit'>edit</a> &nbsp;         <a href='index.php?year=$year&month=$month&date=$date&apptid=$aptid&action=x'>x</a>&nbsp;          <a href='index.php?year=$year&month=$month&date=$date&apptid=$aptid&action=ns'>ns</a>&nbsp;";         //<a href='index.php?year=$year&month=$month&date=$date&apptid=$aptid&action=delete'>delete</a> (hidden now)     }     echo "</td></tr>";     }    }  ?>     </tbody> </table> 

here code adding new record database

<div class='dialog' title='new appointment'>     <form id='newappt' method='post'>         <table>             <tr>                 <td>time</td>                 <td><select name='time'>                 <? $query = mysql_query("select * times", $db); //set time option times available times db                    while($row = mysql_fetch_array($query)){                     echo "<option value = '$row[time]'>";                     echo date('h:i a', strtotime($row[time]));                      echo "</option>";                    }                 ?>                 </td>             </tr>             <tr>                 <td>date</td>                 <td><input type='text' id='datepicker' name='date'></td>             </tr>             <tr>                 <td>name</td>                 <td><input type='text' name='name'></td>             </tr>             <tr>                 <td>phone</td>                 <td><input type='text' name='phone'></td>             </tr>             <tr>                 <td>phone 2</td>                 <td><input type='text' name='phone2'></td>             </tr>             <tr>                 <td>src</td>                 <td><input type='text' name='src'></td>             </tr>             <tr>                 <td>coach</td>                 <td><input type='text' name='coach'></td>             </tr>             <tr>                 <td>comments</td>                 <td><input type='text' name='comments'></td>             </tr>         </table>         <input type='submit' name='submit-newappt' value='add appointment'>     </form> </div> 

then heres happens on submit:

    if($_post['submit-newappt']){ //when submitted insert new record , display success message.         $dateset = date("y-m-d");         $q = "insert appts (date_set, time, date, name, phone, phone2, src, coach, comments) values ('$dateset', '$_post[time]', '$_post[date]', '$_post[name]', '$_post[phone]', '$_post[phone2]', '$_post[src]', '$_post[coach]', '$_post[comments]')";         $result = mysql_query($q) or die(mysql_error());             echo "<br>new appointment added ";         echo $_post['name'];         echo " @ ";         echo $_post['date'];         echo " @ ";         echo date('h:i a', strtotime($_post['time']));     } 

so i'm viewing today, table show appointments todays date. 'add new appointment' 7/14/2013. changing table show appointments whatever date added appointment instead of staying on today.

tl;dr(ish) - why when adding new record database php query change?

date comes from:

if(isset($_get['date'])){         $date = $_get['date'];     }     if(!$date){         $date = date('y-m-d');     } 


Comments