Getting about:blank page

Codes here !

Moderators: egami, macek, gesf

Post Reply
rjmman
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Jun 17, 2017 12:29 pm

Sat Jun 17, 2017 12:51 pm

My PHP/HTML script displays a form, check for data entered then does an INSERT into a MySQL database. What is happening is the first time in the form entering perfect data then pressing the SUBMIT button goes to the about:blank page. If I leave one of the fields blank, to force an error, the error message displays, then form comes back and I can enter the correct data and press the SUBMIT button and the database gets updated for that and all subsequent records.
So does anyone have an idea of were to look for this behavior? I have scoured the code and for the life of me can not figure it out. It looks like to me that under both scenarios it falls through the same database connect, SQL build and INSERT submit code.
I'm hesitant to upload the code because I'm embarrassed by it. It is not very neat and needs some work, I know. Plus I'll need to learn how to do that :D
Thanks for your help
Rick

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 526
Joined: Mon Feb 22, 2016 5:52 pm

Sat Jun 17, 2017 2:05 pm

Without your code, we cannot see where problems might be.

When you get the post reply box, there are some icons, click on the "</>" button to post your code, it might be easier to post the code then highlight it and click the button.

The most likely problem is your forwarding code 'header()' when all entries are considered correct.

rjmman
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Jun 17, 2017 12:29 pm

Sat Jun 17, 2017 2:17 pm

Thanks for the reply. Here is the code:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fish Ferris Add Catch</title>
<style type="text/css">
<!--
body {
	background-color: #837560;
}
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 16px;
	color: #000;
	font-weight: bold;
}
-->
</style></head>

<body>

