Page 1 of 1
INSERT INTO not working
Posted: Mon Aug 27, 2012 3:16 pm
by robertb13
The connection shows "Heck Yes"
The INSERT INTO isn't working
Not sure what I'm missing...
Code: Select all
<?php
include ('config/connection.php'); //Add configuration file
if (!$dbc)
{
die('Could not connect: ' . mysql_error());
}
else {
echo "Heck Yes";
}
mysql_select_db("survey_answers", $dbc);
$sql="INSERT INTO survey_answers (survey_id,user_id,answer_body) VALUES (3,1,'ID03 ANS01')";
if (!mysql_query($sql,$dbc))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($dbc);
?>
Re: INSERT INTO not working
Posted: Mon Aug 27, 2012 3:38 pm
by requinix
I don't know either, but I bet I'd have a good idea if you showed us the error message you're getting.
Re: INSERT INTO not working
Posted: Mon Aug 27, 2012 3:47 pm
by robertb13
All it says is...
Heck Yes Error
Re: INSERT INTO not working
Posted: Mon Aug 27, 2012 5:47 pm
by mixa2000
There could be the problem with the variables or with something else in the connection.php ; "include ('config/connection.php'); //Add configuration file."
Re: INSERT INTO not working
Posted: Mon Aug 27, 2012 5:55 pm
by robertb13
The variable for $dbc is
Code: Select all
<?php
/* ################################ */
/* ##### Connection Document ###### */
/* ################################ */
DEFINE ('DB_USER'
DEFINE ('DB_PASSWORD
DEFINE ('DB_HOST'
DEFINE ('DB_NAME'
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$dbc) {
die ('Could not connect to the database');
}
echo 'Alright!';
?>
This returns Alright! so it is connecting.
It also returns Heck Yes 03 in this code
Code: Select all
<?php
include ('config/config.php'); //Add configuration file
if (!$dbc)
{
die('Could not connect: ' . mysqli_error($dbc));
}
else {
echo "Heck Yes 03";
}
mysqli_select_db("survey_answers", $dbc);
$sql="INSERT INTO survey_answers (survey_id,user_id,answer_body) VALUES (3,1,'ID03 ANS01')";
if (!mysqli_query($sql,$dbc))
{
die('Error: ' . mysqli_error());
}
echo "1 record added";
mysqli_close($dbc);
?>
I ran -- INSERT INTO survey_answers (survey_id,user_id,answer_body) VALUES (3,1,'ID03 ANS01')
in myphpadmin and it added the row correctly
I am not sure what's happening

Re: INSERT INTO not working
Posted: Mon Aug 27, 2012 11:18 pm
by requinix
Duuude, don't post your database information on a public forum! Edit it out of your post!
Re: INSERT INTO not working
Posted: Mon Aug 27, 2012 11:31 pm
by robertb13
Thanks. Didn't even think of that. I'm a newby for real

Re: INSERT INTO not working
Posted: Tue Aug 28, 2012 1:13 am
by robertb13
I'm pulling my hair out over here.
If I put ...
INSERT INTO survey_answers (survey_id,user_id,answer_body) VALUES (3,1,567);
...into SQL of myPHPadmin, the database entry is created.
When I run this page...
Code: Select all
<?php
include ('config/config.php'); //Add configuration file
if (!$dbc) {
die ('Could not connect to the database');
}
echo '....Yes it is!';
!mysql_query("INSERT INTO survey_answers (survey_id,user_id,answer_body) VALUES (3,1,567)");
echo "....1 record add";
mysql_close ($dbc);
?>
It echos
....Yes it is....1 record add
But the data is NOT in the database. WTF?
Re: INSERT INTO not working
Posted: Tue Aug 28, 2012 1:53 pm
by robertb13
I gave up on this one.
Did it a different way.