php file takes long time loading then returns blank page mysqli -
i'm trying display elements of event in form user edit. want current values entered or selected, want in way don't have validate sorts of info. have calendar picker , want use dropdowns times. code hangs few minutes , returns blank page. overloading server queries or there wrong code?
$id = $_post['id']; /* edit event form */ echo '<form action="edit-event-process.php" method="post">'; echo '<center><table style="text-align:center">'; /* set queries individually allow dropdowns hour, minute, am/pm, category */ /************* query name *******************/ $queryname = mysqli_query($link, "select name events id = " . $id); while($rowname = mysqli_fetch_assoc($queryname)){ foreach($rowname $keyname => $valname){ echo '<tr><td>name: </td><td><input type="text" id="name" name="name" value="' . $valname . '"></td></tr>'; } } /************* query description **************/ $querydesc = mysqli_query($link, "select description events id = " . $id); while($rowdesc = mysqli_fetch_assoc($querydesc)){ foreach($rowdesc $keydesc => $valdesc){ echo '<tr><td>description: </td><td><input type="text" id="description" name="description" value="' . $valdesc . '"></td></tr>'; } } /************* query start date ***************/ $querystdt = mysqli_query($link, "select startdate events id = " . $id); while($rowstdt = mysqli_fetch_assoc($querystdt)){ foreach($rowstdt $keystdt => $valstdt){ echo '<tr><td>start date: </td><td><input type="text" id="startdate" name="startdate" value="' . $valstdt . '"></td></tr>'; } } /************* query day **************/ $queryallday = mysqli_query($link, "select allday events id = " . $id); while($rowallday = mysqli_fetch_assoc($queryallday)){ foreach($rowallday $keyallday => $valallday){ if ($valallday == '1'){ echo '<tr><td>all day? </td><td><input type="checkbox" id="allday" name="allday" checked="checked"></td></tr>'; } else { echo '<tr><td>all day? </td><td><input type="checkbox" id="allday" name="allday"></td></tr>'; } } } /************/ echo '<div id="dates">'; /************/ /************* query start hour ****************/ echo '<tr><td>start hour</td><td><select name="starthour" id="starthour">'; $querysthr = mysqli_query($link, "select time_format(starttime, '%h') starthour id = " . $id); while ($rowsthr = mysqli_fetch_assoc($resultsthr)){ foreach($rowsthr $keysthr => $valsthr){ $selectedsthr = $valsthr; } } if ($valsthr == "" || $valsthr == "null"){ echo '<option value="null">--</option>'; } else { echo '<option value="'.$valsthr.'">' . $valsthr . '</option>'; echo '<option value="null">--</option>'; } $sthr = 0; while($sthr < 13){ echo '<option value="'.$sthr.'">' . $sthr . '</option>'; $sthr = $sthr++; } echo '</select></td></tr>'; /************* query start min *****************/ echo '<tr><td>start minute</td><td><select name="startmin" id="startmin">'; $querystmin = mysqli_query($link, "select time_format(starttime, '%m') startmin id = " . $id); while ($rowstmin = mysqli_fetch_assoc($resultstmin)){ foreach($rowstmin $keystmin => $valstmin){ $selectedstmin = $valstmin; } } if ($valstmin == "" || $valstmin == "null"){ echo '<option value="null">--</option>'; } else{ if ($valstmin < 10){ echo '<option value="0'.$valstmin.'">0' . $valstmin . '</option>'; echo '<option value="null">--</option>'; } else { echo '<option value="'.$valstmin.'">' . $valstmin . '</option>'; echo '<option value="null">--</option>'; } } $stmin = 0; while($stmin < 60){ if ($stmin < 10){ echo '<option value="0'.$stmin.'">0' . $stmin . '</option>'; } else { echo '<option value="'.$stmin.'">' . $stmin . '</option>'; } $stmin = $stmin +5; } echo '</select></td></tr>'; /************* query start ampm ****************/ echo '<tr><td>start am/pm</td><td><select name="stap" id="stap">'; $querystap = mysqli_query($link, "select time_format(starttime, '%p') stap id = " . $id); while ($rowstap = mysqli_fetch_assoc($resultstap)){ foreach($rowstap $keystap => $valstap){ $selected = $valstap; } } if ($valstap != ""){ echo '<option selected name="stap" value="' . $valstap . '">' . $valstap . '</option>'; } echo '<option value="--">--</option>'; echo '<option value="am">am</option>'; echo '<option value="pm">pm</option>'; echo '</select></td></tr>'; /************* query end date *****************/ $queryenddt = mysqli_query($link, "select enddate events id = " . $id); while($rowenddt = mysqli_fetch_assoc($queryenddt)){ foreach($rowenddt $keydesc => $valenddt){ echo '<tr><td>start date: </td><td><input type="text" id="startdate" name="startdate" value="' . $valenddt . '"></td></tr>'; } } /************* query end hour *****************/ echo '<tr><td>end hour</td><td><select name="endhour" id="endhour">'; $queryendhr = mysqli_query($link, "select time_format(endtime, '%h') endhour id = " . $id); while ($rowendhr = mysqli_fetch_assoc($resultendhr)){ foreach($rowendhr $keyendhr => $valendhr){ $selectedendhr = $valsendhr; } } if ($valendhr == "" || $valendhr == "null"){ echo '<option value="null">--</option>'; } else { echo '<option value="'.$valendhr.'">' . $valendhr . '</option>'; echo '<option value="null">--</option>'; } $endmin = 0; while($endmin < 13){ echo '<option value="'.$endmin.'">' . $endmin . '</option>'; $endmin = $endmin++; } echo '</select></td></tr>'; /************* query end min ******************/ echo '<tr><td>start minute</td><td><select name="endmin" id="endmin">'; $queryendmin = mysqli_query($link, "select time_format(endtime, '%m') endmin id = " . $id); while ($rowendmin = mysqli_fetch_assoc($resultendmin)){ foreach($rowendmin $keyendmin => $valendmin){ $selectedendmin = $valendmin; } } if ($valendmin == "" || $valendmin == "null"){ echo '<option value="null">--</option>'; } else{ if ($valendmin < 10){ echo '<option value="0'.$valendmin.'">0' . $valendmin . '</option>'; echo '<option value="null">--</option>'; } else { echo '<option value="'.$valendmin.'">' . $valendmin . '</option>'; echo '<option value="null">--</option>'; } } $endmin = 0; while($endmin < 60){ if ($endmin < 10){ echo '<option value="0'.$endmin.'">0' . $endmin . '</option>'; } else { echo '<option value="'.$endmin.'">' . $endmin . '</option>'; } $endmin = $endmin +5; } echo '</select></td></tr>'; /************* query end ampm *****************/ echo '<tr><td>end am/pm</td><td><select name="endap" id="endap">'; $querystap = mysqli_query($link, "select time_format(starttime, '%p') endap id = " . $id); while ($rowendap = mysqli_fetch_assoc($resultendap)){ foreach($rowendap $keyendap => $valendap){ $selected = $valendap; } } if ($valendap != ""){ echo '<option selected name="stap" value="' . $valendap . '">' . $valendap . '</option>'; } echo '<option name="endap" value="--">--</option>'; echo '<option name="endap" value="am">am</option>'; echo '<option name="endap" value="pm">pm</option>'; echo '</select></td></tr>'; /*************/ echo '</div>'; /************/ /************* query place ********************/ $queryplace = mysqli_query($link, "select place events id = " . $id); while($rowplace = mysqli_fetch_assoc($queryplace)){ foreach($rowplace $keyplace => $valplace){ echo '<tr><td>place: </td><td><input type="text" id="place" name="place" value="' . $valplace . '"></td></tr>'; } } /************** query category *****************/ echo '<tr><td>category</td><td><select name="category" id="category">'; $query2 = "select category events id = " . $id; $result2 = mysqli_query($link, $query2); while ($row2 = mysqli_fetch_assoc($result2)){ foreach($row2 $key2 => $val2){ $selected = $val2; } } echo '<option name="none" value="">none</option>'; $querycategory = "select name categories"; $result = mysqli_query($link, $querycategory); while($row1 = mysqli_fetch_assoc($result)){ foreach($row1 $key1 => $val1){ if ($val1 != ""){ if ($val1 == $val2){ echo '<option selected name="' . $key . '" value="' . $val1 . '">' . $val1 . '</option>'; } else { echo '<option name="' . $key . '" value="' . $val1 . '">' . $val1 . '</option>'; } } } } echo '</select></td></tr>'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '<tr><td><input type="submit" value="save changes" /></td></tr>'; echo "</table>"; echo "</form>";
this isn't complete answer, i'd recommend have @ , revise code. you're running unnecessary queries , there security error too.
//this needs casted here (assuming int) $id = (int) $_post['id']; /* edit event form */ echo '<form action="edit-event-process.php" method="post">'; echo '<center><table style="text-align:center">'; /* don't queries individually */ $queryevent = mysqli_query($link, "select name,description,startdate,allday events id = " . $id); if($row = mysqli_fetch_assoc($queryevent)){ ?> <tr> <td>name: </td> <td><input type="text" id="name" name="name" value="<?php echo $row['name']; ?>"></td> </tr> <tr> <td>description: </td> <td><input type="text" id="description" name="description" value="<?php echo $row['description']; ?>"></td> </tr> <tr> <td>start date: </td> <td><input type="text" id="startdate" name="startdate" value="<?php echo $row['startdate']; ?>"></td> </tr> <tr> <td>all day? </td> <td><input type="checkbox" id="allday" name="allday"<?php if($row['allday'] == '1') echo 'checked="checked"'; ?>></td></tr>'; </tr> <?php }
Comments
Post a Comment