Jump to content

Insert data from a form into table


Seapep

Recommended Posts

HI first timer here so please forgive me if this is in the wrong section.

 

Anyway, here goes.

 

I have 2 tables

 

Table 1

Levels

LevelID

LevelName

 

 

Table 2

Members

MemberID

FirstName

LastName

Birthdate

LevelID

 

 

I have a form that has the LevelID populated from table 1 with a query.  When I enter all my data and hit submit the data gets written to the members table. However, the LevelID is written as 0 for each and everyone record that I have entered. So the question is what am I missing?

 

As mentioned I am very new at this so any help would be greatly appreciated. Please see below for my code.

 

Thanks in advance

 

 

<?php

require_once 'dblogin1.php';

$db_server = mysql_connect($db_hostname, $db_username, $db_password);

if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

 

mysql_select_db($db_database)

or die("Unable to select database: " . mysql_error());

$sql = "SELECT\n"

    . "levels.LevelID,\n"

    . "levels.LevelName\n"

    . "FROM\n"

    . "levels\n";

 

$result = mysql_query($sql) or die(mysql_error());

 

$options="";

 

while($row = mysql_fetch_array($result)){

 

$LevelId=$row["LevelID"];

$LevelName=$row["LevelName"];

$options.="<OPTION VALUE=\"$LevelID\">".$LevelName.'</option>';

}

?>

<style type="text/css">

<!--

body p {

color: #F00;

}

-->

</style>

 

 

 

<table width="500" border="1" align="center" cellpadding="0" cellspacing="1" >

<tr>

<td>

<form name="form1" method="post" action="insert_ac.php">

<table width="100%" border="1" cellspacing="1" cellpadding="3">

<tr>

<td colspan="3"><div align="center">

  <p><strong>Myers Player Registration Form</strong></p>

</div></td>

</tr>

<tr>

<td>First Name</td>

<td><div align="center">:</div></td>

<td><input name="firstname" type="text" id="firstname"></td>

</tr>

<tr>

<td>Last Name</td>

<td><div align="center">:</div></td>

<td><input name="lastname" type="text" id="lastname"></td>

</tr>

<tr>

<td>Birthdate (yyyy-mm-dd)</td>

<td><div align="center">:</div></td>

<td><input name="birthdate" type="text" id="birthdate">

</td>

</tr>

 

<tr>

<td>Level</td>

<td><div align="center">:</div></td>

<td><select name="LevelID">

      <OPTION VALUE="0">Choose

  <?php echo $options?>

 

 

 

    </select></td>

</tr>

</form>

</td>

</tr>

</table>

 

Link to comment
Share on other sites

you have this....

<?php echo $options?>

it needs to be this...

<?php echo $options;?>

 

When programming use this below, it will tell you when you have something mistyped...

Just paste into the top of a page that gets called for every page like your functions page then when you are done just comment out the lines, in case you need it again you can just uncomment it.

 

ini_set('display_errors', 'on');

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

 

 

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.