what is wrong with my php file?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

nataliafoster26
New php-forum User
New php-forum User
Posts: 12
Joined: Fri Sep 21, 2012 9:45 pm

what is wrong with my php file?

Postby nataliafoster26 » Sun Dec 02, 2012 11:58 am

<html>
<head>
<title>create your database table</title>
</head>
<body>
<h1>schedule your Appointments<h1>
<form method="POST" ACTION="showfielddef.php">
<p> <strong>your name:</strong><br>
<INPUT TYPE="text" NAME="table_name" SIZE=30></p>
<p><strong>number of people:</strong><br>
<INPUT TYPE="text" NAME=num_fields" SIZE=5></p>
<p> <INPUT TYPE="submit" Name="submit" VALUE="go to field names"></p>
</form>
</body>
</html>

//here is my html and my php why does it not go in order, that way it suppose to look

Code: Select all

<?php
  //Validate important input
  if((!$_POST[table_name]) ||  (!$_POST[num_fields]))
   {
    header("Location: createtable.html");
    exit;
   }
   // begin creating form for display
   
   $form_block="<form method=\"post\" action=\"createtable.php\">
     <input type=\"hidden\" name=\"table_name\" value=\"$_POST[table_name]\">
     <table border='1' cellspacing=5 cellpadding=5>
     <tr>
        <th>Field Name</th> <th> Field Type</th> <th> Field Length</th>
        <th>Primary Key?</th><th>Auto_increment</th>
     </tr>";
     //count from 0 until you reach the number of fields
     for($i=0; $i < $_POST[num_fields]; $i++)
     {
      //add to the form one row for each field
      $form_block .="
       <tr>
         <td align=center>
         <input type=\"text\" name=\"field_name[]\" size=\"30\"></td>
         <td align=center>
         <select name=\"field_type[]\">
            <option value=\"char\">char</option>
            <option value=\"date\">date</option>
            <option value=\"float\">float</option>
            <option value=\"int\">int</option>
            <option value=\"text\">text</option>
            <option value=\"varchar\">varchar</option>
          </select>
         </td>
        <td align=center>
        <input type=\"text\" name=\"field_length[]\" size=\"5\"></td>
        <td align=center>
        <input type=\"checkbox\" name=\"primary[]\" value=\"Y\"></td>
        <td align=center>
        <input type=\"checkbox\" name=\"auto_increment[]\" value=\"Y\"></td>
      </tr>";
     }
//finish up the form
   $form_block .= "
   <tr>
    <td align=center colspan=3><input type=\"submit\" value=\" Create Table\"></td>
   </tr>
   </table>
  </form>";
 ?>
 
  <html>
  <head> <title> Create A Database Table Step 2 </title> </head>
    <style  type="text/css">
      body {margin: 10px auto; width 800px; text-align: center;}
      h1,th {margin: 10px auto; background-color: #00cccc; width: 800px; text-align: center;}
</style>
  <body>
     <h1> Define fields for <?php echo "$_POST[table_name]"; ?></h1>
    <?php  echo "$form_block";  ?>
  </body>
 </html>

User avatar
webinfopedia
New php-forum User
New php-forum User
Posts: 84
Joined: Sat May 21, 2011 10:26 pm
Contact:

Re: what is wrong with my php file?

Postby webinfopedia » Fri Dec 14, 2012 3:27 am

Hi,

Use the PHP and HTML syntax properly..I mean you need to mention the name and id tag to a input field. its missing in your case. While retrieving the value in PHP, the syntax is $_POST['field'] the single quotes is missing. Don't use uppercase in HTML, its not error, but it's not proper method. :D

for more visit: http://www.webinfopedia.com/ Web Designing and Development Free Blog.

Here is your code.

Code: Select all

<html>
<head>
<title>create your database table</title>
</head>
<body>
<h1>schedule your Appointments<h1>
<form method="POST" ACTION="test.php">
<p> <strong>your name:</strong><br>
<INPUT TYPE="text" NAME="table_name" id="table_name" SIZE=30></p>
<p><strong>number of people:</strong><br>
<INPUT TYPE="text" NAME="num_fields" id="num_fields" SIZE=5></p>
<p> <INPUT TYPE="submit" Name="submit" VALUE="go to field names"></p>
</form>
</body>
</html>


and the PHP code,

Code: Select all

    <?php
      //Validate important input
      if((!$_POST['table_name']) ||  (!$_POST['num_fields']))
       {
        header("Location: createtable.html");
        exit;
       }
       // begin creating form for display
       
       $form_block="<form method=\"post\" action=\"createtable.php\">
         <input type=\"hidden\" name=\"table_name\" value=\"$_POST[table_name]\">
         <table border='1' cellspacing=5 cellpadding=5>
         <tr>
            <th>Field Name</th> <th> Field Type</th> <th> Field Length</th>
            <th>Primary Key?</th><th>Auto_increment</th>
         </tr>";
         //count from 0 until you reach the number of fields
         for($i=0; $i < $_POST['num_fields']; $i++)
         {
          //add to the form one row for each field
          $form_block .="
           <tr>
             <td align=center>
             <input type=\"text\" name=\"field_name[]\" size=\"30\"></td>
             <td align=center>
             <select name=\"field_type[]\">
                <option value=\"char\">char</option>
                <option value=\"date\">date</option>
                <option value=\"float\">float</option>
                <option value=\"int\">int</option>
                <option value=\"text\">text</option>
                <option value=\"varchar\">varchar</option>
              </select>
             </td>
            <td align=center>
            <input type=\"text\" name=\"field_length[]\" size=\"5\"></td>
            <td align=center>
            <input type=\"checkbox\" name=\"primary[]\" value=\"Y\"></td>
            <td align=center>
            <input type=\"checkbox\" name=\"auto_increment[]\" value=\"Y\"></td>
          </tr>";
         }
    //finish up the form
       $form_block .= "
       <tr>
        <td align=center colspan=3><input type=\"submit\" value=\" Create Table\"></td>
       </tr>
       </table>
      </form>";
     ?>
     
      <html>
      <head> <title> Create A Database Table Step 2 </title> </head>
        <style  type="text/css">
          body {margin: 10px auto; width 800px; text-align: center;}
          h1,th {margin: 10px auto; background-color: #00cccc; width: 800px; text-align: center;}
    </style>
      <body>
         <h1> Define fields for <?php echo "$_POST[table_name]"; ?></h1>
        <?php  echo "$form_block";  ?>
      </body>
     </html>


Hope that this will help you.. Don't forget to visit http://www.webinfopedia.com/

Thank you
webinfopedia
Attachments
screenshot.JPG
Here is your script running....
screenshot.JPG (192.87 KiB) Viewed 1133 times


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot], landi and 2 guests

cron