Pauls74462 Posted June 21, 2010 Share Posted June 21, 2010 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 More sharing options...
wirehopper Posted June 22, 2010 Share Posted June 22, 2010 You might want to change the table name, the user table is used by MySQL.http://dev.mysql.com/doc/refman/5.1/en/adding-users.html Link to comment Share on other sites More sharing options...
Pauls74462 Posted June 22, 2010 Author Share Posted June 22, 2010 You might want to change the table name, the user table is used by MySQL.OK, I changed it from "users" to "Members" no differances Link to comment Share on other sites More sharing options...
End User Posted June 22, 2010 Share Posted June 22, 2010 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 More sharing options...
NurAzije Posted June 22, 2010 Share Posted June 22, 2010 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 More sharing options...
justsomeguy Posted June 22, 2010 Share Posted June 22, 2010 You're only checking for errors when you connect, you should be checking everywhere else also. e.g.:mysql_query($sql, $link) or exit(mysql_error()); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.