coop Posted December 8, 2006 Share Posted December 8, 2006 CREATE TABLE on databaseHi all,I'm new to php, so I'm going through a few tutorials like the one below. I'm stuck why I carn't create a table on the database. I get the "success in database connection" and "success in database creation", but then "No tables". Is there an obvious problem with the code.[code=php:0]<?php//set your info$dbhost ='localhost';$dbusername ='root';$dbpassword = 'root';$dbname = 'firstdb';////connect to the mysql database server.$link_id = mysql_connect($dbhost,$dbusername,$dbpassword);echo"success in database connection <br>";////create database.$dbname = $dbusername."_".$dbname;if(!mysql_query("CREATE DATABASE $dbname")) die(mysql_error()); echo"success in database creation <br>"; $result="CREATE TABLE address_book (first_name VARCHAR(25) last_name VARCHAR(25) phone_number VARCHAR(15))";if(mysql_query($result)){ echo"table created";}else{ echo"No tables"; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/29943-create-table-on-database/ Share on other sites More sharing options...
boo_lolly Posted December 8, 2006 Share Posted December 8, 2006 you need commas separating your column names...[code=php:0]$result = "CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))";[/code] Link to comment https://forums.phpfreaks.com/topic/29943-create-table-on-database/#findComment-137567 Share on other sites More sharing options...
desithugg Posted December 8, 2006 Share Posted December 8, 2006 yup commas Link to comment https://forums.phpfreaks.com/topic/29943-create-table-on-database/#findComment-137568 Share on other sites More sharing options...
coop Posted December 8, 2006 Author Share Posted December 8, 2006 still no luck, sorrystill gettingsuccess in database connection success in database creation No tables Link to comment https://forums.phpfreaks.com/topic/29943-create-table-on-database/#findComment-137575 Share on other sites More sharing options...
jsladek Posted December 8, 2006 Share Posted December 8, 2006 do you have to select that database now that you created it?mysql_select_db();-John Link to comment https://forums.phpfreaks.com/topic/29943-create-table-on-database/#findComment-137606 Share on other sites More sharing options...
Trium918 Posted December 10, 2006 Share Posted December 10, 2006 [color=blue]$result[/color] [color=green]=[/color][color=red]"create table if not exists address_book (first_name VARCHAR(25) Not Null Primary Key , last_name VARCHAR(25) Not Null, phone_number VARCHAR(15) Not Null)"[/color][color=green];[/color] Link to comment https://forums.phpfreaks.com/topic/29943-create-table-on-database/#findComment-138301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.