ultraloveninja Posted February 28, 2011 Share Posted February 28, 2011 Hey there! So, I am working trying to get a page to edit and update field to insert back into the DB. But for some odd reason, the page just shows up vlank. I've added it to show errors, but still nothing is coming back, so I have no idea what the issue is. Not too sure if there is a config issue with PHP on my server or what. Here's my code: <?php ini_set('display_errors', 1); //open DB connection include '../dbconn.php'; if ($_POST) { $msg=""; //build an update query $update = "update testspaces set status='$_POST[status]',spacenumber='$_POST[spacenumber]' where id='$_POST[id]'"; //execute query and check to see if it went through if (!mysql_query($update)) { $msg = "Error Updating User"; print $update; } else { $msg = "Record Updated Successfully"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<div class='header2'><a href='adminindex.php'>Go Back To Edit</a></div>"; //print $update; //write a table row confirming the data $table_row = <<<EOR <TR> <td>$status</td> <td>$spacenumber</td> </TR> EOR; } //if not posted, check that an ID has been //passes VIA the URL } else { if (!IsSet($_GET['id'])) { $msg = "No User Selected!"; } else { $id = $_GET['id']; //build and execute da query $select = "select * from testspaces where id=$id"; $result = mysql_query($select); //check to see if the record is there if (mysql_num_rows($result) < 1) { $msg = "No User with that ID is found"; } else { //set the variables for the form code $form_start = "<FORM METHOD=\"post\"ACTION= \"" . $_SERVER['PHP_SELF'] . "\">"; $form_end = ' <TR> <TD COLSPAN="2"><input type="submit" value="Submit Changes" /> <input type="reset" value="Cancel Changes" /></td> </tr> </form> '; //assign the results to an array while ($row = mysql_fetch_array($result)){ $status = $row['status']; $space = $row['spacenumber']; //write out into table row with form fields $table_row = ' <table border="1" align="center" cellpadding="5" cellspacing="0"> <th>Space Number</th> <th>Status</th> </tr> <tr> <td><input type="text" name ="spacenumber" value ="' . $space . '" size="20"/></td> <td><input type="text" name ="status" value ="' . $status . '" size="20"/></td> </tr> <br /> <a href="editemployees.php">Back to Employees</a> '; } // end of while } // end of else num rows } // end of else isset get id } // end of else mysql update //print message echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" : ""; ?> <? echo (IsSet($form_start)) ? $form_start : ""; ?> <input type ="hidden" name="id" value="<? echo $id ?>" /> <? echo (IsSet($table_row)) ? $table_row : ""; ?> <? echo (IsSet($form_end)) ? $form_end : ""; ?> Not too sure what could be causing to become blank. Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/ Share on other sites More sharing options...
Muddy_Funster Posted February 28, 2011 Share Posted February 28, 2011 what's this all about? //print message echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" : ""; ?> <? echo (IsSet($form_start)) ? $form_start : ""; ?> <input type ="hidden" name="id" value="<? echo $id ?>" /> <? echo (IsSet($table_row)) ? $table_row : ""; ?> <? echo (IsSet($form_end)) ? $form_end : ""; ?> why are you breaking out of PHP and then coming back in again on the next line using short tags? also, what are you doing here? if($_POST) { Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180807 Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Author Share Posted February 28, 2011 Well, to be honest with you, this was based off a tutorial that I found in a book, but it has always seemed to work in the past with out any issues. It's a page that will take the info from a DB and populate the info into form field so that you can edit the info that is in them and then submit it so that it will update the table with the edited info. I believe that this part: <? echo (IsSet($form_start)) ? $form_start : ""; ?> <input type ="hidden" name="id" value="<? echo $id ?>" /> <? echo (IsSet($table_row)) ? $table_row : ""; ?> <? echo (IsSet($form_end)) ? $form_end : ""; ?> Is so that it can update the db table to match the ID that is being pulled from the DB. Again, wasn't really explained too much in the book so I am assuming. and I really have no idea why this: if($_POST) { is there or what it does. I have an general understanding of PHP, but have mainly taught myself over the years through trial and error and tweaking tutorials that I could find in books and on the net. This has worked out fine in the past, but if there is a better way to edit information from a DB using PHP so users can login and edit that info, I am more than welcome to any input, or tutorials, or anything that maybe easier and if needed more secure. Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180833 Share on other sites More sharing options...
Muddy_Funster Posted February 28, 2011 Share Posted February 28, 2011 ok, we'll leave the if alone for the moment, let's clean up these short tags first of all, then we may want to have a look at dbconn.php incase the error is in there. change the end code to this: //print message echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" : ""; echo (IsSet($form_start)) ? $form_start : ""; echo '<input type ="hidden" name="id" value="'.$id.'" />'; echo (IsSet($table_row)) ? $table_row : ""; echo (IsSet($form_end)) ? $form_end : ""; ?> if this make no difference, post up your dbconn.php aswell. Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180840 Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Author Share Posted February 28, 2011 Wow. That seemed to do the trick! It updated successfully even though it spit out this error: Warning: main(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for '-6.0/no DST' instead in C:\Inetpub\thedunhams\test\admin\edit-space.php on line 111 Notice: Undefined variable: id in C:\Inetpub\thedunhams\test\admin\edit-space.php on line 111 No idea why it says that, but it worked. Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180857 Share on other sites More sharing options...
Muddy_Funster Posted February 28, 2011 Share Posted February 28, 2011 it's reffering to the timezone settings in your php.ini file. the defaults havn't been set properly. are you running this on a local server? Quick tags (<?) have been depreciated, so should be avoided. Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180862 Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Author Share Posted February 28, 2011 Yep. I think I found where in the php.ini file to set that, but I am not sure what it needs to be set at. Honestly, I have never encountered this error in the past. I wonder if I missed something when I setup PHP...? Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180867 Share on other sites More sharing options...
Muddy_Funster Posted February 28, 2011 Share Posted February 28, 2011 PHP5 yeah? I was having some massive headaches with PHP5 (that was one of them), finaly binned it and went back to 4. Search the PHP manual pages for the timezone settings, it's country specific (I get bonus points for stating the obvious ) so you'll need to find the value for your country there. Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180878 Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Author Share Posted February 28, 2011 cool, yeah, I think I got it. I added my "timezone" area and that seemed to fix it. Getting only 2 of these tho: Undefined variable: id in (etc...) and Notice: Undefined variable: status in (etc...) but it's still working, so, I guess I could just turn off reporting the errors on the page and let it roll. Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180889 Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 DO NOT use PHP4. Learn PHP5. If you are having problems with PHP5, post them here and we can help you. Ken Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180893 Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Author Share Posted February 28, 2011 Is there any way to get rid of those two undefined variable errors? Or are they there cause PHP just says they are? Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180940 Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 Please post all your code and the full error messages. Ignoring errors just because the "code runs fine" is like ignoring the warning when the gas gauge on a car warns that the car is low on gas. Yes, the car is running fine when the warning is given, but if you don't get more gas soon, the car will stop. If you ignore the error, eventually it will cause problems. Ken Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180943 Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Author Share Posted February 28, 2011 Sorry about that. Here's the code with the fix that was implemented from the previous posts: <?php ini_set('display_errors', 1); //open DB connection include '../dbconn.php'; if ($_POST) { $msg=""; //build update query $update = "update testspaces set status='$_POST[status]',spacenumber='$_POST[spacenumber]' where id='$_POST[id]'"; //execute query and check to see if it went through if (!mysql_query($update)) { $msg = "Error Updating User"; print $update; } else { $msg = "Record Updated Successfully"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<div class='header2'><a href='adminindex.php'>Go Back To Edit</a></div>"; //print $update; //write a table row confirming the data $table_row = <<<EOR <TR> <td>$status</td> <td>$spacenumber</td> </TR> EOR; } //if not posted, check that an ID has been //passes VIA the URL } else { if (!IsSet($_GET['id'])) { $msg = "No User Selected!"; } else { $id = $_GET['id']; //build and execute da query $select = "select * from testspaces where id=$id"; $result = mysql_query($select); //check to see if the record is there if (mysql_num_rows($result) < 1) { $msg = "No User with that ID is found"; } else { //set the variables for the form code $form_start = "<FORM METHOD=\"post\"ACTION= \"" . $_SERVER['PHP_SELF'] . "\">"; $form_end = ' <TR> <TD COLSPAN="2"><input type="submit" value="Submit Changes" /> <input type="reset" value="Cancel Changes" /></td> </tr> </form> '; //assign the results to an array while ($row = mysql_fetch_array($result)){ $status = $row['status']; $space = $row['spacenumber']; //write out into table row with form fields $table_row = ' <table border="1" align="center" cellpadding="5" cellspacing="0"> <th>Space Number</th> <th>Status</th> </tr> <tr> <td><input type="text" name ="spacenumber" value ="' . $space . '" size="20"/></td> <td><input type="text" name ="status" value ="' . $status . '" size="20"/></td> </tr> <br /> <a href="editemployees.php">Back to Employees</a> '; } // end of while } // end of else num rows } // end of else isset get id } // end of else mysql update //print message echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" : ""; echo (IsSet($form_start)) ? $form_start : ""; echo '<input type ="hidden" name="id" value="'.$id.'" />'; echo (IsSet($table_row)) ? $table_row : ""; echo (IsSet($form_end)) ? $form_end : ""; ?> and here are the two errors: Notice: Undefined variable: status in C:\Inetpub\thedunhams\test\admin\edit-space.php on line 45 Notice: Undefined variable: spacenumber in C:\Inetpub\thedunhams\test\admin\edit-space.php on line 46 Notice: Undefined variable: id in C:\Inetpub\thedunhams\test\admin\edit-space.php on line 111 Don't know where or what could be causing those issues. Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180945 Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 The code you posted doesn't have 111 lines. Ken Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180955 Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Author Share Posted February 28, 2011 Here's the full code: <html> <head> <title>Edit Spaces</title> <link href="../css/styles.css" rel="stylesheet" type="text/css"> </head> <body> <div> <span class="header">Edit Spaces</span><br> <br> <?php ini_set('display_errors', 1); //open DB connection include '../dbconn.php'; if ($_POST) { $msg=""; //build an update query $update = "update testspaces set status='$_POST[status]',spacenumber='$_POST[spacenumber]' where id='$_POST[id]'"; //execute query and check to see if it went through if (!mysql_query($update)) { $msg = "Error Updating User"; print $update; } else { $msg = "Record Updated Successfully"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<div class='header2'><a href='adminindex.php'>Go Back To Edit</a></div>"; //print $update; //write a table row confirming the data $table_row = <<<EOR <TR> <td>$status</td> <td>$spacenumber</td> </TR> EOR; } //if not posted, check that an ID has been //passes VIA the URL } else { if (!IsSet($_GET['id'])) { $msg = "No User Selected!"; } else { $id = $_GET['id']; //build and execute da query $select = "select * from testspaces where id=$id"; $result = mysql_query($select); //check to see if the record is there if (mysql_num_rows($result) < 1) { $msg = "No User with that ID is found, dork..."; } else { //set the variables for the form code $form_start = "<FORM METHOD=\"post\"ACTION= \"" . $_SERVER['PHP_SELF'] . "\">"; $form_end = ' <TR> <TD COLSPAN="2"><input type="submit" value="Submit Changes" /> <input type="reset" value="Cancel Changes" /></td> </tr> </form> '; //assign the results to an array while ($row = mysql_fetch_array($result)){ $status = $row['status']; $space = $row['spacenumber']; //write out into table row with form fields $table_row = ' <table border="1" align="center" cellpadding="5" cellspacing="0"> <th>Space Number</th> <th>Status</th> </tr> <tr> <td><input type="text" name ="spacenumber" value ="' . $space . '" size="20"/></td> <td><input type="text" name ="status" value ="' . $status . '" size="20"/></td> </tr> <br /> <a href="adminindex.php">Back to Edit</a> '; } // end of while } // end of else num rows } // end of else isset get id } // end of else mysql update //print message echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" : ""; echo (IsSet($form_start)) ? $form_start : ""; echo '<input type ="hidden" name="id" value="'.$id.'" />'; echo (IsSet($table_row)) ? $table_row : ""; echo (IsSet($form_end)) ? $form_end : ""; ?> </table> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/229097-real-zany-page-output/#findComment-1180959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.