<?php 
$now = date("Y-m-d");  //Set the current date to be used in the form
if (isset($_POST['submit'])) {  //If this page is called by a form (thus the POST is set) then check that all the variables have been set prior to trying to add them to the database which could result in an error.



	$message = NULL;  //Create an empty variable and/or reset it to receive new messages to display.
	
	//Check for a User ID
	if (empty($_POST['userid'])){
		$u = FALSE;
		$message .= '<p>You forgot to select a Fisherman!</p>';
	} else {
		$u = $_POST['userid'];
	}
	
	//Check for a Date
	if (empty($_POST['date'])){
		$d = FALSE;
		$message .= '<p>You forgot to select a Date!</p>';
	} else {
		$d = $_POST['date'];
	}

	//Check for a Length
	if (empty($_POST['length'])){
		$l = FALSE;
		$message .= '<p>You forgot to select a Length!</p>';
	} else {
		$l = $_POST['length'];
	}

	//Chech for Pounds
	if (empty($_POST['pounds'])){
		$lbs = FALSE;
		$message .= '<p>You forgot to enter Pounds!</p>';
	} else {
		$lbs = $_POST['pounds'];
	}

	//Chech for Ounces
	if (empty($_POST['ounces'])){
		$oz = FALSE;
		$message .= '<p>You forgot to enter Ounces!</p>';
	} else {
		$oz = $_POST['ounces'];
	}

	//Check for a Species
	if (empty($_POST['species'])){
		$sp = FALSE;
		$message .= '<p>You forgot to select a Species!</p>';
	} else {
		$sp = $_POST['species'];
	}

	//Check for a Lure
	if (empty($_POST['lure'])){
		$lr = FALSE;
		$message .= '<p>You forgot to select a Lure!</p>';
	} else {
		$lr = $_POST['lure'];
	}

	//Post Comments
	$c = $_POST['comments'];
	//  Calculate the total ounces
         $w = ($lbs * 16) + $oz;
	if ($u && $d && $l && $lbs && $oz && $sp && $lr) {  //If everything is OK then

$sql_host = "localhost"; 
$sql_database = "thedes_FishFerris"; 
$sql_table = "FF_LOG"; 
$sql_name = "thedes_manuszr"; 
$sql_password = "fishferris2012";
$conn = mysql_connect($sql_host, $sql_name, $sql_password) or die('Error connecting to mysql'); 
$db_select = mysql_select_db($sql_database, $conn); 
//$query = "INSERT INTO catch_tbl (userid, date, length, weight, species, lure, comments) 
//VALUES ('$u', '$d', '$l', '$lbs', '$oz', '$w', '$sp', '$lr', '$c')";  
//Make the query

// Get fish date, weeknum, and month, from schedule table
	$query ="SELECT max(weeknum), max(fish_date) FROM FF_SCHEDULE
                     WHERE fish_date - curdate() < 5
                     and EXTRACT(YEAR FROM FISH_DATE) = EXTRACT(YEAR FROM CURDATE())";
	$result2 = mysql_query($query) or die(mysql_error());
	while ($row = mysql_fetch_array($result2))
	{
		$wk = $row[0];
                $fd = $row[1];
	}
//Establish pounds and ounces from the weight $w
$weightinpounds=$w/16;
$pound=floor($weightinpounds);
$weightinounces=$weightinpounds-$pound;
$ounce=$weightinounces*16;
//$weightlbsoz=strval($pound) . ' Lbs ' . strval($ounce) . ' Oz';
$weightlbsoz=strval($lbs) . ' Lbs ' . strval($oz) . ' Oz';


//Extract month number from date
$fdmonth = date("m");
	
$query = "INSERT INTO FF_LOG (ID, MONTH, FISH_DATE, WEEK_NO, LENGTH, WEIGHT_OZ, LBS, OZ, WEIGHT_LBS_OZ, NO_OF_FISH, SPECIES, LURE, COMMENTS) VALUES ('$u', '$fdmonth', '$fd', '$wk', '$l', '$w', '$lbs', '$oz', '$weightlbsoz', 1, '$sp', '$lr', '$c')";
		
$result = @mysql_query ($query);  //Run the query
mysql_close();
		
		if ($result){  //If the Insert Query ran OK
		//	echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"2;URL=addfish.php\">";  // This redirects the browser to addfish.php after 2 seconds
			echo '<p><b>This fish has been registered</b></p>';
		//	exit();  //Quit the script
			
		} else { //If it did not run OK
			$message = '<p><b>That fish has not been registered due to an error.  Sorry.</b></p><p>' . mysql_error() . '</p>';
			//echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"3;URL=addfish.php\">";  // This redirects the browser to addfish.php after 3 seconds
		}
		
	} 
	else {
		//$message = '<p>Please try again.</p>';
	}
} //End of the main submit conditional

if (isset($message)) {
	echo '<font color="red">', $message, '</font>';
	$message = ''; // Reset the message variable to clear the values
}
?>

<form action="" method="post">
<fieldset><legend>Enter your fish data in the form below:</legend>

<p><b>User ID:
  <select name="userid" tabindex="1">
  	<option selected="selected"><?php if (isset($_POST['userid'])) echo $_POST['userid']; ?></option>
  	<?php 
//	require_once ('mysql_connect.php');

//$sql_host = "50.97.101.245"; 
$sql_host = "localhost"; 
$sql_database = "thedes_FishFerris"; 
$sql_table = "FF_LOG"; 
$sql_name = "thedes_manuszr"; 
$sql_password = "fishferris2012"; 
$conn = mysql_connect($sql_host, $sql_name, $sql_password) or die('Error connecting to mysql'); 
//2 
$db_select = mysql_select_db("$sql_database", $conn); 
if (!$db_select) { die("Database selection failed1: " . mysql_error()); 
} 


	$query ="SELECT ID FROM FF_MEMBERS WHERE Active=1 ORDER BY ID ASC";
	$result = mysql_query($query) or die(mysql_error());
	while ($row = mysql_fetch_array($result))
	{
		$user = $row['ID'];
		echo "<option>{$user}</option>";
	}
	$row = null;
	mysql_close();
	?>
  </select>
