Jump to content

HTML Form Processing PHP help


dhendler

Recommended Posts

I'm having trouble processing an HTML form. I can't get the data to post into the mysql database and I keep getting a Parse ErrorParse Error in "file" on line 18.

 

Here's the code for the HTML form:

<form action="process.php" method="post">
        <table width="410" border="0" cellpadding="2">
          <tr>
            <td nowrap="nowrap"><div align="right">Trakker # </div></td>
            <td nowrap="nowrap"><INPUT TYPE= text NAME="idnum" ID="idnum" SIZE=30 MAXLENGTH=100 />            </td>
          </tr>
          <tr>
            <td nowrap="nowrap"><div align="right">Found By : </div></td>
            <td nowrap="nowrap"><INPUT TYPE=TEXT NAME="found_by" ID="found_by" SIZE=30 MAXLENGTH=100  /></td>
          </tr>
          <tr>
            <td nowrap="nowrap"><div align="right">Date Found : </div></td>
            <td nowrap="nowrap"><?php DateDropDown($size=90,$default="DropDate"); ?></td>
          </tr>
          <tr>
            <td nowrap="nowrap"><div align="right">City / Town : </div></td>
            <td nowrap="nowrap"><INPUT TYPE=TEXT NAME="city" ID="city" SIZE=30 MAXLENGTH=100 /></td>
          </tr>
          <tr>
            <td nowrap="nowrap"><div align="right">State / Province : </div></td>
            <td nowrap="nowrap"><INPUT TYPE=TEXT NAME="state" ID="state" SIZE=30 MAXLENGTH=100 />            </td>
          </tr>
          <tr>
            <td><div align="right">Country : </div></td>
            <td><select name="country" ID='country'>
              <option selected="selected" value="">(Select a Country) </option>
              <option value="USA">United States of America </option>
                   //bunch of countries listed
              <option value="UNK">Not Listed___________________________ </option>
            </select>            </td>
          </tr>
          <tr>
            <td nowrap="nowrap"> </td>
            <td nowrap="nowrap"><div align="left">
              <input type="submit" name="submit" value="submit" />
            </div></td>
          </tr>
        </table>
        </form>

 

The date field is a javascript drop down thing.

 

Here's the process.php code:

<?php
if(isset($_POST['submit']))
{
include 'config_dino.php';//connection info

mysql_connect($server, $db_user, $db_pass);
@mysql_select_db($database) or die( "Unable to select database");

/*Posted information from HTML (dinos.php) form*/
$idnum=$_POST['idnum'];
$found_by=$_POST['found_by'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];

/*Insert posted information into bugz database - Table Dino*/
mysql_query("INSERT INTO 'dino' ('idnum', 'found_by', $city', 'state', 'country') VALUES ('$idnum', '$found_by', '$city', '$state', '$country')")
}
?>

 

I also want to redirect the user to "trakked.html" after the form has been processed, but I have no idea how.

 

I'm obviously very new to PHP, thank you in advance for your help.

 

 

Link to comment
Share on other sites

Change:

 

mysql_query("INSERT INTO 'dino' ('idnum', 'found_by', $city', 'state', 'country') VALUES ('$idnum', '$found_by', '$city', '$state', '$country')")

 

To:

 

mysql_query("INSERT INTO dino (idnum, found_by, city, state, country) VALUES ('$idnum', '$found_by', '$city', '$state', '$country')");

 

Basically you don't want the quotes around the table columns only the inserted variables.

 

 

To redirect the page you can use:

 

header("Location: trakked.html");

 

 

Link to comment
Share on other sites

Right on!  I'm not getting that Parse Error anymore, it was the semi-colon that fixed it :)

 

The data is being passed onto the database now too!  You guys/gals rock!

 

I am also having trouble trying to figure out how to reference the drop down date results with PHP since it's a custom function.

 

Here's the complete form with the function.

 

<script language="JavaScript" type="text/javascript">
<?php function DateDropDown($size=90,$default="DropDate") {
   // $size = the number of days to display in the drop down
   // $default = Todays date in m:d:Y format (SEE DATE COMMAND ON WWW.PHP.NET)
   // $skip = if set then the program will skip Sundays and Saturdays
   $skip=1;
   echo "<select name=dropdate STYLE=\"font-family: arial;\">\n";
   for ($i = 0; $i <= $size; $i++) {
      $theday = mktime (0,0,0,date("m") ,date("d")+$i ,date("Y"));
      $option=date("D M j, Y",$theday);
      $value=date("m:d:Y",$theday);
      $dow=date("D",$theday);
      if ($dow=="Sun") {
         echo "<option disabled> </option>\n";
      }
      if ($value == $default) {
         $selected="SELECTED";
      } else {
         $selected="";
      }
      if (($dow!="Sun" and $dow!="Sat") or !$skip) {
         echo "<option value=\"$value\" $selected>$option</option>\n";
      }
   }
   
   echo "</select>\n";
}
?>
<form action="process.php" method="post">
        <table width="410" border="0" cellpadding="2">
          <tr>
            <td nowrap="nowrap"><div align="right">Trakker # </div></td>
            <td nowrap="nowrap"><INPUT TYPE= text NAME="idnum" ID="idnum" SIZE=30 MAXLENGTH=100 />            </td>
          </tr>
          <tr>
            <td nowrap="nowrap"><div align="right">Found By : </div></td>
            <td nowrap="nowrap"><INPUT TYPE=TEXT NAME="found_by" ID="found_by" SIZE=30 MAXLENGTH=100  /></td>
          </tr>
          <tr>
            <td nowrap="nowrap"><div align="right">Date Found : </div></td>
            <td nowrap="nowrap"><?php DateDropDown($size=90,$default="DropDate"); ?></td>
          </tr>
          <tr>
            <td nowrap="nowrap"><div align="right">City / Town : </div></td>
            <td nowrap="nowrap"><INPUT TYPE=TEXT NAME="city" ID="city" SIZE=30 MAXLENGTH=100 /></td>
          </tr>
          <tr>
            <td nowrap="nowrap"><div align="right">State / Province : </div></td>
            <td nowrap="nowrap"><INPUT TYPE=TEXT NAME="state" ID="state" SIZE=30 MAXLENGTH=100 />            </td>
          </tr>
          <tr>
            <td><div align="right">Country : </div></td>
            <td><select name="country" ID='country'>
              <option selected="selected" value="">(Select a Country) </option>
              <option value="USA">United States of America </option>
                   //bunch of countries listed
              <option value="UNK">Not Listed___________________________ </option>
            </select>            </td>
          </tr>
          <tr>
            <td nowrap="nowrap"> </td>
            <td nowrap="nowrap"><div align="left">
              <input type="submit" name="submit" value="submit" />
            </div></td>
          </tr>
        </table>
        </form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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