Help - Search - Members - Calendar
Full Version: Custom Create Table
Zymic Webmaster Forums > Zymic Free Web Hosting > Databases & MySQL
MrFish
PhpMyAdmin doesn't log me in. I don't know why but it never loads the page. I don't mind writing my own tables/databases/entries but does Zymic let you? I've tried this script to test it out, and it won't create my table. It also doesn't give me an error report.

CODE
<html>
<body>

<?
$con = mysql_connect('localhost', '********', '********');
if(!$con){
die();
echo 'Mysql did not connect: ' . mysql_error();
}
if(mysql_select_db('robocookie_userdb', $con)){
echo 'Database selected <br />';
} else {
die();
echo mysql_error();
}
if (mysql_query("CREATE TABLE users(id INT, username Varchar(255), password Varchar(255)")){
echo 'Table Created';
} else {
echo 'Table not created';
die();
echo mysql_error();
}
?>

</body>
</html>


This is what the page looks like-

QUOTE
Database selected
Table not created


What's up? Is my code wrong or is it Zymic? My code is right by w3schools standards.
Braunson
Hello, My name is Braunson.

First off, you cannot put a die(); before a echo, as the die() function completely stops the page from loading any more. So with the way you have it, the page would just stop loading and anything after that in that if statement would not display.

Secondly, your were missing a ')' from the SQL statement.

Third, try this code..
CODE
<?php
$con = mysql_connect('localhost', '********', '********');

if(!$con){
    echo 'Mysql did not connect: ' . mysql_error();
    die();
}

$db_conn = mysql_select_db('robocookie_userdb', $con);

if(!$db_conn){
    echo mysql_error();
    die();
} else {
    echo 'Database selected <br />';
}

$sql = "CREATE TABLE users (
        id INT,
        username VARCHAR(255),
        password VARCHAR(255)
        )";

$query = mysql_query($sql);

if(!$query){
    echo 'Table not created '.mysql_error();
    die();
} else {
    echo 'Table Created';
}
?>


Please reply if this works or not.
MrFish
I replied in the other post too. I'm not sure exactly what I did right this time around but I sorta copied how yours looked and it worked great. Here is my code-

CODE
<html>
<body>
<?
$con = mysql_connect('localhost', 'robocookie_1', 'OOPPS, DUN LOOK ><');
if(!$con){
die();
echo 'Mysql did not connect: ' . mysql_error();
}
if(mysql_select_db('robocookie_udb', $con)){
echo 'Database selected <br />';
} else {
die();
echo mysql_error();
}
$queryinfo = "CREATE TABLE ui (id INT, username varchar(255), password varchar(255))";
$query = mysql_query($queryinfo) or mysql_error();
?>
</body>
</html>


Thank you very much for helping me with my problem biggrin.gif
Braunson
Your very welcome! But you might want to follow my code as with your previous code, you have the script die before it can echo out the mysql_error, thus the page will be blank and you will not see an error.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.