table creation

Codes here !

Moderators: egami, macek, gesf

Post Reply
User avatar
xlordt
New php-forum User
New php-forum User
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ
Contact:

Sun Feb 09, 2003 9:37 pm

this is really weard.. i created this script.. but its not creating the table....

Code: Select all


<?php

$db_name = "test";
$table_name = "users";

$db = @mysql_connect("localhost", "x", "123") or
      die ("Could not connect to mysql");
      mysql_create_db($db_name, $db);
      mysql_select_db($db_name, $db);

$db_table = "CREATE TABLE $table_name (id INT NOT NULL AUTO_INCREMENT, username
VARCHAR(255))";
$table_Creation = mysql_db_query($table_name, $db_table, $db);
  echo "creation as been made successfully!";

?>


i cant figure out why.. =/ the error that i keep getting is..
Computer/Programm rox.. (php, c/c++ will take over soon muhahah

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Tue Feb 11, 2003 3:53 pm

Try this:

Code: Select all

$sql ="CREATE TABLE ".$table_name."   (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,username VARCHAR(255))";
   $myconn = mysql_connect($server,$user,$password);
if (!@mysql_select_db($database)){
   echo "Couldn't open database";
   exit();
}

if(!@mysql_query($sql,$myconn)){
   echo "Error: ".mysql_error();
}else{
   echo ("Table succesfully created");
}

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests