Here is my list of issues that I just cannot figure out for the life of me (Could be a result of staring at it for too long.):

  1. HTML form is coming up fine, no problems there, however it is giving my the undefined variable message(line 94: $rs is undefined when I first pull up the form, not after I try to submit something.

  2. If i stupidly try to just ignore the message, fill out the form, and click submit it does not give me an "it worked" or "it didn't work" message that I on lines 94-99.

  3. Also, when the page is first pulled up, it is saying all of my form variables are undefined as well, which is true becuase POST has nothing in it to make that definition, but I thought I had written this is a way that it should pull the form first, and then do all the variable shananigans.

Please help

<?php
include("connect.php");
if (!isset($_POST['submit'])){
?>
<html>
<title>Robotabase Create Table Page</title>
<h4>Please fill in the following information</h4>

<body>

<form method="post" action="Create_Table.php">
Table name: <input type="Text" name = "TableName" /><br />
<p />
<fieldset>
<legend>Table Elements</legend>
<b>Field 1:</b> <br />
Column Name:</b> <input type="text" name="field1" />
Data Type: <input type= "text" name="DataType1" />
Other: <select name="other1">
<option value="NULL">NULL</option>
<option value="NOT NULL">NOT NULL</option>
</select>
<br />
<b>Field 2:</b> <br />
Column Name: <input type="text" name="field2" />
Data Type: <input type= "text" name="DataType2" />
Other: <select name="other2">
<option value="NULL">NULL</option>
<option value="NOT NULL">NOT NULL</option>
</select>
<br />
<b>Field 3:</b> <br />
Column Name: <input type="text" name="field3" />
Data Type: <input type= "text" name="DataType3" />
Other: <select name="other3">
<option value="NULL">NULL</option>
<option value="NOT NULL">NOT NULL</option>
</select>
<br />
<b>Field 4:</b> <br />
Column Name: <input type="text" name="field4" />
Data Type: <input type= "text" name="DataType4" />
Other: <select name="other4">
<option value="NULL">NULL</option>
<option value="NOT NULL">NOT NULL</option>
</select>
<br />
<b>Field 5:</b> <br />
Column Name: <input type="text" name="field5" />
Data Type: <input type= "text" name="DataType5" />
Other: <select name="other5">
<option value="NULL">NULL</option>
<option value="NOT NULL">NOT NULL</option>
</select>
</fieldset>
<p/>
<input type="submit" name="submit" value="Create" />
</form>
</body>
</html>
<?php
}else{
$TableName = $_POST['TableName'];

$field1 = $_POST['field1'];
$DataType1 = $_POST['DataType1'];
$other1 = $_POST['other1'];

$field2 = $_POST['field2'];
$DataType2 = $_POST['DataType2'];
$other2 = $_POST['other2'];

$field3 = $_POST['field3'];
$DataType3 = $_POST['DataType3'];
$other3 = $_POST['other3'];

$field4 = $_POST['field4'];
$DataType4 = $_POST['DataType4'];
$other4 = $_POST['other4'];

$field5 = $_POST['field5'];
$DataType5 = $_POST['DataType5'];
$other5 = $_POST['other5'];

$sql = "CREATE TABLE '$TableName' ("
      . "'$field1' '$DataType1' '$other1'" 
      . ", '$field2' '$DataType2' '$other2'"
      . ", '$field3' '$DataType3' '$other3'"  //use arrays instead?
      . ", '$field4' '$DataType4' '$other4'" 
      . ", '$field5' '$DataType5' '$other5'"
      . ")";
$rs = odbc_exec($conn, $sql);
}
if (!$rs) {
  print("Table creation failed with error:\n");
  print(odbc_error($conn).": ".odbc_errormsg($conn)."\n");
}
else {
  print("Table '$TableName' created.\n");
};
?>

    I just noticed I was calling the wrong file in the action part of the form. Issues still apply though.. Help still needed...

      which one is line 94?
      I suspect your query fails.

      try this:
      replace this

      $rs = odbc_exec($conn, $sql);
      }
      if (!$rs) {
        print("Table creation failed with error:\n");
        print(odbc_error($conn).": ".odbc_errormsg($conn)."\n");
      }
      else {
        print("Table '$TableName' created.\n");
      };
      

      with

      $rs = odbc_exec($conn, $sql) or raise_error(odbc_error($conn).":".odbc_errormsg($conn)."\n",E_USER_ERROR);
      print("Table '$TableName' created.\n");
      
        Write a Reply...