Jump to content

PHP form for creating table in MySQL


buchberg

Recommended Posts

Windows 7, Apache 2.2.21 / PHP 5.3.5.  What does the below error mean?  I am new and fighting through this particular piece of code. 

 

Thank you in advance for your help. 

 

 

Warning: mysql() expects parameter 3 to be resource, string given in C:\website\do_createtable.php on line 3

 

<?

$db_name="booster";

$connection=mysql("localhost", "USERNAME", "PASSWORD") 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>

 

Link to comment
https://forums.phpfreaks.com/topic/257228-php-form-for-creating-table-in-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.