Jump to content


Photo

chpt 2 - "error querying database"


  • Please log in to reply
65 replies to this topic

#21 lemuel

lemuel

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 577 posts

Posted 23 February 2009 - 11:47 AM

What happens if you change each occurrence of "mysqli" to "mysql"?

#22 embtech

embtech

    Active Member

  • Members
  • PipPipPip
  • 73 posts

Posted 23 February 2009 - 03:04 PM

I have changed the mysql(i) back and forth. Rewritten the whole php file numerous times but no data is being added to the database. I have even created several different databases and tables to see if I can find the problem. I have induced errors into the code and do get some errors back, but with the code running correctly---nothing. Please help! I am about to give up.

#23 lemuel

lemuel

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 577 posts

Posted 23 February 2009 - 05:52 PM

Have you confirmed that your host company uses "localhost" as the mySQL connection host? I know of at least one that does not.

#24 embtech

embtech

    Active Member

  • Members
  • PipPipPip
  • 73 posts

Posted 23 February 2009 - 07:44 PM

Yes I have confirmed this. As I said in an earlier post, I have shown this to the person who is hosting my sites (private host), and he says that everything in the code is ok. I am not having connection problems. Just not seeing the data update.

#25 Mr_Prinny

Mr_Prinny

    New Member

  • Members
  • Pip
  • 1 posts

Posted 03 March 2009 - 06:36 PM

QUOTE (embtech @ Feb 23 2009, 07:44 PM) <{POST_SNAPBACK}>
Yes I have confirmed this. As I said in an earlier post, I have shown this to the person who is hosting my sites (private host), and he says that everything in the code is ok. I am not having connection problems. Just not seeing the data update.


I had a similar issue. What I had to do was change
CODE
$name = $_POST['firstname'] . ' ' . $_POST['lastname'];

to
CODE
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];


Everything went peachy after that.

#26 WoodChuck34

WoodChuck34

    New Member

  • Members
  • Pip
  • 6 posts

Posted 18 March 2009 - 10:26 AM

I'm having this problem too and I have no idea why. I did a test run with another, more simple, report and it did successfully query the database, but it only used mysql commands and not mysqli commands. Obviously my user name and password are working if I can connect into my test database and extract data. Anyone have any suggestions?

Chuck

mysql server 5.1.32
php 5.2.9.1
apache version 2.2.11
running on Vista Home Premium

#27 WoodChuck34

WoodChuck34

    New Member

  • Members
  • Pip
  • 6 posts

Posted 18 March 2009 - 10:48 AM

Just an update. With my particular build of PHP, I noticed that in my php.ini file the following was commented out:

;extension=php_mysql.dll

I went in and removed the semicolon, restarted my computer, and ran my personal test code again and it worked. The report used mysqli_connect, mysqli_query and mysqli_close, all of which worked. For some reason, I still can't get the report.php from chapter 2 to run.

Chuck

#28 mudcap

mudcap

    New Member

  • Members
  • Pip
  • 2 posts

Posted 20 March 2009 - 05:42 PM

yep looks like i got the same error as everyone else. looks like the authors could care less as i see nothing on here that will help. i also notice from the posts there are tons of other problems with this trash book.
since i'm going to have to read a real book to figure out all of the errors in this one i guess this one will be getting tossed in the trash since it is trash. wow i've never came across anything as crappy as this garbage book.
lol what a sick joke.

#29 eimac

eimac

    New Member

  • Members
  • Pip
  • 1 posts

Posted 27 March 2009 - 07:43 PM

My server didn't like the "i" forms of the commands used in the example and I was getting the same errors. So I used the older versions and got it all to work by replacing the mysqli_connect command with these two:

$dbc = mysql_connect('data.aliensabductedme.com', 'owen', 'aliensrool')
or die('Error connecting to MySQL server.');

mysql_select_db('aliendatabase');

Also, I used

