TronB24 Posted July 6, 2010 Share Posted July 6, 2010 I've coded this form which I've used the base code for several times but for whatever reason on my latest attempt my script is not working. When I click the submit button all I get is blank page. I've tried rewriting the script piece by piece but I'm having no luck. The for is supposed to submit the users into a database and then eventually I will write a mail function once I can get it at least submit the data. Here's my code sans page styling, etc. <?php if(isset($submit)) { // Handle the form. function escape_data($data) { global $dbc; if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_escape_string($data); } $message = NULL; // Create an empty new variable. if ($_POST['unitSize'] == 'Please Choose') { $unitSize = FALSE; $message .= '<p>You forgot to enter your chain size.</p>'; } else { $unitSize = escape_data($_POST['unitSize']); } if (empty($_POST['firstName'])) { $firstName = FALSE; $message .= '<p>You forgot to enter your first name.</p>'; } else { $firstName = escape_data($_POST['firstName']); } if (empty($_POST['lastName'])) { $lastName = FALSE; $message .= '<p>You forgot to enter your last name.</p>'; } else { $lastName = escape_data($_POST['lastName']); } if (empty($_POST['businessName'])) { $businessName = FALSE; $message .= '<p>You forgot to enter your business name.</p>'; } else { $businessName = escape_data($_POST['businessName']); } if (empty($_POST['address'])) { $address = FALSE; $message .= '<p>You forgot to enter your address.</p>'; } else { $address = escape_data($_POST['address']); } if (empty($_POST['city'])) { $city = FALSE; $message .= '<p>You forgot to enter your city.</p>'; } else { $city = escape_data($_POST['city']); } if ($_POST['state'] == 'Please Choose') { $state = FALSE; $message .= '<p>You forgot to enter your state.</p>'; } else { $state = escape_data($_POST['state']); } if (empty($_POST['zip'])) { $zip = FALSE; $message .= '<p>You forgot to enter your zip code.</p>'; } else { $zip = escape_data($_POST['zip']); } if (empty($_POST['phone'])) { $phone = FALSE; $message .= '<p>You forgot to enter your telephone number.</p>'; } else { $phone = escape_data($_POST['phone']); } if (empty($_POST['email'])) { $email = FALSE; $message .= '<p>You forgot to enter your email address.</p>'; } else { $email = escape_data($_POST['email']); } if ($unitSize && $firstName && $lastName && $businessName && $address && $city && $state && $zip && $phone && $email) { // If everythings OK. require_once ('/include/dbnrn.php'); // Register user to database. $query = "INSERT INTO leads (unitSize, firstName, lastName, businessName, address, city, state, zip, phone, email, webaddress, registration_date) VALUES ('$unitSize', '$firstName', '$lastName', '$businessName', '$address', '$city', '$state', '$zip', '$phone', '$email', '$webaddress',NOW() )"; $result = @mysql_query ($query); if ($result) { // If it ran OK. // Redirect user and close script. header ('Location: success.php'); exit(); // Quit the script. } else { $message .= '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p><p>' .mysql_error().' </p>'; } mysql_close(); } else { $message .= '<p align="center">Please fill in the missing field(s)</p>'; } } // End of the Submit coniditional ?> <!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>Monin Gourmet Flavorings: Ultimate Taste, Ultimate Creativity</title> <link href="/css/nrnform.css" rel="stylesheet" type="text/css" media="all" /> </head> <body> <?php if (isset($message)) { echo "$message" ; } ?> <form action="<?php echo $_POST['PHP_SELF']; ?>" method="post"> <table width="100%" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="4" class="emphasis"><label for="unitSize" class="shadow">How many stores do you have?</label> <br /> <select name="unitSize" id="unitSize"> <option value="Please Choose">Please Choose</option> <option value="small">1-25</option> <option value="medium">26-50</option> <option value="large">51+</option> </select></td> </tr> <tr> <td><span class="shadow">First Name: </span><br /> <label for="firstName" class="round"><span><input name="firstName" type="text" id="firstName" value="<?php if (isset($_POST['firstName'])) echo $_POST['firstName']; ?>" style="width:100%"/></span></label></td> <td colspan="3"> <span class="shadow">Last Name: </span><br /> <label for="lastName" class="round"><span><input name="lastName" type="text" class="textInput" id="lastName" value="<?php if (isset($_POST['lastName'])) echo $_POST['lastName']; ?>" style="width:230px"/></span></label></td> </tr> <tr> <td colspan="4"><span class="shadow"> Operation Name:</span> <br /> <label for="businessName" class="round"><span><input name="businessName" type="text" id="businessName" value="<?php if (isset($_POST['businessName'])) echo $_POST['businessName']; ?>" style="width:360px"/></span></label></td> </tr> <tr> <td colspan="4" valign="top"> <span class="shadow">Address: </span><br /> <label for="address" class="round"><span><input name="address" type="text" id="address" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>" style="width:360px" /></span></label></td> </tr> <tr valign="top"> <td><span class="shadow"> City:</span> <br /> <label for="city" class="round"><span class="submit"><input name="city" type="text" id="city" value="<?php if (isset($_POST['city'])) echo $_POST['city']; ?>" /></span></label></td> <td><label for="state" class="shadow"> State:</label> <br /> <select name="state" id="state"> <option value="Please Choose" selected>Please Choose <option value="AL">Alabama <option value="AK">Alaska <option value="AR">Arkansas <option value="AZ">Arizona <option value="CA">California <option value="CO">Colorado <option value="CT">Connecticut <option value="DE">Delaware <option value="FL">Florida <option value="GA">Georgia <option value="HI">Hawaii <option value="IA">Iowa <option value="ID">Idaho <option value="IL">Illinois <option value="IN">Indiana <option value="KS">Kansas <option value="KY">Kentucky <option value="LA">Louisiana <option value="ME">Maine <option value="MD">Maryland <option value="MA">Massachusetts <option value="MI">Michigan <option value="MN">Minnesota <option value="MS">Mississippi <option value="MO">Missouri <option value="MT">Montana <option value="NE">Nebraska <option value="NV">Nevada <option value="NH">New Hampshire <option value="NJ">New Jersey <option value="NM">New Mexico <option value="NY">New York <option value="NC">North Carolina <option value="ND">North Dakota <option value="OH">Ohio <option value="OK">Oklahoma <option value="OR">Oregon <option value="PA">Pennsylvania <option value="RI">Rhode Island <option value="SC">South Carolina <option value="SD">South Dakota <option value="TN">Tennessee <option value="TX">Texas <option value="UT">Utah <option value="VT">Vermont <option value="VA">Virginia <option value="WA">Washington <option value="DC">Washington D.C. <option value="WV">West Virginia <option value="WI">Wisconsin <option value="WY">Wyoming <option value="Please Choose">--------- <option value="PR">Puerto Rico <option value="VI">Virgin Islands </select></td> <td><span class="shadow"> Zip:</span> <br /> <label for="zip" class="round"><span><input name="zip" type="text" id="zip" value="<?php if (isset($_POST['zip'])) echo $_POST['zip']; ?>" style="width:70px"/></span></label> </td> </tr> <tr> <td></td> <td colspan="3"></td> </tr> <tr> <td colspan="4"><span class="shadow">Company web address:</span> <br /> <label for="webaddress" class="round"><span><input name="web" type="text" id="web" value="<?php if (isset($_POST['web'])) echo $_POST['web']; ?>" style="width:360px" /></span></label></td> </tr> <tr> <td><span class="shadow"> Phone:</span> <br /> <label for="phone" class="round"><span><input name="phone" type="text" id="phone" value="<?php if (isset($_POST['phone'])) echo $_POST['phone']; ?>" maxlength="15" /></span></label></td> <td colspan="3"><label for="email" class="shadow"> Email:</label> <br /> <label for="email" class="round"><span><input name="email" type="text" id="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" style="width:230px"/></span></label></td> </tr> <tr align="center"> <td colspan="3"><label for="submit"><input name="submit" type="submit" id="submit" value="Submit Request" /></label></td> </tr> </table> <input type="hidden" name="userID" id="userID" /> </form> </body> </html> Thanks a million times over for help Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/ Share on other sites More sharing options...
AbraCadaver Posted July 6, 2010 Share Posted July 6, 2010 It's the simple things: if(isset($_POST['submit'])) { // Handle the form. Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1081948 Share on other sites More sharing options...
TronB24 Posted July 6, 2010 Author Share Posted July 6, 2010 Thanks for looking at this. I just fixed that line and it's still submitting blank. I'm not sure what's going on. Here's the form in action with that revision, which I can't believe I overlooked. http://us.monin.com/nrninquiry.php Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1081951 Share on other sites More sharing options...
AbraCadaver Posted July 6, 2010 Share Posted July 6, 2010 Most likely a parse error. Since it loads the first time then it is probably in the required file or the required file isn't found: require_once ('/include/dbnrn.php'); Do this at the top of the main page: error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1081968 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2010 Share Posted July 6, 2010 I concur with AbraCadaver (lulz on the username, btw). Probably can't find the required file. What errors are you getting in your PHP error log? You DO log errors, right? Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1081969 Share on other sites More sharing options...
TronB24 Posted July 6, 2010 Author Share Posted July 6, 2010 Unfortunately I'm embarrassed to say that I don't log errors. I'm pretty new at this and not really sure how to do that yet. So I put that code at the top of my page. Was something supposed to happen? The required file is my db connection script. I'm pretty sure it functions like it's supposed to but like you said, I'm not really sure if it's being found by my page. Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1081977 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2010 Share Posted July 6, 2010 Having those two lines of code immediately after your first opening <?php tag line of code should show runtime errors, warnings, and notices (you may need to do a 'view source' of your page in your browser to see some of them because if they occure inside of some html tags and elements, such as a form, they will appear in the source of the page but they won't appear in the rendered output of the page.) If you are getting a blank page, you likely have a fatal parse error and setting those two values in your code won't help. You should be developing and debugging php code on a local development system where you can set those two values before your code is requested (in the master php.ini) so that they will report and display all the php detected errors. You will also save a ton of time, because constantly uploading files to your web server to see one result wastes a huge amount of your time. You also have an error in your form's action="" attribute. It's not $_POST['PHP_SELF'] it is $_SERVER['PHP_SELF']. Edit: Also as has already been suggested, your require_once() is probably failing and stopping code execution. A leading slash on a file system path refers to the root of the current hard disk and I doubt that is where your /include/ folder is located nor do you likely have access to the root of the hard disk on your web hosting. Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1081985 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2010 Share Posted July 6, 2010 I suspect the problem is going to be in the path specification to the included file. Comment it out, and try these (one at a time, obviously). One may work for you, but not knowing your directory structure, I can't say for sure. require_once ('include/dbnrn.php'); require_once ('../include/dbnrn.php'); require_once ('./include/dbnrn.php'); Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1081989 Share on other sites More sharing options...
TronB24 Posted July 6, 2010 Author Share Posted July 6, 2010 This is what I'm getting with the log. Notice: Undefined variable: webaddress in /var/www/vhosts/monin.com/subdomains/us/httpdocs/nrninquiry.php on line 96 Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/monin.com/subdomains/us/httpdocs/nrninquiry.php:96) in /var/www/vhosts/monin.com/subdomains/us/httpdocs/nrninquiry.php on line 103 line 96 in my page $query = "INSERT INTO leads (unitSize, firstName, lastName, businessName, address, city, state, zip, phone, email, webaddress, registration_date) VALUES ('$unitSize', '$firstName', '$lastName', '$businessName', '$address', '$city', '$state', '$zip', '$phone', '$email', '$webaddress',NOW() )"; line 103 header ('Location: http://us.monin.com/success.php'); Thanks for all of you guys help. I'm still stumped though. Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1081994 Share on other sites More sharing options...
wildteen88 Posted July 6, 2010 Share Posted July 6, 2010 You appear to be inserting the variable $webaddress in your query. This variable is not being defined in your code. Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1082002 Share on other sites More sharing options...
kenrbnsn Posted July 6, 2010 Share Posted July 6, 2010 Where is $webaddress being set? I don't see it in the code you posted. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1082003 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2010 Share Posted July 6, 2010 Here are the errors I get when I submit the form on your website. Looks like (for now, at least) the problem is with the require_once() path specification. Warning: main(): open_basedir restriction in effect. File(/dbnrn.php) is not within the allowed path(s): (/var/www/vhosts/monin.com/subdomains/us/httpdocs:/tmp) in /var/www/vhosts/monin.com/subdomains/us/httpdocs/nrninquiry.php on line 91 Warning: main(/dbnrn.php): failed to open stream: Operation not permitted in /var/www/vhosts/monin.com/subdomains/us/httpdocs/nrninquiry.php on line 91 Fatal error: main(): Failed opening required '/dbnrn.php' (include_path='.:/usr/share/pear') in /var/www/vhosts/monin.com/subdomains/us/httpdocs/nrninquiry.php on line 91 Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1082006 Share on other sites More sharing options...
TronB24 Posted July 6, 2010 Author Share Posted July 6, 2010 You guys put me on the right path. You all were correct that my require_once file not being found. I changed require_once ('/include/dbnrn.php'); to require_once ($_SERVER['DOCUMENT_ROOT'] . "/include/dbnrn.php"); I'll be honest in admitting that I have no idea why this was necessary. Also I did change the $webaddress variable to $web somewhere in my trouble shooting. So I fixed that. The form appears to be working now. I can see the results in my db. Now the next steps for me are to figure out how to customize the the "success" page message based on the unit size selection and writing the email script. Thank you all for your help. I've been working on this for about 4 hours now Quote Link to comment https://forums.phpfreaks.com/topic/206898-form-is-submiting-blank-please-help/#findComment-1082010 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.