</p>
<p><b>Date:</b> <input type="text" name="date" size="15" tabindex="2" value="<?php if (isset($_POST['date'])){ echo $_POST['date'];}else{ echo $now;} ?>" /></p>

<p><b>Length:</b> <input type="text" name="length" size="5" tabindex="3" value="<?php if (isset($_POST['length'])) echo $_POST['length']; ?>" /></p>

<p><b>Pounds:</b> <input type="text" name="pounds" size="5" tabindex="4" value="<?php if (isset($_POST['pounds'])) echo $_POST['pounds']; ?>" /></p>

<p><b>Ounces:</b> <input type="text" name="ounces" size="5" tabindex="5" value="<?php if (isset($_POST['ounces'])) echo $_POST['ounces']; ?>" /></p>

<p><b>Species:</b> 
  <select name="species" tabindex="6">
   <option selected="selected"><?php if (isset($_POST['species'])) echo $_POST['species']; ?>   </option>
    <option>Largemouth Bass</option>
    <option>Smallmouth Bass</option>
    <option>Pike</option>
    <option>Crappie</option>
    <option>Walleye</option>
    <option>Catfish</option>
    <option>Bullhead</option>
    <option>Perch</option>
    <option>Bluegill/Sunfish</option>
    <option></option>
  </select>
</p>
<p><b>Lure:</b> <input type="text" name="lure" size="60" tabindex="7" maxlength="100" value="<?php if (isset($_POST['lure'])) echo $_POST['lure']; ?>" /></p>
<p><b>Comments:</b> <input type="text" name="comments" size="60" tabindex="8" maxlength="100" value="<?php if (isset($_POST['comments'])) echo $_POST['comments']; 
	
	
?>" /></p>

</fieldset>
 <div align="left"><input type="submit" name="submit" value="Register Fish" /></div>
 
 </form><!-- End of Form -->
 
</body>
</html>

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 526
Joined: Mon Feb 22, 2016 5:52 pm

Sat Jun 17, 2017 3:23 pm

Ok,

The good news: it is not as messy as you thought, it's quite readable -

The bad news: it is completely out of date (by years) and in-secure; mysql functions were deprecated in PHP 5.5 and are not used at all in PHP 7; effectively if you are upgraded to PHP 7, your script will not work.

There is nothing obvious which is re-directing you to your about:us page, but I haven't examined in greater detail as you have so many other problems (which can be fixed relatively easily as you are learning) that it's better to wipe the slate clean and start a fresh, you might be getting a fatal error, do you have error reporting turned on?.

You should be writing HTML 5
Your css should be in a separate file
You should not need to use the @ symbol in front of any function as it suppresses errors, you should always display errors when you are testing then log errors when on a public web site.
You should be using PDO (PHP data objects) for any database activity, I'm not sure how good that link is, but it seemed ok with a quick glance.
Don't publish passwords or usernames, try and edit them out of your post (not sure if you can?).
Only create one connection in a script.
Never trust user input, always verify that the data submitted is correctly formed, the minimum you should be doing when using $_POST or $_GET is

Code: Select all

$var = htmlentities($_POST['user_submitted_data']);
This is a blank (ish) html 5 document

Code: Select all

<!doctype html>
<html lang='en'>
<head>
<title>Minimum</title>
<link href='style.css' rel='stylesheet'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
</head>
<body>
<h1>Minimum</h1>

</body>
</html>

rjmman
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Jun 17, 2017 12:29 pm

Sat Jun 17, 2017 4:43 pm

Thanks. I'll work on it.

rjmman
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Jun 17, 2017 12:29 pm

Sat Jun 24, 2017 5:31 am

Thanks for your help.
So just in case somebody looks at this for a resolution I will briefly update this, then close it.

The problem was in the development, testing side of Wordpress. The problem only occurred there. After 'publishing' the page it worked fine. So I figured out a way around the testing part and am calling it good.

Post Reply