Jump to content

[SOLVED] Why am i receiving this very unclear error?


28rain

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

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.