Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

What Am I doing wrong with my INSERT statement?

$
0
0

Hey all this is my first time posting and was wondering if I could get some help and see what I am doing wrong.

 

// I've tried my best to find my answer through google searches and after days of working on this I finally decided to ask for some guidence.  //

 

Project: I am trying to make a web based form that will take information about my comic books and input them into a mysql database.

 

Info: I have got the code for the html input page all done and have it sending the $_POST[''] variables to another script that will actually input the data into the database.  / In addition this app is only available to me and won't be facing the public world so I have left out the checks on the data since most of it is controled variables from the form.

 

Problem: After I input the 7 values into the html form and submit them the script never inputs the data. I have echoed out the $_POST[''] variables to make sure they were being passed correctly and well they are.

 

Question: It's a multi part question / a.) Can anyone see what I am doing wrong in my INSERT statement and mysqli_query  b.) Is there a better way? I saw PDO but couldn't really wrap my head around it. c.) what could or should I be using to see what mysql is telling me when the INSERT statement runs to see if Its a problem on the other side.

 

What I've done/tried:  Seems like too much too say... lol but I've verified the user permissions for the DB and the user I'm connecting with and it has full rights on DB / Multiple INSERT statements but none of em work. / I've tried moving the table into a separate database scheme (still no go) / I've tried different ways of selecting the DB outside of the connection params as well as in the connection params with no favorable result. / I tried using the string that mysql workbench creates to input values the same as the php code to input values and that didn't work.

 

Code: [comic_form.php]

$comic_db = mysqli_connect("foo", "bar", "foobar", "comic_info_db");

if(!$comic_db){
	echo "Connection to DB Failed";
	}
else {
	echo "Connect to DB Established";
	}

// Variables From Web Form

$idcomic_db = $_POST['idcomic_db'];
$publisher = $_POST['publisher'];
$comic_name = $_POST['comic_name'];
$comic_num = $_POST['comic_num'];
$comic_cover = $_POST['comic_cover'];
$price_paid = $_POST['price_paid'];
$quantity = $_POST['quantity'];

$sql_insert = "INSERT INTO `comic_db` (idcomic_db, publisher, comic_name, comic_num, comic_cover, price_paid, quantity) VALUES ('$idcomic_db', '$publisher', '$comic_name', '$comic_num', '$comic_cover', '$price_paid', '$quantity')";
$db_con = mysqli_query($sql_insert, $comic_db);
$error = mysqli_error($db_con);

In that same script I also have echoed the variables as well as the sql_insert string and this is what I get. I did this just to see what variables were being passed as well as the string that was being created. Dunno if there is a better way to do it.

1
Marvel Comics
The Superior Spider-Man
1
original
3.99
1

INSERT INTO `comic_db`.`comic_db` (`idcomic_db`, `publisher`, `comic_name`, `comic_number`, `comic_cover`, `price_paid`, `quantity`) VALUES ('0', 'Marvel Comics', 'The Superior Spider-Man', '1', 'original', '3.99', '1')

I've also included a screen shot of the table params from mysql.

if it helps I also am using PHP Version 5.3.10-1ubuntu3.6

 

 

Sorry if this is lengthy thought more info would be better

Thanks for the help

 

 

Attached Thumbnails

  • db.PNG

Viewing all articles
Browse latest Browse all 13200

Trending Articles