Avenging_Flame Posted April 15, 2013 Share Posted April 15, 2013 (edited) For the life of me I cannot figure out what I am doing wrong here. <?php //data.php $con = mysql_connect("localhost","avenging_record","passwordwithheld","avenging_records"); if (!$con) { die('Could not connect: '. mysql_error()); } mysql_select_db("avenging_records"); // Get values from form $Fname = $_POST['first_name']; $Lname = $_POST['last_name']; $street1 = $_POST['street_address1']; $street2 = $_POST['street_address2']; $city = $_POST['city']; $state = $_POST['state_province']; $zip = $_POST['zip_postal']; $gender = $_POST['gender']; $email = $_POST['email']; // Insert data into mysql $order="INSERT INTO customer (first_name, last_name, street_address1, street_address2, city, state_province, zip_postal, gender, email) VALUES ('$Fname','$Lname','$street1','$street2','$city','$state','$zip','$gender','$email')"; $result = mysql_query($order); //if successfully insert data into database, displays message "Successful". if($result){ echo "Thank you, your customer information has been entered"; } else { echo "ERROR"; } //close mysql mysql_close(); ?> This program will not work no matter what. I have tried changing many things about it but I just can't seem to get it to work.It says error no matter what. Any help would be much appreciated. For reference below is the form that it is getting data from <section id="top area"> <article class="box-right"> <form action="data.php" method="post"> <p> <label>First Name:</label> <input name="first_name" required="required" placeholder="Jane" type="text"> </p> <p> <label>Last Name:</label> <input name="last_name" required="required" placeholder="Doe" type="text"> </p> <p> <label>Street Address 1:</label> <input name="street_address1" required="required" placeholder="street address" type="text"> </p> <p> <label>Street Address 2:</label> <input name="street_address2" type="text"> </p> <p> <label>City:</label> <input name="city" required="required" placeholder="City" type="text"> </p> <p> <label>State/Province:</label> <input name="state_province" required="required" placeholder="State/Province" type="text"> </p> <p> <label>Zip/Postal Code:</label> <input name="zip_postal" required="required" placeholder="Zip/Postal Code" type="text"> </p> <p> <label>Gender:</label> <input type="radio" name="gender" value="male" checked="checked" /><label>male</label> <input type="radio" name="gender" value="female" /><label>female</label> </p> <p> <label>Email Address:</label> <input name="email" required="required" placeholder="name@email.com" type="email"> </p> <p> <input value="Submit" type="submit"> </p> </form> </article> </section> Edited April 15, 2013 by Avenging_Flame Quote Link to comment Share on other sites More sharing options...
Solution DavidAM Posted April 15, 2013 Solution Share Posted April 15, 2013 Echo mysql_error when $result is FALSE. It will print the error from the database server. BTW: You need to sanitize ALL user input. See mysql_real_escape_string You never checked to see if the form was actually posted. If someone goes to data.php in the browser, it will (attempt to) insert a row of empty values into the database. Turn on error reporting, so you can see any PHP errors (warnings, etc) The mysql extension has been deprecated. You should switch to mysqli (or PDO) for any new development. Quote Link to comment Share on other sites More sharing options...
Avenging_Flame Posted April 15, 2013 Author Share Posted April 15, 2013 Thanks, that helped me find the problem. Im new to SQL and PHP so I am just kind of making due with what little I know. 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.