0

I have the following form asking for simple information, yet the data will not parse to my database. I have similar forms on other parts of my site, and they are connected to the database and retrieving data perfectly. Have pasted the code below and believe that MYSQL script is written as it is supposed to be. Why is the data not being retrieved once a use presses the submit button?

<?php 
// Written by KV Ghumaan
session_start(); // Start session first thing in script
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Connect to the MySQL database  
include "storescripts/connect_to_mysql.php"; 
?>
<?php
// Parse the form data and add inventory item to the system
if(isset($_POST['fName'])){

    $id = mysql_real_escape_string($_POST['id']);
    $fName = mysql_real_escape_string($_POST['fName']);
    $lName = mysql_real_escape_string($_POST['lName']);
    $address = mysql_real_escape_string($_POST['address']);
    $city = mysql_real_escape_string($_POST['city']);
    $state = mysql_real_escape_string($_POST['state']);
    $zipCode = mysql_real_escape_string($_POST['zipCode']);

    //Add this product into the database now

    $sql = mysql_query("INSERT INTO checkoutInfo (id, fName, lName, address, city, state, zipCode)
        VALUES('$id','$fName','$lName','$address','$city','$state','$zipCode')") or die (mysql_error());
    $pid = mysql_insert_id();
}
?>
<html>
    <head>
        <!--JQUERY-->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="jqueryui/jquery-ui.js"></script>
        <link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.css"/>
        <link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.structure.css"/>
        <link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.theme.css"/>
  <!--GOOGLE FONT & EXTERNAL LIBS-->
        <link href="https://fonts.googleapis.com/css?family=Raleway:100" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" type="text/css" href="style/style.css"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>CHECKOUT</title>
    </head>
    <body>
        <?php include_once("template_header.php");?>
        <table width="100%" height="76vh" border="10%" cellspacing="10" style="padding: 2vh 10vw 0vh 10vw; border-style:none;">
            
            <tr height="75%" cellspacing="0" style="border-style:none;">
                <td width="30%" style="border-style:none; padding-top: 10vh;">
                  <form class="form" action="confirmation.php" enctype="multipart/form-data" name="checkoutForm" id="checkoutForm" method="POST">
                      <div id="billingQuestions">
                            <h3><strong>BILLING ADDRESS:</strong></h3>
                            <div id="formQuestions">
                                <label>First Name:*</label><br />
                                <input type="text" name="fName" size="40vw" required>
                            </div>
                            <div id="formQuestions">
                                <label>Last Name:*</label><br />
                                <input type="text" name="lName" size="40vw" required>
                            </div>
                            <div id="formQuestions">
                                <label>Address 1:*</label><br />
                                <input type="text" name="address" size="40vw" required>
                            </div>
                            <div id="formQuestions">
                                <label>Address 2:*</label><br />
                                <input type="text" size="40vw">
                            </div>
<div id="formQuestions">
                                                                    <label>City: *</label><br />
                                                                    <input name="city" type="text" size="40vw" required>
                                                                </div>
                                                                <div id="formQuestions">
                                                                    <label>State: *</label><br />
                                                                    <input name="state" type="text" size="40vw" required>
                                                                </div>
                                                                <div id="formQuestions">
                                                                    <label>Zip Code: *</label><br />
                                                                    <input name="zipCode" type="text" size="40vw" required>
                                                                </div>
                        <input type="submit" value="Submit"/>
</div>
</form>
         </td>
         </tr>
            
        </table>
        <?php include_once("template_footer.php");?>
    </body>
</html>
chris85
  • 23,846
  • 7
  • 34
  • 51
user7366442
  • 731
  • 2
  • 9
  • 16
  • 1
    No errors are thrown? You are using `mysql_*` elsewhere? I don't see a `name="id"` so `$_POST['id']` should be throwing an undefined index notice. Also is the DB `id` auto-incrementing? – chris85 Feb 13 '17 at 16:45
  • I suspect chris85 is onto something. If the `id` column is auto increment, then don't supply a value for it, it will automatically populate with the next digit. so remove `id,` and `'$id',` from your query – Duane Lortie Feb 13 '17 at 17:53
  • 1
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Feb 13 '17 at 17:57
  • Add error reporting to the top of your file(s) right after your opening ` – Jay Blanchard Feb 13 '17 at 17:58
  • The DB 'id' is auto-incremented. Great note and I have removed that from my query, yet the form data is not parsing. Could using depreciated mysql_* functions be the main cause? I am using similar scripts on other forms and they are working just fine. Thanks for all the help everyone. @DuaneLortie – user7366442 Feb 15 '17 at 00:01
  • mysql method should work, but it will be removed from upcoming versions of PHP so switching to a different method is highly encouraged. For me, it was easiest to convert to mysqli – Duane Lortie Feb 15 '17 at 01:11

0 Answers0