Jump to content

[SOLVED] problems inserting data into database


joshgarrod

Recommended Posts

Hi guys, noob here as you will guess, I am having trouble with this script, it merely refreshes the page when you click the submit button, what am I doing wrong?

 

<?php

    (POST METHOD)
    if ($REQUEST_METHOD=="POST") {

        $SQL = " INSERT INTO awnings ";
        $SQL = $SQL . " (Make, Model, Size, Year, Price, Description) VALUES ";
        $SQL = $SQL . " ('$Make','$Model','$Size','$Year, $Price, $Description') ";


        
        $result = mysql_db_query($db,"$SQL",$cid);
	$ID=mysql_insert_id();


        
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

        echo ("<P><B>New awning has been added, thank you</B></P>\n");

    }

?>
<FORM NAME="fa" ACTION="add_used_awnings.php" METHOD="POST">
Make: <INPUT NAME="Make" TYPE="text" id="Make" SIZE=40><br /><br />
Model: <INPUT TYPE="Model" NAME="Model" VALUE="" SIZE=15><br /><br />
Size: <input name="Size" type="text" id="Size" value="" size="15" /><br /><br />
Year: <input name="Year" type="text" id="Year" value="" size="15" /><br /><br />
Price: <input name="Price" type="text" id="Price" value="£" size="15" /><br /><br />
Description: <textarea name="Description" cols="50" rows="10" id="Description" type="text" value="" /></textarea><br /><br />
<input name="submit" type="submit" value="Add stock" />
</FORM>

<?php

    if ($_POST['submit']) {

        $SQL = " INSERT INTO awnings ";
        $SQL .= " (Make, Model, Size, Year, Price, Description) VALUES ";
        $SQL .= " ('$Make','$Model','$Size','$Year, $Price, $Description') ";


        
        $result = mysql_db_query($db,$SQL,$cid);
      $ID=mysql_insert_id();


        
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

        echo ("<P><B>New awning has been added, thank you</B></P>\n");

    }

?>
   <FORM NAME="fa" ACTION="add_used_awnings.php" METHOD="POST">
   Make: <INPUT NAME="Make" TYPE="text" id="Make" SIZE=40><br /><br />
   Model: <INPUT TYPE="Model" NAME="Model" VALUE="" SIZE=15><br /><br />
   Size: <input name="Size" type="text" id="Size" value="" size="15" /><br /><br />
   Year: <input name="Year" type="text" id="Year" value="" size="15" /><br /><br />
   Price: <input name="Price" type="text" id="Price" value="£" size="15" /><br /><br />
   Description: <textarea name="Description" cols="50" rows="10" id="Description" type="text" value="" /></textarea><br /><br />
   <input name="submit" type="submit" value="Add stock" />
   </FORM>

<?php
    $usr = "user";
    $pwd = "pword";
    $db = "database";
    $host = "host";

    # connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

    if ($_POST['submit']) {

        $SQL = " INSERT INTO awnings ";
        $SQL .= " (Make, Model, Size, Year, Price, Description) VALUES ";
        $SQL .= " ('$Make','$Model','$Size','$Year, $Price, $Description') ";


        
        $result = mysql_db_query($db,$SQL,$cid);
      $ID=mysql_insert_id();


        
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

        echo ("<P><B>New awning has been added, thank you</B></P>\n");

    }

?>
   <FORM NAME="fa" ACTION="add_used_awnings.php" METHOD="POST">
   Make: <INPUT NAME="Make" TYPE="text" id="Make" SIZE=40><br /><br />
   Model: <INPUT TYPE="Model" NAME="Model" VALUE="" SIZE=15><br /><br />
   Size: <input name="Size" type="text" id="Size" value="" size="15" /><br /><br />
   Year: <input name="Year" type="text" id="Year" value="" size="15" /><br /><br />
   Price: <input name="Price" type="text" id="Price" value="£" size="15" /><br /><br />
   Description: <textarea name="Description" cols="50" rows="10" id="Description" type="text" value="" /></textarea><br /><br />
   <input name="submit" type="submit" value="Add stock" />
   </FORM>

   <?php    mysql_close($cid); ?>

Firstly;

 

$SQL .= " ('$Make','$Model','$Size','$Year, $Price, $Description') ";

 

change that line to;

 

$SQL .= " ('$Make','$Model','$Size','$Year', '$Price', '$Description') ";

 

Secondly, you haven't assigned your variables;

 

$Make = mysql_real_escape_string($_POST['Make']);
$Model = mysql_real_escape_string($_POST['Model');
etc....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.