I tried to create a table like I use to do but it's not working anymore. I don't get any fail messages but the table is not created. Has it something to do with the recently made Mysql updates? I don't understand...
I tried to create a table like I use to do but it's not working anymore. I don't get any fail messages but the table is not created. Has it something to do with the recently made Mysql updates? I don't understand...
And how was that? cPanel? Using phpMyAdmin's table wizard? Running a query from phpMyAdmin? Running a query from a script? Something else? When asking for help, be precise and informative.
Last edited by misson; 02-11-2010 at 08:37 PM.
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
"Running a query from a script?" jepp, that's how, like I've done thousand times before.
Code:
// Connects to your Database
$con = mysql_connect("localhost", "xxxxxx", "xxxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("md7dani2_haveroom", $con);
mysql_query("CREATE TABLE subscr(ID varchar(30),check varchar(5))");
mysql_query("INSERT INTO subscr(ID,check) VALUES ('Daniel','Yes')");
mysql_close($con);
Have you tried doing it via PHPmyAdmin?
I ask this just to see where the problem might lie. I know you want to be able to do it via script.
Nothing is always absolutely so.
haven't done that. How do I write the query in phpMyadmin? I've Tried different querys: CREATE TABLE subscr(ID varchar(30),check varchar(5)); ,but no success.
"#1064 - 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 'varchar(5))' at line 1"
thx in advance.
The problem is that you named one of your columns 'check' apparently 'check' is some kind of command or constant in MySql. So this should work:
CREATE TABLE subscr(ID varchar(30),checkid varchar(5));, or whatever you'll name it.
I've done this beforespent hours in computercidal rage, trying to figure out what's wrong, only to find out that one of my variables is the reserved word.
Hope this will help.
P.S. I would set up mysql on your home computer/laptop, it's much easier to check queries that way, before plugging 'em into your script.
Last edited by garikr; 02-12-2010 at 05:49 PM.
Nice catch. Didn't even pay attention to the column names.
But, I just used phpMyAdmin to create a table, using their 'wizard' which generated this code:
and the table was created.Code:CREATE TABLE `XXXXX_test`.`test01` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT , `check` INT NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM ;
Maybe you have to make sure to quote the field name.
Nothing is always absolutely so.
event with the same column name you might be to create a table
try this
notice the col-name enclosed in a back-tick (`)mysql_query("CREATE TABLE subscr(`ID` varchar(30),`check` varchar(5))");
mysql_query("INSERT INTO subscr(`ID`,`check`) VALUES ('Daniel','Yes')");
One should alwaz use this to prevent any such problem.
The same thing can also be used in table names if there is such a problem esp when we need to create tables based on user input
P.S.@ DESCALZO Quote may not work in such situations.
Last edited by rkalhans; 02-12-2010 at 02:23 PM.
You are right, descalzo, using ` around the check does the trick. I didn't even know you can use ` in mysql. ` and not '. I think that's the first time I've used that key on my keyboard. Any other languages accept ` in their syntax??
P.S. so "back-tick" is it's name...![]()
Last edited by garikr; 02-12-2010 at 02:25 PM.
Some languages use `command` to execute shell commands (if it is enabled).
I cannot think of any (besides SQL) that use `backticks` like 'single' or "double" quotes.
Nothing is always absolutely so.