anne3marie Posted June 1, 2012 Share Posted June 1, 2012 I have been working for hours! I have a html form that submits to a php to update my sql database. The first bit of code is my registration form. <form name="register" method="post" action="register_member.php"> <p>Please create a free account to get started! </p> <table width="100%" border="0" cellpadding="4" cellspacing="2"> <tr> <td width="34%" align="left" valign="top"><div align="right">First Name</div></td> <td width="66%"><input name="first_name" type="text" id="first_name2" value="<? echo $first_name; ?>"></td> </tr> <tr> <td align="left" valign="top"><div align="right">Last Name</div></td> <td><input name="last_name" type="text" id="last_name" value="<? echo $last_name; ?>"></td> </tr> <tr> <td align="left" valign="top"><div align="right">Email Address</div></td> <td><input name="email_address" type="text" id="email_address" value="<? echo $email_address; ?>"></td> </tr> <tr> <td align="left" valign="top"><div align="right">Username</div></td> <td><input name="username" type="text" id="username" value="<? echo $username; ?>"></td> </tr> <tr> <td align="left" valign="top"><label for="delivery address"> <div align="right">Delivery Address</div> </label></td> <td><input type="text" name="address" id="delivery address" /></td> </tr> <tr> <td align="left" valign="top"><div align="right">City, State</div></td> <td>Roseburg, OR</td> </tr> <tr> <td align="left" valign="top"><div align="right">Zip Code</div></td> <td><label for="Zip"></label> <input type="text" name="zip" id="Zip" /></td> </tr> <tr> <td align="left" valign="top"><div align="right">Phone</div></td> <td><label for="phone"></label> <input type="text" name="phone" id="phone" /></td> </tr> <tr> <td align="left" valign="top"><div align="right">Check all that apply:</div></td> <td><input type="checkbox" name="hill" id="hill" /> <label for="hill">I live on a hill</label></td> </tr> <tr> <td align="left" valign="top"> </td> <td><input type="checkbox" name="hard" id="hard" /> <label for="hard"></label> My house is hard to find</td> </tr> <tr> <td align="left" valign="top"> </td> <td><input type="checkbox" name="gated" id="gated" /> <label for="gated"></label> I live in a gated community</td> </tr> <tr> <td align="left" valign="top"> </td> <td><input type="checkbox" name="apartment" id="apartment" /> <label for="apartment"></label> I live in an apartment</td> </tr> <tr> <td align="left" valign="top"><div align="right">Special instructions, keycode, etc, for your delivery:</div></td> <td><label for="instructions"></label> <textarea name="instructions" id="instructions" cols="35" rows="3"></textarea></td> </tr> <tr> <td align="left" valign="top"><div align="right">Where would you like your delivery rider to leave your box?</div></td> <td><label for="where"></label> <textarea name="where" id="where" cols="35" rows="3"></textarea></td> </tr> <tr> <td align="right">I agree to the NewLeaf <a href="policies.html" onclick="MM_openBrWindow('Policies_and_Procedures.html','','width=500,height=300')">Policies and Procedures:</a></td> <td><input type="checkbox" name="pp_check" id="pp_check" /> <label for="pp_check"></label></td> </tr> <tr> <td align="left" valign="top"> </td> <td><input type="submit" name="Submit" value="Join Now!"></td> </tr> </table> </form> Next this is my register_member.php which should process the form, insert mysql database, and email me that a new member needs to be reviewed. <? include 'db.php'; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $address = $_POST['address']; $zip = $_POST['zip']; $phone = $_POST['phone']; $hill = $_POST['hill']; $hard = $_POST['hard']; $gated = $_POST['gated']; $apartment = $_POST['apartment']; $instructions = $_POST['instructions']; $where = $_POST['where']; $pp_check = $_POST['pp_check']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username) || (!$address) || (!$phone) || (!$where)){ echo 'You did not submit the following required information! <br />';include 'join_form.html';} if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } if(!$address){ echo "Delivery Address is a required field. Please enter it below.<br />"; } if(!$phone){ echo "Phone is a required field. Please enter it below.<br />"; } if(!$where){ echo "Where would you like your delivery driver to leave your box is a required field. Please enter it below.<br />"; } // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ // Enter info into the Database. $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, address, zip, phone, hill, hard, gated, apartment, instructions, where, pp_check, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$address', '$zip', $phone, $hill, $hard, $gated, $apartment, $instructions, $where, $pp_check, now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact NewLeaf Delivery at newleaf@newleafdelivery.com.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "A NewLeaf Member!"; $message = "NewLeaf, $first_name $last_name, just registered online. The delivery address is $address, and email address is $email_address. Check the delivery address and email the new member!! NewLeaf Delivery This is an automated response, please do not reply!"; mail('annemari.riley@gmail.com'|| 'newleaf@newleafdelivery.com', $subject, $message, "From: NewLeaf Delivery<newleaf@newleafdelivery.com>\nX-Mailer: PHP/" . phpversion()); echo "";include 'order_contents.php'; } ?> When I fill out the form, I get this message from the browser "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where, signup_date) VALUES('test', 'test', 'test', 'test', 'test','test','test' at line 1" Test is what I entered into each field. THank you for reading. Hope you can help! Quote Link to comment https://forums.phpfreaks.com/topic/263466-registration-form-not-working-please-help/ Share on other sites More sharing options...
PravinS Posted June 1, 2012 Share Posted June 1, 2012 "where" is reserved word in MySQL which is used as field name in your INSERT query, it may be giving problem, so change the field name or use "`" (back tick) to enclose field name in query may this will help you Quote Link to comment https://forums.phpfreaks.com/topic/263466-registration-form-not-working-please-help/#findComment-1350222 Share on other sites More sharing options...
Stavros Posted June 1, 2012 Share Posted June 1, 2012 Hello there I think you are missing some syntax on this section "$zip', $phone, $hill, $hard, $gated, $apartment, $instructions, $where," you need to add in ' ' etc for each item as you have on the variables before the poit where the error starts. eg '$gated' Quote Link to comment https://forums.phpfreaks.com/topic/263466-registration-form-not-working-please-help/#findComment-1350223 Share on other sites More sharing options...
anne3marie Posted June 1, 2012 Author Share Posted June 1, 2012 I changed 'where' to 'location' and added '' around each entered variable and I am no longer getting an error message but when i submit the form, the register_member.php is completely blank with no errors. here is the updated code. <?php include 'db.php'; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $address = $_POST['address']; $zip = $_POST['zip']; $phone = $_POST['phone']; $instructions = $_POST['instructions']; $location = $_POST['location']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username) || (!$address) || (!$phone) || (!$location)){ echo 'You did not submit the following required information! <br />';include 'join_form.html';} if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } if(!$address){ echo "Delivery Address is a required field. Please enter it below.<br />"; } if(!$phone){ echo "Phone is a required field. Please enter it below.<br />"; } if(!$location){ echo "Where would you like your delivery driver to leave your box is a required field. Please enter it below.<br />"; } // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ // Enter info into the Database. $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, address, zip,phone, instructions, location, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$address', '$zip', '$phone','$instructions', '$location', now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact NewLeaf Delivery at newleaf@newleafdelivery.com.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "A NewLeaf Member!"; $message = "NewLeaf, $first_name $last_name, just registered online. The delivery address is $address, and email address is $email_address. Check the delivery address and email the new member!! NewLeaf Delivery This is an automated response, please do not reply!"; mail('annemari.riley@gmail.com'|| 'newleaf@newleafdelivery.com', $subject, $message, "From: NewLeaf Delivery<newleaf@newleafdelivery.com>\nX-Mailer: PHP/" . phpversion()); echo "";include 'order_contents.php'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/263466-registration-form-not-working-please-help/#findComment-1350227 Share on other sites More sharing options...
darkfreaks Posted June 2, 2012 Share Posted June 2, 2012 According to phplint you have a few uncaught errors in MYSQL you need to fix. Quote Link to comment https://forums.phpfreaks.com/topic/263466-registration-form-not-working-please-help/#findComment-1350493 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.