Jump to content

problem adding new entry to a database


rogerse

Recommended Posts

Hi there,

 

I have written a page which is meant to allow a user to enter details of a new car for sale (via a form), and then the submission of this form should add the details to the database.

As far as I can see all the code is correct, yet I don't get a new entry.

 

The Form

------------

<form action="addCar.php" method="post">
            Category: <select name="Category">
                        <option>Classic</option>
                        <option>Modern</option>
                        <option>Range_Rover</option>
                      </select>
                      <br />
            Make:<input type="text" name="Make" value=""><br />
            Model: <input type="text" name="Model" value=""><br />
            Reg Year: <input type="text" name="Reg_Year" value=""><br />
            Reg Letter: <input type="text" name="Reg_Letter" value=""><br />
            Mileage: <input type="text" name="Mileage" value=""><br />
            Price: <input type="text" name="Price" value=""><br />
            Price Alternate: <input type="text" name="Price_Alternate" value=""><br />
            Description: <textarea cols="60" name="Description" rows="4"></textarea><br />
            Image 1: <input type="text" name="Image1" value="<? echo $Image1; ?>"><br />
            Image 2: <input type="text" name="Image2" value="<? echo $Image2; ?>"><br />
            Image 3: <input type="text" name="Image3" value="<? echo $Image3; ?>"><br />
            Image 4: <input type="text" name="Image4" value="<? echo $Image4; ?>"><br />
        <input type="Submit" value="Add" name="send">
    </form>

 

addCar.php

--------------

    <?php
     
        $Category=$_POST['Category'];
        $Make=$_POST['Make'];
        $Model=$_POST['Model'];
        $Reg_Year=$_POST['Reg_Year'];
        $Reg_Letter=$_POST['Reg_Letter'];
        $Mileage=$_POST['Mileage'];
        $Price=$_POST['Price'];
        $Price_Alternate=$_POST['Price_Alternate'];
        $Description=$_POST['Description'];
        $Image1=$_POST['Image1'];
        $Image2=$_POST['Image2'];
        $Image3=$_POST['Image3'];
        $Image4=$_POST['Image4'];
    
        $username="usrname";
        $password="pswd";
        $database="dbName";
        
        mysql_connect(localhost,$username,$password);
        @mysql_select_db($database) or die( "Unable to select database");

        $query="INSERT INTO cars (ID, Category, Make, Model, Reg_Year, Reg_Letter, Mileage, Price, Price_Alternate, Description, Image1, Image2, Image3, Image4) VALUES ('','$Category,'$Make','$Model','$Reg_Year','$Reg_Letter,'$Mileage','$Price','$Price_Alternate','$Description','$Image1','$Image2','$Image3','$Image4')";
        mysql_query($query);
        echo "Car Added";

        mysql_close();
    ?>

 

Is this a case of "can't see the wood for the tree's"? Am I missing something glaringly obvious?

 

Cheers guys,

 

Ed

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.