Jump to content

[SOLVED] Once again over my head. Nothing comes out and I cant figure out why


churdaddy

Recommended Posts

Just when I thought I was getting the hang of this. I'm trying to make a small MySQL database with some serial number information. I cant figure out what is wrong with my code though it just gives me a blank page viewing source just gives me the head and body tags. any help would be appreciated.

 

<?php

if ( ! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['End_Serial']  ) &&
! empty( $_REQUEST['Entry_Person']  ) &&
! empty( $_REQUEST['Part_Number']  ) &&
! empty( $_REQUEST['Work_Date']  ) ) {
$dberror = "";
$ret = add_to_database( $_REQUEST['Start_Serial'],
			$_REQUEST['End_Serial'],
			$_REQUEST['Entry_Person'],
			$_REQUEST['Part_Number'],
			$_REQUEST['Work_Date'], $dberror );
if ( ! $ret ) {
print "Error: $dberror<br />\n Contact Josh";
} else {
print "Entry Excepted <A href=\"$_SERVER['PHP_SELF']\">Return to form</a><br />\n";
} else {
write_form();
}

function add_to_database( $Start_Serial, $End_Serial, $Entry_Person, $Part_Number, $Work_Date, &$dberror ) {
$Start_Serial = mysql_real_escape_string($Start_Serial);
$End_Serial = mysql_real_escape_string($End_Serial);
$Entry_Person = mysql_real_escape_string($Entry_Person);
$Part_Number = mysql_real_escape_string($Part_Number);
$Work_Date = mysql_real_escape_string($Work_Date);
$user = 'root';
$pass = 'xxxxx';
$host = 'webserver';
$db = 'serialnumlog';
$conn = mysql_connect($host, $user, $pass);

if( ! $conn ) {$dberror = mysql_error();
return false;
}
if( ! mysql_select_db($db, $conn) ) {$dberror = mysql_error();
return false;
}
return true;
}	

function write_form() {
print <<<EOF
	<form method="post" action="{$_SERVER['PHP_SELF']}">

	<p><input type="text" name="Start_Serial" />
	Start Serial Number</p>
	<p><input type="text" name="End_Serial" />
	End Serial Number</p>
	<p><input type="text" name="Entry_Person" />
	Innitials</p>
	<p><input type="text" name="Part_Number" />
	Part Number</p>
	<p><input type="text" name="Work_Date" />
	Date work was completed</p>
	<p><input type="submit" value="submit!" />
	</form>
FORM;
}
?>

Link to comment
Share on other sites

firstly you have everything in "if ( ! empty( $_REQUEST['Start_Serial']  ) &&...."

condition except the function write_form which is called in the if condition..

 

2ndly you are missing "EOF" in the write_form function. replace "FORM" with "EOF"

 

and make sure all the conditions are met.. then only the code will be executed...

 

Link to comment
Share on other sites

are you telling us that you got all below information in the url, wouldnt session's be better then showing all that?

 

if ( ! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['End_Serial']  ) &&
! empty( $_REQUEST['Entry_Person']  ) &&
! empty( $_REQUEST['Part_Number']  ) &&
! empty( $_REQUEST['Work_Date']  ) ) {
$dberror = "";
$ret = add_to_database( $_REQUEST['Start_Serial'],
			$_REQUEST['End_Serial'],
			$_REQUEST['Entry_Person'],
			$_REQUEST['Part_Number'],
			$_REQUEST['Work_Date'], $dberror );

 

Link to comment
Share on other sites

are you telling us that you got all below information in the url, wouldnt session's be better then showing all that?

 

if ( ! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['End_Serial']  ) &&
! empty( $_REQUEST['Entry_Person']  ) &&
! empty( $_REQUEST['Part_Number']  ) &&
! empty( $_REQUEST['Work_Date']  ) ) {
$dberror = "";
$ret = add_to_database( $_REQUEST['Start_Serial'],
			$_REQUEST['End_Serial'],
			$_REQUEST['Entry_Person'],
			$_REQUEST['Part_Number'],
			$_REQUEST['Work_Date'], $dberror );

 

 

No this should all come from the form. If the data does not exist then it shows the form. If the data exist from a previous form post it should put it in the MYSQL database. I'd love to learn to do sessions some day and everythign else, but I'm a complete PHP newb.

Link to comment
Share on other sites

Hi!

 

If that all need to come from a form, use $_POST instead of $_REQUEST.

 

You have a few mistakes in your script. Here is your script:

 

<?php

if ( ! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['End_Serial']  ) &&
! empty( $_REQUEST['Entry_Person']  ) &&
! empty( $_REQUEST['Part_Number']  ) &&
! empty( $_REQUEST['Work_Date']  ) ) {
$dberror = "";
$ret = add_to_database( $_REQUEST['Start_Serial'],
			$_REQUEST['End_Serial'],
			$_REQUEST['Entry_Person'],
			$_REQUEST['Part_Number'],
			$_REQUEST['Work_Date'], $dberror );
if ( ! $ret ) {
print "Error: $dberror<br />\n Contact Josh";
} else {
print "Entry Excepted <A href=\"$_SERVER['PHP_SELF']\">Return to form</a><br />\n";
} else {
write_form();
}

function add_to_database( $Start_Serial, $End_Serial, $Entry_Person, $Part_Number, $Work_Date, &$dberror ) {
$Start_Serial = mysql_real_escape_string($Start_Serial);
$End_Serial = mysql_real_escape_string($End_Serial);
$Entry_Person = mysql_real_escape_string($Entry_Person);
$Part_Number = mysql_real_escape_string($Part_Number);
$Work_Date = mysql_real_escape_string($Work_Date);
$user = 'root';
$pass = 'xxxxx';
$host = 'webserver';
$db = 'serialnumlog';
$conn = mysql_connect($host, $user, $pass);

if( ! $conn ) {$dberror = mysql_error();
return false;
}
if( ! mysql_select_db($db, $conn) ) {$dberror = mysql_error();
return false;
}
return true;
}	

function write_form() {
print <<<EOF
	<form method="post" action="{$_SERVER['PHP_SELF']}">

	<p><input type="text" name="Start_Serial" />
	Start Serial Number</p>
	<p><input type="text" name="End_Serial" />
	End Serial Number</p>
	<p><input type="text" name="Entry_Person" />
	Innitials</p>
	<p><input type="text" name="Part_Number" />
	Part Number</p>
	<p><input type="text" name="Work_Date" />
	Date work was completed</p>
	<p><input type="submit" value="submit!" />
	</form>
FORM;
}
?>

 

Now follow me!

 

In the 19th line write this instead of the existed code: }} else {

In the 45th line after print add: ?>

On the 46th line after <form method="post" action=" add: <?php echo $_SERVER['PHP_SELF']; ?>">

In this same line delete <<<EOF. It is useless.

On the 60th line delete the FROM word and write: <?php

On the 61th line delete the ")" and add: }

 

