14 Replies - 649 Views - Last Post: 14 September 2009 - 02:32 AM

#1 mikecheer101   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 114
  • Joined: 12-June 09

myslq is failing and I don't know why

Posted 11 September 2009 - 03:30 PM

i opened a new thread because it wouldnt let me reply to my other one any ways can anyone fix this i keep getting an error
<?php
session_start();

$dbhost = "mysql12.000webhost.com";
$dbuser = "a3693917_123";
$dbpassword = "mike95";

$dbdatabase = "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($a3693917_123, $db);

$sql = "SELECT * FROM products;";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result)) {
   echo $row['product'];
}
?>


Is This A Good Question/Topic? 0
  • +

Replies To: myslq is failing and I don't know why

#2 gregwhitworth   User is offline

  • Tired.
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,613
  • Joined: 20-January 09

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 03:38 PM

What error? Be more specific, and next time don't just write HELP! as your title, make it descriptive.

Not to mention - you need to change your credentials now.

--

Greg

Remove the semi-colon from your query:
$sql = "SELECT * FROM products;";




to

$sql = "SELECT * FROM products";


Was This Post Helpful? 0
  • +
  • -

#3 mikecheer101   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 114
  • Joined: 12-June 09

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 04:02 PM

it says error on line 14
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6839
  • View blog
  • Posts: 31,513
  • Joined: 10-May 07

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 04:10 PM

Try running the following, & seeing why mysql is failing.

$sql = "SELECT * FROM products;";
$result = mysql_query($sql) or die(mysql_error());;


Was This Post Helpful? 0
  • +
  • -

#5 gregwhitworth   User is offline

  • Tired.
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,613
  • Joined: 20-January 09

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 04:14 PM

Me counting the lines from your code above is this line:
mysql_select_db($a3693917_123, $db);




Is that correct.

That is why I said to be specific, error on line 14 but what error? Also, if you add 'or die' after the queries and db connections it allows you to know where it is dying a little better.

For example:
<?php
session_start();

$dbhost = "mysql12.000webhost.com";
$dbuser = "a3693917_123";
$dbpassword = "mike95";

$dbdatabase = "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($a3693917_123, $db) or die("Could not connect to the database");

$sql = "SELECT * FROM products;";
$result = mysql_query($sql) or die("Could not complete your query");

while($row = mysql_fetch_assoc($result)) {
   echo $row['product'];
}
?>


This will stop your algorithm in its tracks and echo your statement in the quotes.

If the line above is the error - then my guess is the fact that you are giving the user twice, it should just be this:

mysql_select_db($db);



Hope that helps,
Greg
Was This Post Helpful? 0
  • +
  • -

#6 mikecheer101   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 114
  • Joined: 12-June 09

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 05:59 PM

i added both of those and it says no database selected?
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 06:04 PM

Your problem is that you're not telling it which database to select. You have these variables

$dbhost = "mysql12.000webhost.com";
$dbuser = "a3693917_123";
$dbpassword = "mike95";
$dbdatabase = "productsdb";




Then when you use mysql_db_select you're passing variables that aren't even declared

mysql_select_db($a3693917_123, $db)



$a3693917_123 is never declared. Try this

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);



Was This Post Helpful? 0
  • +
  • -

#8 mikecheer101   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 114
  • Joined: 12-June 09

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 06:11 PM

nope this is wat the code looks like now
<?php
session_start();

$dbhost = "mysql12.000webhost.com";
$dbuser = "a3693917_123";
$dbpassword = "mike95";

$dbdatabase = "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $db);

$sql = "SELECT * FROM products;";
$result = mysql_query($sql) or die(mysql_error());;

while($row = mysql_fetch_assoc($result)) {
   echo $row['product'];
}
?>

Was This Post Helpful? 0
  • +
  • -

#9 tommyflint   User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 06:15 PM

In that script you use the varible: $dbdatabase to store the database name and then when you go to select the database you are using a different varible which hasn't been declared you need to change the
mysql_select_db($database, $db);

Tooo

mysql_select_db($dbdatabase, $db);



tommyflint
Was This Post Helpful? 0
  • +
  • -

#10 gregwhitworth   User is offline

  • Tired.
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,613
  • Joined: 20-January 09

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 06:17 PM

First off you aren't doing error checking, second of all you have two semi colons again:

or die(mysql_error());;



Nice catch tommy.
Was This Post Helpful? 0
  • +
  • -

#11 mikecheer101   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 114
  • Joined: 12-June 09

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 06:18 PM

it says "no database selected"?
Was This Post Helpful? 0
  • +
  • -

#12 tommyflint   User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 06:33 PM

are they incorrect username and password in that script becuase if not i can try test the script for you?

tommyflint
Was This Post Helpful? 0
  • +
  • -

#13 mikecheer101   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 114
  • Joined: 12-June 09

Re: myslq is failing and I don't know why

Posted 11 September 2009 - 06:49 PM

it still wont connect and don't know why.

This post has been edited by mikecheer101: 12 September 2009 - 09:14 AM

Was This Post Helpful? 0
  • +
  • -

#14 mikecheer101   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 114
  • Joined: 12-June 09

Re: myslq is failing and I don't know why

Posted 12 September 2009 - 11:27 AM

it says no data base selected
<?php
session_start();

$dbhost = "mysql12.000webhost.com";
$dbuser = "a3693917_123";
$dbpassword = "mike95";

$dbdatabase = "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);

$sql = "SELECT * FROM products;";
$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($result)) {
   echo $row['product'];
}
?>

Was This Post Helpful? 0
  • +
  • -

#15 Sc00by22   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 09-September 09

Re: myslq is failing and I don't know why

Posted 14 September 2009 - 02:32 AM

Remove the semicolon from

$sql = "SELECT * FROM products;";


It should look like this

$sql = "SELECT * FROM products";

This post has been edited by Sc00by22: 14 September 2009 - 02:33 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1