create table using php & mysql....need help

hi experts ! I’m new to PHP & MySQL , PLS point out the error . Thank you in advance.
This is what happed when i run the code :

Could not create the table because:
Query was empty.
The query being run was: CREATE TABLE entries (entry_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100)NOT NULL, entry TEXT NOT NULL, date_entered DATETIME NOT NULL )

// Inside my php code: //

Create a Table <?php //Script 12.4 - create_table.php /* this script connects to the MySQL server,selects the database,and creates a table */

//connect and select:
if($dbc=@mysql_connect(‘localhost’,‘root’,‘xxxxxx’)) {

// handle the error if the database could’t be selected:
if(!@mysql_select_db(‘myblog’)) {
print’

Could not select the database because:
’.mysql_error().’.

’;
mysql_close();
$dbc = FALSE;
}

} else { //Connection failure.
print ‘

Could not connect to MySQL:
’.mysql_error().’.

’;
}

if($dbc) {

  //Define the query:
  $query = 'CREATE TABLE entries (entry_id INT UNSIGNED NOT NULL
  AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(100)NOT NULL,
  entry TEXT NOT NULL,
  date_entered DATETIME NOT NULL
  )';
  
  
  //execute the query:
  if(@mysql_query($querry)) {
     print '<p>The table has been created.</p>';
  
  } else {
     print '<p style="color:red;">
     Could not create the table because:<br/>'.mysql_error().'.</p>
     <p>The query being run was: '.$query.'</p>';
  }
  
  
  mysql_close();  ////close the connection
  }

?>

guys…i solved it ;D i make s stupid mistake there…
typo in my php code causing query to not run.

de ja vue…
:smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service