28rain Posted February 8, 2009 Share Posted February 8, 2009 ok im using MySQL version;5.0.67 community edition 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 ')' at line 1 From this script <? $db_name ="testDB"; $connection = @mysql_connect("127.0.0.1", "*****", "******") or die (mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $sql = "CREATE TABLE $_POST[table_name] ("; for ($i = 0; $i < count($_POST['field_name']); $i++){ $sql .= $_POST['field_name'][$i]." ".$_POST['field_type'][$i]; if ($_POST['field_length'][$i] != ""){ $sql .= " (".$_POST['field_length'][$i]."),"; } else { $sql .= " , "; } } $sql = substr($sql, 0 , -1); $sql .= ")"; $result = mysql_query($sql,$connection) or die(mysql_error()); if ($result){ $msg = "<p>".$_POST[table_name]." has been created!</p>"; } ?> <html> <head> <title>Create a Database table: step 3</title> </head> <body> <h1>Adding Table to <? echo "$db_name"; ?> ...</h1> <? echo "$msg"; ?> </body> </html> Any help is appreciated! Thanks P.s yes I am using the correct username / password Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 8, 2009 Share Posted February 8, 2009 If you echo out the $sql variable, you or someone else could probably immediately see what is wrong with the sql syntax. Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757497 Share on other sites More sharing options...
28rain Posted February 8, 2009 Author Share Posted February 8, 2009 I cant echo it because im still getting the error Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757499 Share on other sites More sharing options...
trq Posted February 8, 2009 Share Posted February 8, 2009 Replace this... $result = mysql_query($sql,$connection) or die(mysql_error()); with.... die($sql); $result = mysql_query($sql,$connection) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757502 Share on other sites More sharing options...
28rain Posted February 8, 2009 Author Share Posted February 8, 2009 Ok that did something but now insted of doing the html it is just 'echo ing' the $sql variable This is what i get (Sorry i was randomly typing in things as a tester) CREATE TABLE my_rand (gdfd char , werw char , jhdj varchar (123),sttg date ,) and this is the code <? $db_name ="testDB"; $connection = @mysql_connect("127.0.0.1", "*****", "****") or die (mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $sql = "CREATE TABLE $_POST[table_name] ("; for ($i = 0; $i < count($_POST['field_name']); $i++){ $sql .= $_POST['field_name'][$i]." ".$_POST['field_type'][$i]; if ($_POST['field_length'][$i] != ""){ $sql .= " (".$_POST['field_length'][$i]."),"; } else { $sql .= " , "; } } $sql = substr($sql, 0 , -1); $sql .= ")"; die($sql); $result = mysql_query($sql,$connection) or die(mysql_error()); if ($result){ $msg = "<p>".$_POST[table_name]." has been created!</p>"; } ?> <html> <head> <title>Create a Database table: step 3</title> </head> <body> <h1>Adding Table to <? echo "$db_name"; ?> ...</h1> <? echo "$msg"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757511 Share on other sites More sharing options...
Mchl Posted February 8, 2009 Share Posted February 8, 2009 Does the comma before last ) not bother you? It should CREATE TABLE my_rand (gdfd char , werw char , jhdj varchar (123),sttg date ,) Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757514 Share on other sites More sharing options...
28rain Posted February 8, 2009 Author Share Posted February 8, 2009 Ok now i get this i have made it a bit clearer and fixed last comma CREATE TABLE my_rand (date_acq date , Name varchar (100),Title varchar (150),Length float (10)) Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757519 Share on other sites More sharing options...
PFMaBiSmAd Posted February 8, 2009 Share Posted February 8, 2009 So, if you remove the code change that thorpe gave for troubleshooting purposes, does the mysql_query work? Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757522 Share on other sites More sharing options...
Mchl Posted February 8, 2009 Share Posted February 8, 2009 I think FLOAT(10) is incorrect syntax, but did not check that. Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757533 Share on other sites More sharing options...
28rain Posted February 8, 2009 Author Share Posted February 8, 2009 i get the origional error. Seems as if thorns code is vital? Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757586 Share on other sites More sharing options...
Mchl Posted February 8, 2009 Share Posted February 8, 2009 Oh it is. It stops the script before it runs the query. Did you check if FLOAT(10) is correct syntax? It happens to be in same place that previous error was, so it might provoke same error message. Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757590 Share on other sites More sharing options...
28rain Posted February 8, 2009 Author Share Posted February 8, 2009 Ah wiked thanks guys it works now. I dont get how my stupid guide makes stupid mistakes like that! I didnt use a float on another test and it wrked just fine! P.s Im trying to list all the databases i have but the code prints on the screen; No database selected. just i wrote all this code and it doesnt work could you help lmfao! <? $connection = @mysql_connect("127.0.0.1", "**", "***") or die (mysql_error()); $dbs = @mysql_list_dbs($connection) or die (mysql_error()); $db_list = "<ul>"; $db_num = 0; while ($db_num < mysql_num_rows($dbs)) { $db_names[$db_num] = mysql_tablename($dbs, $db_num); $db_list .= "<li>$db_names[$db_num]"; $tables = @mysql_list_tables($db_names['$db_num']) or die (mysql_error()); $table_list = "<ul>"; $table_num = 0; while (table_num < mysql_num_rows($tables)) { $table_names[$table_num] = mysql_tablename($tables, $table_num); $table_list .= "<li>$table_names[$table_num]"; $table_num++; } $table_list .= "</ul>"; $db_list .= "$table_list"; $db_num++; } $db_list .= "</ul>"; ?> <html> <head> <title>MySQL Tables</title> </head> <body> <P><strong>Databases and tables on localhost</strong>;</p> <? echo "$db_list"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757629 Share on other sites More sharing options...
Mchl Posted February 8, 2009 Share Posted February 8, 2009 Why don't you check out the example in php manual? http://www.php.net/mysql_list_dbs Quote Link to comment https://forums.phpfreaks.com/topic/144356-solved-why-am-i-receiving-this-very-unclear-error/#findComment-757695 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.