Jump to content

Quick question


paulman888888

Recommended Posts

What have i done wrong?

 

<?php
mysql_connect("something.com", "something", "something") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("something") or die(mysql_error());
echo "Connected to Database";
// Create a MySQL table in the selected database
mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
name VARCHAR(30), 
score INT),
ipaddress VARCHAR(30),
country VARCHAR(30),
date VARCHAR (30)")
or die(mysql_error());  

echo "Table Created!";

?>

 

Please help

 

Thankyou

Link to comment
Share on other sites

thanks but still doesnt work

now i get this error.

 

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 '(INT), ipaddress VARCHAR(30), country VARCHAR(30), date VA

 

thankyou anyway

 

paul

Link to comment
Share on other sites

mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
name VARCHAR(30), 
score INT,
ipaddress VARCHAR(30),
country VARCHAR(30),
date VARCHAR (30)")
or die(mysql_error()); 

 

That works.

 

Link to comment
Share on other sites

mysql_query(CREATE TABLE `example` (

`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,

`name` VARCHAR( 30 ) NOT NULL ,

`score` INT,

`ipaddress` VARCHAR( 30 ),

`country` VARCHAR( 30 ),

`date` VARCHAR (30)) or die (mysql_error());

 

This should work.

 

Any probs, shout!

 

Best Regards

 

 

Tom

Link to comment
Share on other sites

nope that doesnt work.

<?php mysql_query(CREATE TABLE `example` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 30 ) NOT NULL ,
`score` INT,
`ipaddress` VARCHAR( 30 ),
`country` VARCHAR( 30 ),
`thedate` VARCHAR (30)) or die (mysql_error());?>

 

I dont know why its not working. It comeing up with this Parse error: parse error, unexpected T_STRING in /home/www/mysite.com/install.php on line 7

 

Thankyou anyway

Any more ideas

 

Thankyou

Paul

Link to comment
Share on other sites

You have to assign each part to a string. So, for example:

 

<?php
$conn = mysql_connect("host", "user", "pass");
$db = mysql_select_db("database, $conn);
.....

 

And so on.

 

Now, for the query in question, you need to assign as follows:

 

<?php
$sql = mysql_query("CREATE TABLE `example` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 30 ) NOT NULL ,
`score` INT,
`ipaddress` VARCHAR( 30 ),
`country` VARCHAR( 30 ),
`thedate` VARCHAR (30)") or die (mysql_error());
?>

 

What I would then do, to make sure it worked, would to:

 

<?php
if ($sql) {
echo "Table Created";
}
?>

 

Any closer?

 

Best Regards

 

 

 

Tom

Link to comment
Share on other sites

this was my old install file.

 

<?php
mysql_connect("host", "and", "so on") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("anything") or die(mysql_error());
echo "Connected to Database";
// Create a MySQL table in the selected database
mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
name VARCHAR(30), 
score INT)")
or die(mysql_error());  

echo "Table Created!";

?>

 

But i wanted to add date, ipaddress and country but i  for some reason can't.

 

Would it be easy to start a whole new script? Because for some reason none of us can get it working.

Link to comment
Share on other sites

This is very funny.  ???

 

Another suggestion:

 

mysql_query("CREATE TABLE example (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30), 
score INT,
ipaddress VARCHAR(30),
country VARCHAR(30),
date VARCHAR (30)")
or die(mysql_error());

 

I can't think what else could be wrong with it.

 

Let me know how you get on.

 

Best Regards

 

 

 

Tom

Link to comment
Share on other sites

???

<?php
mysql_connect("www.com", "ssss", "essss") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("huh") or die(mysql_error());
echo "Connected to Database";
// Create a MySQL table in the selected database
mysql_query("CREATE TABLE myscore2 (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30), 
score INT,
ipaddress VARCHAR(30),
country VARCHAR(30),
thedate VARCHAR (30)")
or die(mysql_error());

echo "Table Created!";

?>

??? Still not working and i have no idea why?

Link to comment
Share on other sites

<?php
mysql_connect("host", "and", "so on") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("anything") or die(mysql_error());
echo "Connected to Database";
// Create a MySQL table in the selected database
$query=mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
name VARCHAR(30), 
score INT)")
or die(mysql_error());  
echo $query;  
echo "Table Created!";

?>

 

do this and tell me what query echos

Link to comment
Share on other sites

You put Primary Key in the wrong place:

 

CREATE TABLE `myscore2` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 30 ) NOT NULL ,
`score` INT NOT NULL ,
`ipaddress` VARCHAR( 30 ) NOT NULL ,
`country` VARCHAR( 30 ) NOT NULL ,
`thedate` VARCHAR( 30 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM

 

try that.

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.