2
     <html>
        <head>
    <title>Updated</title>
    </head>
    <body>
    <?php
$link = mysql_connect('localhost', 'josephha_salesm', 'lamepassword1');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db('josephha_carsales', $link);
if (!$db_selected) {
die ('Can\'t use carsales : ' . mysql_error());
}

        $strSQL = "INSERT INTO salesreport(Neworused) values('" . $_POST["Neworused"] .                                 "')";
        $strSQL = "INSERT INTO salesreport(Make) values('" . $_POST["Make"] . "')";
    $strSQL = "INSERT INTO salesreport(Model) values('" . $_POST["Model"] . "')";
    $strSQL = "INSERT INTO salesreport(Price) values('" . $_POST["Price"] . "')";
    $strSQL = "INSERT INTO salesreport(Salesid) values('" . $_POST["Salesid"] . "')";
// Close the database connection
    mysql_query($strSQL) or die (mysql_error());

    mysql_close();
    ?>

    <h1>The database is updated!</h1>
    </body>
    </html>

The code runs and updates that database when I only have Salesid, when I add the other char fields they all return an empty field. When I add the price field only the price shows up, the rest return empty values.

Prix
  • 19,417
  • 15
  • 73
  • 132
liquidacid
  • 108
  • 1
  • 9
  • 2
    Three words: `Little`, `Bobby` and `Tables` - https://xkcd.com/327/ – Mark Baker Feb 28 '14 at 17:47
  • You have 5 variables with a SQL query which are overwritten by the below variable hence why only the salesid execute, you should 1) sanitize the `$_POST` data before directly using it so you avoid SQL Injection and 2) make a single SQL query with all your fields and data for the insert. – Prix Feb 28 '14 at 18:36

1 Answers1

0

you have to put it in the same insert.

This is one insert. $strSQL = "INSERT INTO salesreport(Make) values('" . $_POST["Make"] . "')";

This is other insert. $strSQL = "INSERT INTO salesreport(Model) values('" . $_POST["Model"] . "')";

So you have one register with the value of Make and other register with the value of Model...

You should do somthing like that:

   //Not exactly like that... Something like that
    $strSQL = " INSERT INTO salesreport (Make, Model, Price, Salesid) values ($_POST['Make'], $_POST['Model'], $_POST['Price'], $_POST['Salesid'])"; 

This is one insert with all these informations.

Hope it was right. lol.

Alan D.
  • 89
  • 4