ianhaney50 Posted June 18, 2015 Share Posted June 18, 2015 Hi Sorry am stuck again, I know I need to sanitize the PHP etc. but just want to get the form saving the data to my mysql databas but is not for some reason and can't remember what I did yesterday to get the form to work instead of just resetting itself <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php $title = "Sign Up - Micromend"; $pgDesc=""; $pgKeywords=""; include ( 'includes/header.php' ); ?> <!--CONTENT--> <div id="column-whole-inner"> <div id="login"> <h2>Visitor's Form</h2> <br /> <form action="" method="post"> <label>Name :</label> <input type="text" name="visitor_name" required="required" placeholder="Please Enter Name"/> <br /><br /> <label>Email :</label> <input type="email" name="visitor_email" required="required" placeholder="john123@gmail.com"/> <br/><br /> <label>Address Line 1 :</label> <input type="text" name="visitor_firstline" required="required" placeholder="Please Enter First Line of your address"/> <br><br> <label>Address Line 2 :</label> <input type="text" name="visitor_secondline" required="required" placeholder="Please Enter Second Line of your address"/> <br><br> <label>Town :</label> <input type="text" name="visitor_town" required="required" placeholder="Please Enter your Town"/> <br><br> <label>County :</label> <input type="text" name="visitor_county" required="required" placeholder="Please Enter Your County"/> <br/><br /> <label>Postcode :</label> <input type="text" name="visitor_postcode" required="required" placeholder="Please Enter Your Postcode"/> <br><br> <label>Telephone Number :</label> <input type="text" name="visitor_tel" required="required" placeholder="Please Enter Your Telephone Number"/> <br><br> <label>Mobile Number :</label> <input type="text" name="visitor_mobile" required="required" placeholder="Please Enter Your Mobile Number"/> <br><br> <label>Receive our Monthly Newsletter :</label> <br> <input type="radio" name="visitor_newsletter" value="Yes"><label>Yes</label> <br> <input type="radio" name="visitor_newsletter" value="No"><label>No</label> <br><br> <input type="submit" value=" Submit " name="submit"/> <br /> </form> </div> </div> <!--CONTENT--> <?php if(isset($_POST["submit"])){ $servername = ""; $username = ""; $password = ""; $dbname = ""; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "INSERT INTO visitors (visitor_name, visitor_email, visitor_firstline, visitor_secondline, visitor_town, visitor_county, visitor_postcode, visitor_tel, visitor_mobile, visitor_newsletter) VALUES ('".$_POST["visitor_name"]."','".$_POST["visitor_email"]."','".$_POST["visitor_firstline"]."', '".$_POST["visitor_secondline"]."', '".$_POST["visitor_town"]."','".$_POST["visitor_county"]."','".$_POST["visitor_postcode"]."','".$_POST["visitor_tel"]."','".$_POST["visitor_mobile"]."','".$_POST["visitor_newsletter"]."'')"; if ($conn->query($sql) === TRUE) { echo "<script type= 'text/javascript'>alert('Your Information has been added successfully to our database');</script>"; } else { echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>"; } $conn->close(); } ?> <?php include( 'includes/footer.php' ); ?> Just can't see what or where I am going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/296891-php-store-data-form-issue/ Share on other sites More sharing options...
Solution ianhaney50 Posted June 18, 2015 Author Solution Share Posted June 18, 2015 Sorry sussed it again, I had a extra ' at the end of the VALUES line Quote Link to comment https://forums.phpfreaks.com/topic/296891-php-store-data-form-issue/#findComment-1514225 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.