Jump to content

CREATE TABLE on database


coop

Recommended Posts

CREATE TABLE on database

Hi 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.