•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 397,866 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,582 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1841 | Replies: 1
![]() |
•
•
Join Date: Jan 2006
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
I'm creating my first web application in PHP/MySQL, however, when I go to view the database contents, the data has been stored in the wrong columns. I've gone through my insertion code with a fine toothcomb and can see no errors which might cause this. I will post the code below, and you will see that I have some diagnostics built in, which show that the information (at least at that point) appears to be about to be stored in the correct columns.
I have 'checked', 'repaired' and 'flushed' the database using PHPMyAdmin and tried again. I have also restarted my PC several times too (although so far, it has always been very stable).
These are a list of some of the columns in my table called 'products' and along side them is the name of the columns data that is wrongly stored there:
The text to the left of the '=' sign is the Post HTTP header field name and to the right of the '=' is the contents of the form.
Looking at that, it is all good so far, as I typed in each text field some text to identify which field it should be in. EG. I typed 'Main Editorial' in the field called 'Ed_main' in the form that collects the data to insert.
However, when I check the actual contents of the database the data is stored in the wrong columns still.
Here is the full code of the page holding the form:
[HTML]
<html>
<head>
<title>Admin</title>
</head>
<body>
<form action="insert.php" method="post">
<input type="Submit" name="submit" />
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="60" 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>
</body>
</html>
[/HTML]
Here is the code for insert.php
[PHP]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
$username="removed for forum";
$password="removed for forum";
$database="myodbc_store";
if ($username="removed for forum") {
// process form
echo "Values <br>";
while (list($name, $value) = each($HTTP_POST_VARS)) {
echo "$name = $value<br>\n";
}}
$ProdID='';
$NameModel=$_POST['namemodel'];
$Manufacturer=$_POST['manufacturer'];
$Tagline=$_POST['tagline'];
$Ed_Summary=$_POST['ed_summary'];
$Ed_Main=$_POST['ed_main'];
$Features=$_POST['features'];
$Specs=$_POST['specs'];
$Options=$_POST['options'];
$Pic_Thumb_100x100=$_POST['pic_thumb_100x100'];
$Pic_1=$_POST['pic_1'];
$Pic_2=$_POST['pic_2'];
$CostPrice=$_POST['costprice'];
$RetailPrice=$_POST['retailprice'];
$SupplierID=$_POST['supplierid'];
$Curr_Stock=$_POST['curr_stock'];
$MinStock=$_POST['minstock'];
$MaxStock=$_POST['maxstock'];
$conn=odbc_connect($database,$username,$password);
$query = "INSERT INTO products VALUES ('$ProdID', '$NameModel', '$Manufacturer', '$Tagline', '$Ed_Summary', '$Ed_Main', '$Features', '$Specs', '$Options', '$Pic_Thumb_100x100', '$Pic_1', '$Pic_2', '$CostPrice', '$RetailPrice', '$SupplierID', '$Curr_Stock', '$MinStock', '$MaxStock')";
$resultset=odbc_exec($conn,$query) or die ("Error inserting data<BR>$query");
/* <!-- 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
--> */
odbc_close($conn);
?>
</body>
</html>
[/PHP]
I would really appreciate your help!
Thanks, pete
I have 'checked', 'repaired' and 'flushed' the database using PHPMyAdmin and tried again. I have also restarted my PC several times too (although so far, it has always been very stable).
These are a list of some of the columns in my table called 'products' and along side them is the name of the columns data that is wrongly stored there:
This is the diagnostic text that was output on the screen because of the diagnostic code in insert.php
NameModel - correct
Manufacturer - correct
Tagline - CONTAINS Ed_Main
Ed_Summary - CONTAINS Tagline
Ed_main - CONTAINS Ed_Summary
The rest of the columns are store correctly.
•
•
•
•
Values
submit = Submit Query
namemodel = 1Name/Model
manufacturer = Manufacturer
tagline = Tagline
ed_summary = Ed Summary
ed_main = Main Editorial
features = Features
specs = Specs
options = Options
pic_thumb_100x100 = Thumbnail Picture
pic_1 = Picture 1
pic_2 = Picture 2
costprice = 1
retailprice = 2
supplierid = 3
curr_stock = 4
minstock = 5
maxstock = 6
The text to the left of the '=' sign is the Post HTTP header field name and to the right of the '=' is the contents of the form.
Looking at that, it is all good so far, as I typed in each text field some text to identify which field it should be in. EG. I typed 'Main Editorial' in the field called 'Ed_main' in the form that collects the data to insert.
However, when I check the actual contents of the database the data is stored in the wrong columns still.
Here is the full code of the page holding the form:
[HTML]
<html>
<head>
<title>Admin</title>
</head>
<body>
<form action="insert.php" method="post">
<input type="Submit" name="submit" />
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="60" 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>
</body>
</html>
[/HTML]
Here is the code for insert.php
[PHP]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
$username="removed for forum";
$password="removed for forum";
$database="myodbc_store";
if ($username="removed for forum") {
// process form
echo "Values <br>";
while (list($name, $value) = each($HTTP_POST_VARS)) {
echo "$name = $value<br>\n";
}}
$ProdID='';
$NameModel=$_POST['namemodel'];
$Manufacturer=$_POST['manufacturer'];
$Tagline=$_POST['tagline'];
$Ed_Summary=$_POST['ed_summary'];
$Ed_Main=$_POST['ed_main'];
$Features=$_POST['features'];
$Specs=$_POST['specs'];
$Options=$_POST['options'];
$Pic_Thumb_100x100=$_POST['pic_thumb_100x100'];
$Pic_1=$_POST['pic_1'];
$Pic_2=$_POST['pic_2'];
$CostPrice=$_POST['costprice'];
$RetailPrice=$_POST['retailprice'];
$SupplierID=$_POST['supplierid'];
$Curr_Stock=$_POST['curr_stock'];
$MinStock=$_POST['minstock'];
$MaxStock=$_POST['maxstock'];
$conn=odbc_connect($database,$username,$password);
$query = "INSERT INTO products VALUES ('$ProdID', '$NameModel', '$Manufacturer', '$Tagline', '$Ed_Summary', '$Ed_Main', '$Features', '$Specs', '$Options', '$Pic_Thumb_100x100', '$Pic_1', '$Pic_2', '$CostPrice', '$RetailPrice', '$SupplierID', '$Curr_Stock', '$MinStock', '$MaxStock')";
$resultset=odbc_exec($conn,$query) or die ("Error inserting data<BR>$query");
/* <!-- 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
--> */
odbc_close($conn);
?>
</body>
</html>
[/PHP]
I would really appreciate your help!
Thanks, pete
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
- Data from mysql in a 3 columns table (PHP)
- The Definitive Guide to which Forum Software Information (Growing an Online Community)
- MySQL Checkbox Multiple data Delete? (PHP)
- writitng data from php to mysql (PHP)
- transfer data from an asp .net page into a javasscript script (ASP.NET)
- Error message while importing data to Excel from the MySQL db (MySQL)
Other Threads in the MySQL Forum
- Previous Thread: Using MySQL with PHP - Tutorial by Herong
- Next Thread: Java Connection


Linear Mode