churdaddy Posted March 2, 2007 Share Posted March 2, 2007 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; } ?> Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 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... Quote Link to comment Share on other sites More sharing options...
btherl Posted March 2, 2007 Share Posted March 2, 2007 "blank page" often means syntax error. In this case it does (itsmeArry has pointed out the problem). An editor which does php syntax highlighting will save you a lot of grief. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 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 ); Quote Link to comment Share on other sites More sharing options...
churdaddy Posted March 2, 2007 Author Share Posted March 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
Adika Posted March 2, 2007 Share Posted March 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
churdaddy Posted March 2, 2007 Author Share Posted March 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
churdaddy Posted March 2, 2007 Author Share Posted March 2, 2007 An editor which does php syntax highlighting will save you a lot of grief. What editor do you use? I've been just using textedit and notepad. Quote Link to comment Share on other sites More sharing options...
Adika Posted March 2, 2007 Share Posted March 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
churdaddy Posted March 5, 2007 Author Share Posted March 5, 2007 It stopped throwing errors but still didnt do quite what I wanted. I broke this into 4 php files and used include like crazy instead of functions. it worked then. Quote Link to comment 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.