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
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.

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.