Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with php
#1
Hello there...

I had this php script built for me a while back, but I recently deleted a file that was needed so I had to work to rebuild it. I keep getting this annoying error when I try to insert data into the database so maybe someone here will know what the problem is.....

when I try to insert data into the database, I get the follow error:
Unknown column 'Data_Distance' in 'field list'

here's my insert.php file:
Code:
<?PHP

foreach ($_POST as $key => $value){
    $$key = $value;
}

if (!$submit) {

?>

<HTML>
<HEAD>
<TITLE>Insert stuff</TITLE>
<style type="text/css">
ul, li
{
list-style: none;
text-align: left;
}
</style>
</HEAD>
<BODY>
<H1>Insert stuff...</H1>
<FORM ACTION="insert.php" METHOD=POST>
<ul>
<li>Caliber: <INPUT TYPE=TEXT NAME=Caliber></li><BR>
<li>Bullet: <INPUT TYPE=TEXT NAME=Bullet></li><BR>
<li>Powder: <INPUT TYPE=TEXT NAME=Powder></li><BR>
<li>Primer: <INPUT TYPE=TEXT NAME=Primer></li><BR>
<li>OAL: <INPUT TYPE=TEXT NAME=OAL></li><BR>
<li>Distance: <INPUT TYPE=TEXT NAME=Data_Distance></li><BR>
<li>Grouping: <INPUT TYPE=TEXT NAME=Grouping></li><BR>
<li>Bench: <INPUT TYPE=TEXT NAME=Bench></li><BR>
<BR>
<li><INPUT TYPE=HIDDEN NAME=submit VALUE="yes">
<INPUT TYPE=SUBMIT VALUE="Submit your stuff..."></li>
</ul>
</FORM>
</BODY>
</HTML>

<?PHP
exit;
}

$username = removed
$password = removed
$database = removed
$hostname = removed

mysql_connect("$hostname", "$username", "$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());

# this stuff is just for reference (copied from your post) so you know what the database limits are when doing the insert...
# for example, varchar(10) tells us that Ammo_Caliber can be pretty much any character, but not more than 10 characters long...
# and NOT NULL means exactly that... the database won't let you leave it blank (null)

#`Ammo_Caliber` varchar(10) collate latin1_german2_ci NOT NULL,
#`Bullet` varchar(20) collate latin1_german2_ci NOT NULL,
#`Powder` varchar(20) collate latin1_german2_ci NOT NULL,
#`Primer` varchar(20) collate latin1_german2_ci NOT NULL,
#`OAL` varchar(20) collate latin1_german2_ci NOT NULL,
#`Data_Distance` varchar(20) collate latin1_german2_ci NOT NULL,
#`Grouping` varchar(20) collate latin1_german2_ci NOT NULL,
#`Bench` varchar(20) collate latin1_german2_ci NOT NULL,

// Get all the data from the "example" table
$result = mysql_query("INSERT into NewGuns (Caliber,Bullet,Powder,Primer,OAL,Data_Distance,Grouping,Bench) VALUES ('$Caliber','$Bullet','$Powder','$Primer','$OAL','$Data_Distance','$Grouping','$Bench')") or die(mysql_error());  

print "Stuff was inserted.  Click <A HREF=\"select.php\">here</A> to see if it worked...\n";

?>

here's a link to form where the data is inserted:
http://www.andrewshemo.com/reloading/insert.php
Reply
#2
Check your table. I'm guessing that the column 'Data_Distance' does not exist or the column it is referring to is having a different name.
Reply
#3
(03-19-2010, 08:12 AM)blackstrider Wrote: Check your table. I'm guessing that the column 'Data_Distance' does not exist or the column it is referring to is having a different name.

I'm not sure.....but here's a screenshot for you to check out.
[Image: 01Mar19.jpg]


here's the mysql structure I suppose you'd call it:
Code:
CREATE TABLE IF NOT EXISTS `Guns` (
  `ID` int(5) NOT NULL AUTO_INCREMENT,
  `Ammo_Caliber` varchar(10) COLLATE latin1_german2_ci NOT NULL,
  `Bullet` varchar(20) COLLATE latin1_german2_ci NOT NULL,
  `Powder` varchar(20) COLLATE latin1_german2_ci NOT NULL,
  `Primer` varchar(20) COLLATE latin1_german2_ci NOT NULL,
  `OAL` varchar(20) COLLATE latin1_german2_ci NOT NULL,
  `Data_Distance` varchar(20) COLLATE latin1_german2_ci NOT NULL,
  `Grouping` varchar(20) COLLATE latin1_german2_ci NOT NULL,
  `Bench` varchar(20) COLLATE latin1_german2_ci NOT NULL,
  PRIMARY KEY (`ID`)
Reply
#4
(03-16-2010, 10:53 PM)andrewjs18 Wrote: http://www.andrewshemo.com/reloading/insert.php

Post a link to it is quite risky.
Reply
#5
The table structure you sent was for a table called "Guns". The table you are inserting into is called "NewGuns". Could you please send us the table structure for a table called "NewGuns" or alternative change your insert query to "Guns" : $result = mysql_query("INSERT into Guns(Caliber,Bullet,Powder,Primer,OAL,Data_Distance,Grouping,Bench) VALUES ('$Caliber','$Bullet','$Powder','$Primer','$OAL','$Data_Distance','$Grouping','$Bench')") or die(mysql_error());
Reply
#6
(06-13-2010, 04:30 AM)Lord-Nikon Wrote: The table structure you sent was for a table called "Guns". The table you are inserting into is called "NewGuns". Could you please send us the table structure for a table called "NewGuns" or alternative change your insert query to "Guns" : $result = mysql_query("INSERT into Guns(Caliber,Bullet,Powder,Primer,OAL,Data_Distance,Grouping,Bench) VALUES ('$Caliber','$Bullet','$Powder','$Primer','$OAL','$Data_Distance','$Grouping','$Bench')") or die(mysql_error());

this issue has been resolved.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 943 07-27-2020, 11:26 PM
Last Post: tk-hassan
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,674 10-10-2011, 01:00 PM
Last Post: Greyersting

Forum Jump:


Users browsing this thread: 8 Guest(s)