Jump to content

Real zany page output


ultraloveninja

Recommended Posts

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.

 

Link to comment
Share on other sites

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)  {

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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>


 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.