mysql_query($query)
or die('Error querying database.');

instead of the two-argument form for mysqli_query.

I did the same thing in the Chapter 3 example and it works now also. I'm surprised that the "i" versions aren't on my provider's server as they host thousands of accounts running PHP. I'm wondering if I'm just missing an include. At least it works with these mods.


Edited by eimac, 27 March 2009 - 08:01 PM.


#30 theartofconfusion

theartofconfusion

    New Member

  • Members
  • Pip
  • 7 posts

Posted 24 May 2009 - 10:40 PM

Hello Guys,

I share your frustration. But, everything you guys said eventually pointed me in the right direction. I was actually able to send all the information to the database. I had been getting fatal errors all day. Here is the code that worked for me. Thanks guys!!!!! I hope all this helps someone else.

$dbc = mysql_connect('localhost','owen','aliensrool')
or die('Error connecting to mysql server.');

mysql_select_db('aliendatabase');

$query = "INSERT INTO aliens_abduction (first_name, last_name, " .
"when_it_happened, how_long, how_many, alien_description, " .
"what_they_did, fang_spotted, other, email)" .
"VALUES ('$first_name', '$last_name', '$when_it_happened',
'$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', " .
"'$fang_spotted', '$other', " .
"'$email')";

$result = mysql_query($query)
or die('Error querying database.');


mysql_close($dbc);


#31 Mominator

Mominator

    New Member

  • Members
  • Pip
  • 9 posts

Posted 25 May 2009 - 02:14 PM

QUOTE (theartofconfusion @ May 24 2009, 10:40 PM) <{POST_SNAPBACK}>
Hello Guys,

I share your frustration. But, everything you guys said eventually pointed me in the right direction. I was actually able to send all the information to the database. I had been getting fatal errors all day. Here is the code that worked for me. Thanks guys!!!!! I hope all this helps someone else.

$dbc = mysql_connect('localhost','owen','aliensrool')
or die('Error connecting to mysql server.');

mysql_select_db('aliendatabase');

$query = "INSERT INTO aliens_abduction (first_name, last_name, " .
"when_it_happened, how_long, how_many, alien_description, " .
"what_they_did, fang_spotted, other, email)" .
"VALUES ('$first_name', '$last_name', '$when_it_happened',
'$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', " .
"'$fang_spotted', '$other', " .
"'$email')";

$result = mysql_query($query)
or die('Error querying database.');


mysql_close($dbc);


Art - you are da bomb! THIS WORKED!!!!!!!


#32 jrawnw

jrawnw

    New Member

  • Members
  • Pip
  • 6 posts

Posted 25 May 2009 - 11:36 PM

Guys I have tried everything suggested I think. I am using godaddy Server version: 5.0.67.d7-ourdelta-log. It's late I can't keep my eyes open please help. Maybe something I'm missing?

Thank You

#33 jrawnw

jrawnw

    New Member

  • Members
  • Pip
  • 6 posts

Posted 27 May 2009 - 11:28 AM

I'm pulling my hair out. I went back to the beginning, used the localhost. Made the form.php and html they worked. Manually input the database tested the database in Mysql and it worked. redid report.php to input the info and get Error querying database. every time, changed the code to what you guys have mentioned, checked the user rights and so on. I have tried everything.
I'm using vista home
PHP Version 5.2.9
mysql 5.0

Here is the last code I used top to bottom

