Jump to content

[SOLVED] creating table in mysql


eon201

Recommended Posts

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?? :o

 

Thanks in advance. Eon201 ;D

Link to comment
https://forums.phpfreaks.com/topic/77449-solved-creating-table-in-mysql/
Share on other sites

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.

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()); 

?>

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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.