Jump to content

Submitting a form to the same page doesn't work


PHPJack77

Recommended Posts

It seems like whenever I submit a form to the same page using the code...$_SERVER['PHP_SELF']as the form action, the page just clears out the form data and the page will never fully load (the status bar says: "(1 item remaining) opening page..."). Here is an example of code that I have been trying to get working, but can not due to this very reason.Any idea as to why this is not working?

<?php  $self = $_SERVER['PHP_SELF'];  $fields = $POST['fields'];  $db =     $POST['db'];  $name =   $POST['name'];  $table =  $POST['table'];  $type =   $POST['type'];  $size =   $POST['size'];  if( !$fields and !$db )  {     $form ="<form action=\"$self\" method=\"post\">";     $form.="How many fields are needed in the new table?";     $form.="<br /><input type=\"text\" name=\"fields\">";     $form.="<input type=\"submit\" value=\"submit\">";     echo( $form );  }  else if( !$db )  {     $form ="<form action=\"$self\" method=\"post\">";     $form.="Database: <input type=\"text\" name=\"db\"><br />";     $form.="Table Name: <input type=\"text\" name=\"table\"><br />";     for ( $i = 0; $i < $fields; $i++ )     {        $form.="Column Name: <input type=\"text\" name=\"name[$i]\">";        $form.="Type: <select name=\"type[$i]\">";        $form.="<option value=\"char\">char</option>";        $form.="<option value=\"int\">int</option>";        #Add Other Options HERE Later        $form.="</select> ";        $form.="Size:<input type=\"text\" name=\"size[$i]\">";     }     $form.="<input type=\"submit\" value=\"Submit\">";     $form.="</form>";     echo( $form );  }  else  {     #Make the connection to mysql     $conn = @mysql_connect ("sample@sampledomain.com", "SampleUsername", "SamplePassword")       or die("Err:conn");     #Select the specified database     $rs = "create table $table (";     for ($i = 0; $i < count($name); $i++)     {         #Field name and data type         $sql .= "$name[$i] $type[$i]";         #Allow size specification for char and varchar types         if ( ($type[$i] == "char") or ($type[$i] == "varchar") )         {            #If the size has been specified add to the query            if ($size[$i] != "")            {               $sql.= "($size[$i])";            }         }         #If this is not the final field add a comma         if ( ($i+1) != count($name) )         {            $sql.=",";         }     } $sql .= ")";     #Display SQL Query     echo("SQL Command: $sql <hr>");     #Execute the query - attempt to create the table     $result = mysql_query($sql,$conn)       or die("Err:Query");     #Confirm if successful     if ($result)     {        echo("Result: Table \"$table\" has been created");     }  }?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...