<?php
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$how_many = $_POST['howmany'];
$alien_description = $_POST['aliendescription'];
$what_they_did = $_POST['whattheydid'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
$other = $_POST['other'];


$dbc = mysql_connect('localhost','myuser','mypass')
or die('Error connecting to mysql server.');

mysql_select_db('aliendatabase');

$query = "INSERT INTO aliens_abduction (first_name, last_name, " .
"when_it_happened, how_long, how_many, alien_description, " .
"what_they_did, fang_spotted, other, email)" .
"VALUES ('$first_name', '$last_name', '$when_it_happened',
'$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', " .
"'$fang_spotted', '$other', " .
"'$email')";

$result = mysql_query($query)
or die('Error querying database.');


mysql_close($dbc);

echo 'Thanks for submitting the form.<br />';
echo 'You were abducted ' . $when_it_happened;
echo ' and were gone for ' . $how_long . '<br />';
echo 'Number of aliens: ' . $how_many . '<br />';
echo 'Describe them: ' . $alien_description . '<br />';
echo 'The aliens did this: ' . $what_they_did . '<br />';
echo 'Was Fang there? ' . $fang_spotted . '<br />';
echo 'Other comments: ' . $other . '<br />';
echo 'Your email address is ' . $email;




?>

Please for the love of GOD help me find something

#34 Mominator

Mominator

    New Member

  • Members
  • Pip
  • 9 posts

Posted 27 May 2009 - 11:58 AM

QUOTE (jrawnw @ May 27 2009, 11:28 AM) <{POST_SNAPBACK}>
I'm pulling my hair out. I went back to the beginning, used the localhost. Made the form.php and html they worked. Manually input the database tested the database in Mysql and it worked. redid report.php to input the info and get Error querying database. every time, changed the code to what you guys have mentioned, checked the user rights and so on. I have tried everything.
I'm using vista home
PHP Version 5.2.9
mysql 5.0

Here is the last code I used top to bottom

<?php
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$how_many = $_POST['howmany'];
$alien_description = $_POST['aliendescription'];
$what_they_did = $_POST['whattheydid'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
$other = $_POST['other'];


$dbc = mysql_connect('localhost','myuser','mypass')
or die('Error connecting to mysql server.');

mysql_select_db('aliendatabase');

$query = "INSERT INTO aliens_abduction (first_name, last_name, " .
"when_it_happened, how_long, how_many, alien_description, " .
"what_they_did, fang_spotted, other, email)" .
"VALUES ('$first_name', '$last_name', '$when_it_happened',
'$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', " .
"'$fang_spotted', '$other', " .
"'$email')";

$result = mysql_query($query)
or die('Error querying database.');


mysql_close($dbc);

echo 'Thanks for submitting the form.<br />';
echo 'You were abducted ' . $when_it_happened;
echo ' and were gone for ' . $how_long . '<br />';
echo 'Number of aliens: ' . $how_many . '<br />';
echo 'Describe them: ' . $alien_description . '<br />';
echo 'The aliens did this: ' . $what_they_did . '<br />';
echo 'Was Fang there? ' . $fang_spotted . '<br />';
echo 'Other comments: ' . $other . '<br />';
echo 'Your email address is ' . $email;




?>

Please for the love of GOD help me find something


I'm a total newbie - so please forgive me if this sounds stupid...but...in your database, does "other" come before or after "email"? I see your order differs in the .php script. Maybe that matters??


#35 jrawnw

jrawnw

    New Member

  • Members
  • Pip
  • 6 posts

Posted 27 May 2009 - 02:29 PM

Mominator thanks but that was not it. I had one letter missing in "happened" on the database and that caused the problem. But if anyone is on Godaddy and trying this book please let me know if it's working for you on the GoDaddy mysql server. I cannot get it to connect no matter what.

#36 jrawnw

jrawnw

    New Member

  • Members
  • Pip
  • 6 posts

Posted 27 May 2009 - 08:14 PM

OK Persistance is King. After my second call to GoDaddy and getting absolutely no help I decided to read php.net site and found a simple connection code to try. Again it worked on the Localhost and not on the GoDaddy server. I called for the third time to GD tech support and I didn't take "I don't know" for an answer again. This guy checked with the big boys and found that I had IIS 6.0 running on my server. PHP only works on IIS 7.0 and I needed to upgrade. I did and I'm free at last Great God almighty I can move on. Hope that helps someone else. laugh.gif

Edited by jrawnw, 27 May 2009 - 08:16 PM.


#37 lemuel

lemuel

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 577 posts

Posted 27 May 2009 - 08:17 PM

Are you using "localhost" as the host name? I just helped a friend create a database on Godaddy and the hostname was of the form "XXXXXX.secureserver.net".

Edit: Nevermind. She is on a Linux server, IIS is Windows.

Edited by Lemuel, 27 May 2009 - 08:20 PM.


#38 technicka

technicka

    Active Member

  • Members
  • PipPip
  • 13 posts

Posted 29 May 2009 - 06:01 AM

QUOTE (Mominator @ May 25 2009, 02:14 PM) <{POST_SNAPBACK}>
Art - you are da bomb! THIS WORKED!!!!!!!


Same for me. It's slightly annoying the book doesn't mention these little differences (I know there was discussion about mysql vs. mysqli) but there is also a difference in this code of mysql_query($dbc, $query) versus mysql_query($query)

I guess this is caused from differences in PHP and MYSQL versions?

Edited by technicka, 29 May 2009 - 06:02 AM.


#39 AngelusUK

AngelusUK

    New Member

  • Members
  • Pip
  • 3 posts

Posted 17 June 2009 - 08:09 PM

Well, I have a few headfirst books (javascript, ajax, html css, etc but I have to say that php & MySQL is really not written with the novice in mind, I have tried everything that everyone has suggested here on how to connect to my MySQL database.

I have my own dedicated server and am up to date with all the current versions of php & MySQL, I have a few sites on there that are datbase driven and all of them connect fine to their respective MySQL databases.

However, nothing will allow me to connect for the chapter 2 tutorial. I am so glad that I didn't actually purchase this book and instead used the online version at oreilly.com and seeing as there has been no information offered by the author on this problem, then I think I will be deleting it from my bookshelf and using something else - and will not be buying a hard copy of this particular book.

After 14 hours of trying to get a connection both on my local machine and my own server, its left me feeling very frustrated indeed! angry.gif



#40 ricechex

ricechex

    Active Member

  • Members
  • PipPip
  • 18 posts

Posted 02 July 2009 - 03:38 PM

QUOTE (theartofconfusion @ May 24 2009, 10:40 PM) <{POST_SNAPBACK}>
Hello Guys,

I share your frustration. But, everything you guys said eventually pointed me in the right direction. I was actually able to send all the information to the database. I had been getting fatal errors all day. Here is the code that worked for me. Thanks guys!!!!! I hope all this helps someone else.

$dbc = mysql_connect('localhost','owen','aliensrool')
or die('Error connecting to mysql server.');

mysql_select_db('aliendatabase');

$query = "INSERT INTO aliens_abduction (first_name, last_name, " .
"when_it_happened, how_long, how_many, alien_description, " .
"what_they_did, fang_spotted, other, email)" .
"VALUES ('$first_name', '$last_name', '$when_it_happened',
'$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', " .
"'$fang_spotted', '$other', " .
"'$email')";

$result = mysql_query($query)
or die('Error querying database.');


mysql_close($dbc);



Hey first post Php newbie here. Thanks theartofconfusion. Two main things helped me solve the dreaded chapter 2 alien db report.php from your code and start writing to the db:

- mysql_select_db('mydbname');

- "INSERT INTO aliens_abduction (i had the db name, not underlying table name)


I DIDN"T HAVE the first bit of code at all and it wasn't in the book. I think many people could be confused by this. So again, i had to select the database first, THEN the underlying table name to insert. Now I'm filling out reports and by God it's working. I HATE that report!!

It took a few days off and on to get this and i was getting closer and closer each time. Also, i had to use the hosts shared db so i used db's IP to connect as server host. I'll be around this forum off and on so if anyone wants to see my code, i will oblige.

Good luck. Moving on..

Edited by ricechex, 02 July 2009 - 03:39 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users