Is everything working now?

 

 

All the best,

Adika

 

Link to comment
Share on other sites

I tried that and still didn't get something that worked. So I decided to take it in smaller chunks. First I broke out the form into a file called WriteForm.php here

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">


	<p><input type="text" name="Start_Serial" />
	Start Serial Number</p>
	<p><input type="text" name="End_Serial" />
	End Serial Number</p>
	<p><input type="text" name="Entry_Person" />
	Innitials</p>
	<p><input type="text" name="Part_Number" />
	Part Number</p>
	<p><input type="text" name="Work_Date" />
	Date work was completed</p>
	<p><input type="submit" value="submit!" />
	</form>

 

This page shows the form fine. I decided to start debugging the first if statement and made a page called simpleform.php it shows fine until you actually post data then it breaks.

<?php
if ( ! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_POST['Start_Serial']  ) &&
! empty( $_POST['End_Serial']  ) &&
! empty( $_POST['Entry_Person']  ) &&
! empty( $_POST['Part_Number']  ) &&
! empty( $_POST['Work_Date']  ) ) {
$dberror = "";
$ret = add_to_database( $_POST['Start_Serial'],
			$_POST['End_Serial'],
			$_POST['Entry_Person'],
			$_POST['Part_Number'],
			$_POST['Work_Date'], $dberror );
}
echo 'here';
echo "$ret";
include('./WriteForm.php');
?>

Like I said this comes up fine then it goes blank after posting the data. I tried it with both $_POST and $_REQUEST. If I can figure this out then maybe I can add the rest.

Link to comment
Share on other sites

Hi!

 

Here is the right code! It works!

 

<?php

if ( ! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['Start_Serial']  ) &&
! empty( $_REQUEST['End_Serial']  ) &&
! empty( $_REQUEST['Entry_Person']  ) &&
! empty( $_REQUEST['Part_Number']  ) &&
! empty( $_REQUEST['Work_Date']  ) ) {
$dberror = "";
$ret = add_to_database( $_REQUEST['Start_Serial'],
			$_REQUEST['End_Serial'],
			$_REQUEST['Entry_Person'],
			$_REQUEST['Part_Number'],
			$_REQUEST['Work_Date'], $dberror );
if ( ! $ret ) {
print "Error: $dberror<br />\n Contact Josh";
} else {
print "Entry Excepted <A href=\"".$_SERVER['PHP_SELF']."\">Return to form</a><br />\n";
} } else {
write_form();
}

function add_to_database( $Start_Serial, $End_Serial, $Entry_Person, $Part_Number, $Work_Date, &$dberror ) {
$Start_Serial = mysql_real_escape_string($Start_Serial);
$End_Serial = mysql_real_escape_string($End_Serial);
$Entry_Person = mysql_real_escape_string($Entry_Person);
$Part_Number = mysql_real_escape_string($Part_Number);
$Work_Date = mysql_real_escape_string($Work_Date);
$user = 'root';
$pass = 'xxxxx';
$host = 'webserver';
$db = 'serialnumlog';
$conn = mysql_connect($host, $user, $pass);

if( ! $conn ) {$dberror = mysql_error();
return false;
}
if( ! mysql_select_db($db, $conn) ) {$dberror = mysql_error();
return false;
}
return true;
}

function write_form() {
 ?>
	<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

	<p><input type="text" name="Start_Serial" />
	Start Serial Number</p>
	<p><input type="text" name="End_Serial" />
	End Serial Number</p>
	<p><input type="text" name="Entry_Person" />
	Innitials</p>
	<p><input type="text" name="Part_Number" />
	Part Number</p>
	<p><input type="text" name="Work_Date" />
	Date work was completed</p>
	<p><input type="submit" value="submit!" />
	</form>
<?php
}
?>

 

Does it work to you too?

 

 

All the best,

Adika

 

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.