Jump to content

db error


Pauls74462

Recommended Posts

Whats wrong with the below code, all I'm getting is "Connected to db" but when I go into phpMyAdmin the table user is not there!

<?phpinclude ("config.php");// Make a MySQL Connection$link = mysql_connect( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());if (!$link) { die('Could not connect: ' . mysql_error()); }echo "Connected to db ";// select the database//mysql_select_db($dbname) or die ("Could not select database because ".mysql_error());// Create tablemysql_select_db($dbname, $link);$sql = "CREATE TABLE users(column_Domain varchar(99),column_Location varchar(99),)";// Execute querymysql_query($sql, $link);mysql_close($link);?>
Link to comment
Share on other sites

You have an extra comma after the last column definition. It should be:CREATE TABLE users(column_Domain varchar(99),column_Location varchar(99))

Link to comment
Share on other sites

Use this code to catch errors in future:<?function logging_function($msg, $lvl, $email) { /* this is just a function I use to customize my logging. It is in one of my general include files. $msg is the error message $lvl is an arbitrary error level I assign for search purposes $email is t/f indicating if it should send an email alert as well */ error_log("L$lvl:$msg"); if ($email) { // send mail about the error }} $query="SELECT * FROM MyTable";if (!($result=mysql_query($query))) { $err=mysql_error(); $errnum=mysql_errno(); logging_function("MySQL error $errnum ($err) in file at line#",1,false); // forward to an error control page for the user header('location:there-was-an-error.php'); die();}?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...