Custom Create Table |
||
Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.
In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.
Zymic Webmaster Forums Zymic Free Web Hosting Databases & MySQL |
||
![]() |
Custom Create Table |
||
Jun 12 2009, 10:38 PM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 7 Joined: 12-June 09 Member No.: 99,337 |
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. |
|
|
Jun 13 2009, 03:55 AM
Post
#2
|
|
![]() Newbie ![]() Group: Members Posts: 23 Joined: 19-September 07 From: Niagara Falls, Ontario, Canada Member No.: 80 |
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. |
|
|
Jun 13 2009, 05:46 AM
Post
#3
|
|
|
Newbie ![]() Group: Members Posts: 7 Joined: 12-June 09 Member No.: 99,337 |
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 |
|
|
Jun 13 2009, 05:48 AM
Post
#4
|
|
![]() Newbie ![]() Group: Members Posts: 23 Joined: 19-September 07 From: Niagara Falls, Ontario, Canada Member No.: 80 |
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.
|
|
|
![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users) |
||
| 0 Members: | ||
Forum Jump |
||
| Lo-Fi Version | Time is now: 21st November 2009 - 09:00 AM |