Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006

    Unanswered: can't insert data to MySQL with .php (form won't work)

    I am a PHP and MySQL newbie, so please be gentle with me.

    I have made a database and a .php page which reads it and displays the data, however, I am having difficulty getting my page which inserts data to the database, to work.

    This is the code for the form which accepts the data:

    HTML Code:
    <form action="insert.php" method="get">
    <input type="Submit" name="submit" /> <br />
    Name/Model: <input type="text" name="namemodel" /><br />
    Manufacturer: <input type="text" name="manufacturer" /><br />
    Tagline: <input type="text" name="tagline" /><br />
    Ed Summary: <textarea cols="20" rows="10" name="ed_summary"></textarea><br />
    Main Editorial: <textarea cols="20" rows="20" name="ed_main"></textarea><br />
    Features: <textarea cols="20" rows="20" name="features"></textarea><br />
    Specs: <textarea cols="20" rows="10" name="specs"></textarea><br />
    Options: <textarea cols="20" rows="10" name="options"></textarea><br />
    Thumbnail Picture: <input type="text" name="pic_thumb_100x100" /><br />
    Picture 1: <input type="text" name="pic_1" /><br />
    Picture 2: <input type="text" name="pic_2" /><br />
    Cost Price: <input type="text" name="costprice" /><br />
    Retail Price: <input type="text" name="retailprice" /><br />
    Supplier ID: <input type="text" name="supplierid" /><br />
    Current Stock: <input type="text" name="curr_stock" /><br />
    Minimum Stock: <input type="text" name="minstock" /><br />
    Maximum Stock: <input type="text" name="maxstock" /><br />
    <input type="Submit" name="submit" />

    and this is the page called ‘insert.php’ which should insert the data to the database:

    PHP Code:

    ="removed for forum";
    $password="removed for forum";

    $query = ("INSERT INTO products VALUES ('', '$NameModel', '$Manufacturer', '$Tagline', '$Ed_Summary', '$Ed_Main', '$Specs', '$Features', '$Options', '$Pic_Thumb_100x100', '$Pic_1', '$Pic_2', '$CostPrice', '$RetailPrice', '$SupplierID', '$Curr_Stock', '$MinStock', '$MaxStock')");

    My testing has led me to believe that the data is being received by insert.php but is for some reason, not being stored in the database.

    There is no error message.

    Thanks for your time


  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    hi snowman

    You are not doing anything with your SQL statement, its one thing to build it its another to inform PHP to do something with it. You need to use the @mysql_query function to do something.

    $resultset=@mysql_query($sql,$cnn) or die ("<insert error message here><BR>$sql";
    $sql is the variable containing the SQL to be applied
    $cnn is the variable containing a valid MySQL resource
    $resultset is the return from the function


  3. #3
    Join Date
    Jan 2006


    Thanks for that... all good now with the form :-)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts