eon201 Posted November 15, 2007 Share Posted November 15, 2007 Hi, Im trying to create a table in my database with three columns - ip - url - date The php connects to the database but errors when trying to create the table? I get this error .. CONNECT TO MYSQL SUCCESSFUL You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'log( id INT NOT NULL AUTO_INCREMENT, PRIMARY KE mysql_connect("localhost",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); echo 'CONNECT TO MYSQL SUCCESSFUL<br/><br/> '; mysql_query("CREATE TABLE log( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), ip VARCHAR(12), url VARCHAR(255), date VARCHAR(50))") or die(mysql_error()); echo "Table Created!"; What have I done wrong here. I think I have mucked up the syntax, but I cant see where.... Can anybody see the mistake?? Thanks in advance. Eon201 Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/ Share on other sites More sharing options...
axiom82 Posted November 15, 2007 Share Posted November 15, 2007 the id field's data type is INT but it should have a data length... i.e. INT(5) Have you heard of phpMyAdmin...definitely a must for php/mysql developers http://www.phpMyAdmin.net Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/#findComment-392070 Share on other sites More sharing options...
eon201 Posted November 15, 2007 Author Share Posted November 15, 2007 But surely it just increments as each new row is added to the table??? Or have I just got this completely wrong. It needs to increment as this script will add rows to the mysql table all day every day, therefore if I give it a data length it will only work up to a certain point?? ps. Yes I do know about phpmyadin, but creating tables from the php is a must for this script. Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/#findComment-392071 Share on other sites More sharing options...
axiom82 Posted November 15, 2007 Share Posted November 15, 2007 Yes, but the length of the INT is not the maximum value of the INT. The length is the maximum length of the digits...for example: Int(1) = -9 to 9 Int(2) = -99 to 99 Int(3) = -999 to 999 etc, etc. Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/#findComment-392076 Share on other sites More sharing options...
eon201 Posted November 15, 2007 Author Share Posted November 15, 2007 sorry but i dont get what you mean?? - noob Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/#findComment-392078 Share on other sites More sharing options...
logicopinion Posted November 15, 2007 Share Posted November 15, 2007 will this help you? <?php mysql_connect("$localhost", "$username", "$password") or die(mysql_error()); mysql_select_db("dbanem") or die(mysql_error()); echo "CONNECT TO MYSQL SUCCESSFUL"; mysql_query("CREATE TABLE IF NOT EXISTS tablename( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), ip VARCHAR(12), url VARCHAR(255), date VARCHAR(100)) ") mysql_query("INSERT INTO tablename (ip, url,date) VALUES('$ip', '$url', '$date' ) ") or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/#findComment-392091 Share on other sites More sharing options...
eon201 Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks logicopinion, But im still getting the sam error. axiom82 was probably on the right track. I just dont understand what he means!! Its so weird, ive never come across this problem before. ??? Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/#findComment-392097 Share on other sites More sharing options...
eon201 Posted November 15, 2007 Author Share Posted November 15, 2007 Ok I was being an idiot. I get what axiom82 means now, but even though I have changed the code, it still errors... Why is this??? It sucks being a noob!! code... mysql_query("CREATE TABLE log( id INT(100), PRIMARY KEY(id), ip VARCHAR(12), url VARCHAR(255), date VARCHAR(50))") or die(mysql_error()); echo "Table Created!<br/><br/>"; error... CONNECT TO MYSQL SUCCESSFUL You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'log( id INT(100), PRIMARY KEY(id), ip Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/#findComment-392106 Share on other sites More sharing options...
logicopinion Posted November 15, 2007 Share Posted November 15, 2007 try this id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), ip VARCHAR(12), url VARCHAR(255), date VARCHAR(50))") or die(mysql_error()); echo "Table Created!<br/><br/>"; Link to comment https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/#findComment-392117 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.