[PHP]Problem connecting to SQL DB I suppose
Heres the deal: I'm creating a cms on my home-server:
TowelWeb v1.0
now i tried to move it to another web-host, and I get the towelweb is exiting message from this code:
PHP Code:
include('includes/connect.php');
$query = mysql_query("SELECT * FROM cms_themeconfig");
if(mysql_num_rows($query) >= 1) {
while($row = mysql_fetch_array($query)) {
// When variables are made, they will be put here //
$themepath = $row['themepath'];
$themename = $row['themename'];
}
} else {
echo "You must insert a new row into CMS_themeconfig!! TowelWEB is now exiting.";
exit();
}
unset($row);
unset($query);
include('includes/disconnect.php');
here is connect.php:
PHP Code:
<?php
$con = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $con);
?>
Before you ask, yes my database information was changed, and yes there is a row in cms_themeconfig.
Re: [PHP]Problem connecting to SQL DB I suppose
PHP Code:
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
and that will tell you what causes the error.
Re: [PHP]Problem connecting to SQL DB I suppose
dammit.. I totally forgot i turned error reporting off lmao!
edit:
The error is still there though :/ Its very uncool lol
Re: [PHP]Problem connecting to SQL DB I suppose
What are the variables? I am new to PHP so this probably wont help but instead of
$con = mysql_connect($dbhost,$dbuser,$dbpass);
try
$con = mysql_connect("$dbhost","$dbuser","$dbpass");
Just trying to help , sorry if I m incorrectt :P:
Re: [PHP]Problem connecting to SQL DB I suppose
Quote:
dammit.. I totally forgot i turned error reporting off lmao!
edit:
The error is still there though :/ Its very uncool lol
Of course it's there , but it shows you what's wrong with detail. Can eventually paste the error here?
Quote:
What are the variables? I am new to PHP so this probably wont help but instead of
$con = mysql_connect($dbhost,$dbuser,$dbpass);
try
$con = mysql_connect("$dbhost","$dbuser","$dbpass");
Just trying to help , sorry if I m incorrectt
the correct is mysql_connect(host,user,password); , no quotes needed.
Re: [PHP]Problem connecting to SQL DB I suppose
there is no PHP error. Only that it wont find my row in the table. As far as PHP goes, it connects to the DB just fine.. But it wont grab from the table.
Re: [PHP]Problem connecting to SQL DB I suppose
Hmm ... try like this
PHP Code:
<?php
// Make a MySQL Connection
$query = "SELECT * FROM cms_themeconfig";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$themepath = $row['themepath'];
$themename = $row['themename'];
}
?>
this will loop until there is no more data to get from that table
also the row order i think counts.
Re: [PHP]Problem connecting to SQL DB I suppose
Quote:
Originally Posted by
Habbro
What are the variables? I am new to PHP so this probably wont help but instead of
$con = mysql_connect($dbhost,$dbuser,$dbpass);
try
$con = mysql_connect("$dbhost","$dbuser","$dbpass");
Just trying to help , sorry if I m incorrectt :P:
The quotation marks are unnecessary but it won't break the code.
When a variable is placed in a string, it is read as literal if apostrophes are used (i.e. echo ('$dbhost'); makes the HTML page say $dbhost). But when using quotation marks, PHP variables inside the string are shown.
King Towel, I am interested in what $query is returning. First, try kutsumo's code and see if the result changes at all. I suspect the query may be bugging out for whatever reason.
If kutsumo's code does not change the output, then please tell me the result of this:
PHP Code:
include('includes/connect.php');
$query = mysql_query("SELECT * FROM cms_themeconfig");
echo var_export($query) . "\n" . var_export(mysql_num_rows($query);
include('includes/disconnect.php');
Re: [PHP]Problem connecting to SQL DB I suppose
Trying kutsumo's code right meow.. will edit this post.
EDIT
Well i tried the code, and It gave me the SQL error no database selected.
Quote:
mysql_select_db($dbname, $con);
this code ^^ is definitely in connect.php and the include works just fine.. Im going to try it on another webhost for shits and giggles just to see if its the sql database..
Re: [PHP]Problem connecting to SQL DB I suppose
Are you using free hosts?
Re: [PHP]Problem connecting to SQL DB I suppose
Yes sir. For me its free or host it yourself. Im already running another site on my dedi so hosting it myself is out of the question.
However i switched from x10hosting to freehostia and the problem has been fixed. Thanks for all your help guys.
Working website:
TowelWEB
Re: [PHP]Problem connecting to SQL DB I suppose
http://i.imgur.com/Ily3w.jpg
offtopic : looks like it's missing a picture , and cool.
By the way , freehostia is slow , and sometimes it goes offline all of sudden. I was hosting there too for a while.
Re: [PHP]Problem connecting to SQL DB I suppose
thanks, its fixed.
Mod can close thread, problem resolved :D
and agreed, freehostia is damned slow.. May have to invest in paid hosting soon :/