Ok, it's time for the n00b question:
I wrote this script which is supposed to create a table named by the user. This however gives some nasty errors and if the $_POST['addressbook'] is replaced with a non-variable (like just addressbook) it just loads the page again when the form is submitted.
PHP Code:
<? if (!$submit) { ?> <table cellspacing='5' cellpadding='5'> <form action='<? echo $PHP_SELF; ?>' method='POST'> <tr> <td valign='top'><b><font size="-1">Name of the Addressbook:</font></b></td> <td><input size="50" maxlength='250' type='text' name='addressbook'></td> </tr> <tr> <td colspan=2><input type='Submit' name='submit' value='Add'></td> </tr> </form> </table> <? } else { include("conf.php"); $errorList = array(); $count = 0; if (sizeof($errorList) == 0) { $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); $query = "CREATE TABLE $_POST['addressbook'] (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); echo "<font size=-1>Update was successful. <a href=index.php>Return back to the menu.</a>.</font>"; mysql_close($connection); } else { echo "<font size=-1>Following errors were noticed: <br>"; echo "<ul>"; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo "</ul></font>"; } } ?>
As usual, the answer is propably an easy one, but just something I don't seem to notice...
Last edited by 0beron; 06-04-2005 at 08:24 AM..
Reason: Use [php ] tags for php code :)
|