View Full Version : [RESOLVED] Why wont my script create a Database?
irjason
10-24-2007, 06:26 PM
Hey, learning now how to use mysql to store data, plan to make a very simple register / login system for my site. what i'm getting problems with is the fact i can even make a connection by the looks to mysql. thats set up on my pc..
here is a image of what i have now.. from the tutoiral
http://www.w3schools.com/php/php_mysql_create.asp
It's not echoing anything on the site how come?
http://img155.imageshack.us/img155/2025/whywontthisworkue2.jpg
and code if u cant see it in image easly.
<html>
<body>
<?php
$con = mysql_connect("localhost","jason","1234");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
</body>
</html>
BillyGalbreath
10-24-2007, 06:57 PM
Your code looks good...
To get more info from the server, do this:
/*if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}*/
mysql_query("CREATE DATABASE my_db",$con) or die(mysql_error());
This basically comments out your entire if/else statement and will create a DIE() statement when it errors. The DIE() statement will be direct output of what mysql said was wrong.
;)
irjason
10-24-2007, 07:07 PM
Awh that's, But it still wont create a database =[
BillyGalbreath
10-24-2007, 07:26 PM
Yeah, duh! It's not anything different from your code, so its still not going to work.... But what it _is_ going to do is show you more detailed error messages... That way, you have a better idea of what is going wrong and how to fix it...
;)
irjason
10-24-2007, 09:22 PM
=[ i have no idea what's wroung php doesnt seem to want to connect to mysql.. even if i change the password to a bad one and the location to a bad one. it just displays a white screen.. i see it at bottom of browser saying connecting .. but its so fast i cant see if there is a error or not.. since its not shown on the page.. =[
BillyGalbreath
10-25-2007, 12:17 AM
<html>
<body>
<?php
$conn = mysql_connect("localhost","jason","1234") or die(mysql_error());
mysql_query("CREATE DATABASE my_db",$conn) or die(mysql_error());
mysql_close($conn);
?>
</body>
</html>
Try that. I changed $con to $conn - if there are _any_ errors at all, they will be output to the browser in full detail.
;)
Horus_Kol
10-25-2007, 05:49 AM
Yeah, duh! It's not anything different from your code, so its still not going to work....
Play nice there Billy...
Jason,
Can we do a bit more checking out of stuff... if you put echo "something" right at the top of the script, do you see anything?
It's strange that there is absolutely nothing coming out of the script, and that it is "loading" all the time - is that the entire script?
Try some other echo's through the script to see where it is getting stuck?
BillyGalbreath
10-25-2007, 05:50 PM
Play nice there Billy...
Didn't know I wasn't being nice... ;)
If I came off as being rude, I apologize. I didn't mean it in a negative way.
irjason
10-25-2007, 09:06 PM
Haha, It's fine didn't even notice you were being rude oO. anyway i got it work. seem's that for some reason on my home pc the mysql wont work. so i ordered some web space etc with mysql etc support and seem to have it working not using the con way though.. had to use
$dbh = mysql_connect("rdbms.****.de", "U******", "*******");
$query = "use ******";
if (!mysql_query($query, $dbh)) the ("Database doesn’t exist. \n");
thanks for support! =] (p.s i **** out any important info :P)
and here is a link to what i got so far.. simple really it's a form u fill out ..and submits the data to mysql and email's it to me. got that all working now.. since i'm new to php and mysql and html and .css it's just basically me testing out stuff. and learning. Just got a small problem with the emailing.. but ill post in another thread since it's gone off the topic! thanks again all.
http://www.fallenleavesro.com/test2.php
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.