If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > can't insert data to MySQL with .php (form won't work)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-06, 02:19
snowweb snowweb is offline
Registered User
 
Join Date: Jan 2006
Posts: 13
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" />

</form>

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

PHP Code:

<?php
$username
="removed for forum";
$password="removed for forum";
$database="myodbc_store";


$NameModel=$_GET['namemodel'];
$Manufacturer=$_GET['manufacturer'];
$Tagline=$_GET['tagline'];
$Ed_Summary=$_GET['ed_summary'];
$Ed_Main=$_GET['ed_main'];
$Features=$_GET['features'];
$Specs=$_GET['specs'];
$Options=$_GET['options'];
$Pic_Thumb_100x100=$_GET['pic_thumb_100x100'];
$Pic_1=$_GET['pic_1'];
$Pic_2=$_GET['pic_2'];
$CostPrice=$_GET['costprice'];
$RetailPrice=$_GET['retailprice'];
$SupplierID=$_GET['supplierid'];
$Curr_Stock=$_GET['curr_stock'];
$MinStock=$_GET['minstock'];
$MaxStock=$_GET['maxstock'];
 
$conn1=odbc_connect($database,$username,$password);
$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

pete
Reply With Quote
  #2 (permalink)  
Old 01-18-06, 02:34
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,258
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";
where:-
$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

HTH
Reply With Quote
  #3 (permalink)  
Old 01-18-06, 02:52
snowweb snowweb is offline
Registered User
 
Join Date: Jan 2006
Posts: 13
Excellant!!!

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

pete
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On