$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
$name_of_field="id_student";
function field_dynamic($field_num,$field_name){
for($i=1;$i<=$field_num;$i++){
if($i!=$field_num){
$field[$i]="".$field_name."_".$i." VARCHAR(5) NOT NULL,"."";
}else{
$field[$i]="".$field_name."_".$i." VARCHAR(5) NOT NULL";
}
}
return $field;
}
$num=13;
$sql_mathematic = "CREATE TABLE mathematic(".
field_dynamic($num,$name_of_field).")";
mysql_select_db("adrian");
$retval_mathematic = mysql_query( $sql_mathematic, $conn );
if(! $retval_mathematic )
{
die('Could not create table: ' . mysql_error());
}
echo "Table created successfully\n";
its not working:
Connected successfully
Could not create table: 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
Please help me.