Forum Moderators: coopster

Message Too Old, No Replies

another mysql and PHP problem

         

jcmiras

12:03 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Guys, what do you think is the problem in this code
$branch="table1";
$sql4 = "CREATE TABLE $branch (
link_id int(11) NOT NULL auto_increment,
frombus int(11) DEFAULT '0' NOT NULL,
to int(11) DEFAULT '0' NOT NULL,
r float DEFAULT '0' NOT NULL,
x float DEFAULT '0' NOT NULL,
length float DEFAULT '0' NOT NULL,
PRIMARY KEY (link_id)
)";

result=mysql_query($sql4);

mysql query always failed.

tomda

12:13 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi jcmiras,

When you have such errors, the best way is to echo the query (echo $sql4), copy it and paste it the SQL box of PHP MyAdmin.

This is what I did, and it refused because you can't call a field "TO". By just changing the name of the field, it will work.

Mark Barrett

12:46 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Tomba

Can you please explain again what you did?
I have PHPMyAdmin
Do you mean it will tell you potentially where there is an error in your code?
What exactly do you cut and paste into the SQL box?
Sorry if my question is naive - but I am on a steep learning curve!

Thanks

Mark Barrett

tomda

1:12 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, PHP MYADMIN will tell the error and you will be able to correct them easily.

1/ In your php file, just echo the query (echo $sql4).
Refresh your page and you should get something like this in your browser window.

CREATE TABLE table1 (link_id int(11) NOT NULL auto_increment, frombus int(11) DEFAULT '0' NOT NULL, to int(11) DEFAULT '0' NOT NULL, r float DEFAULT '0' NOT NULL, x float DEFAULT '0' NOT NULL, length float DEFAULT '0' NOT NULL, PRIMARY KEY (link_id))

2/ Copy the query

3/ Open PHP MYADMIN in a new tab (FF) or window (IE)

4/ Paste the query in the SQL Query Box and click on the button.

5/ Either the query will be successfull and it will create the table, either it will fail and you will get a warning message. It gave me that there was an error at the line "to ...".

Mark Barrett

1:50 pm on Jun 13, 2005 (gmt 0)

10+ Year Member




That sounds like a very useful tool.

I will have a play around - try putting in some deliberate errors and see what results I get.

Thanks for that!

Mark