Jump to content

Recommended Posts

Hey,

 

Im looking for some help in storing a value from a dynamic drop down box into a table.

 

Here is my dynamic drop down box which works:

<?

require_once ('../mysql_connect.php');

  $sql="SELECT * FROM club";

  $result=mysql_query($sql);

  $options="";

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

$club_id=$row["clubn"];

    $clubName=$row["clubn"];

    $options.="<OPTION VALUE=\"$club_id\">".$clubName.'</option>';

}

?>

<select name="clubdrop">

<option value=0>Select Your Club

<?=$options?>

</select>

 

I am already storing some values from other parts of the form but I am unsure on how to store the $club_id of the club selected into the table at the same time?

 

Cheers

Just read what I have written and its a bit misleading so ill try again.

 

I want to store the $club_id value from the option selected into a table in the database.

 

Here is my dynamic drop down box which works:

<?

require_once ('../mysql_connect.php');

  $sql="SELECT * FROM club";

  $result=mysql_query($sql);

  $options="";

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

  $club_id=$row["club_id"];

    $clubName=$row["clubn"];

    $options.="<OPTION VALUE=\"$club_id\">".$clubName.'</option>';

  }

  ?>

<select name="clubdrop">

<option value=0>Select Your Club

<?=$options?>

</select>

 

Cheers

put the club id in a session then add to the database then try that.....

 

<?php session_start(); <<< dont forget

 

$SESSION['club_id']="$row['club_id']";

 

?>

 

Also i noticed you use short php tags be carefull there all gon in php 6.

Hey thanks for the reply, but im still very new to php so im sorry but I dont really understand how to do that.

 

I know that I have already started a session however in another page called header.html which is included on the page.

 

I have added some more code so you maybe able to see where I am going wrong.

 

Cheers

 

$query = "INSERT INTO users (username, member_type, first_name, last_name, email, password, registration_date) VALUES ('$u', 'Member', '$fn', '$ln', '$e', PASSWORD('$p'), NOW() )";		
$result = @mysql_query ($query);

if ($result) {
echo '<h3>Thank you for registering!</h3>';	
include ('includes/footer.html'); 
exit();				

mysql_close();

} else { 
echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>'; 
}	

} else {			
echo '<p><font color="red" size="+1">That username is already taken.</font></p>'; 
}

mysql_close();

} else { 
echo '<p><font color="red" size="+1">Please try again.</font></p>';		
}
}
?>

<h1>Join Your Club</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<table border="0" align="center">
<tr>	
<td>First Name:</td>
<td><input type="text" name="first_name" size="30" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></td>
</tr>	
<tr>
<td>Email Address:</td>
<td><input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></td>
</tr>
<tr>
<td>Select your club:</td>
<td>
<?php 
require_once ('../mysql_connect.php');
  $sql="SELECT * FROM club";
  $result=mysql_query($sql); 
  $options="";
  while ($row=mysql_fetch_array($result)) {
$club_id=$row["club_id"];
    $clubName=$row["clubn"];
    $options.="<OPTION VALUE=\"$club_id\">".$clubName.'</option>';
}
?>
<select name="clubdrop">
<option value=0>Select Your Club
<?=$options?>
</select>

Try something like this:

<select name="clubdrop"><option value="">Pick</option>
<?php 
$sql = "SELECT * FROM club";
  	$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
	$club_id = $row["club_id"];
	$clubName = $row["clubn"];
	$club_id == $YOUR_OTHER_CLUB_ID ? $sel = 'SELECTED' : $sel = '';
?>
<option value="<?php echo $club_id ?>" <?php echo $sel ?>><?php echo $clubName ?></option>
<?php 
} ?>
</select>

This makes up my full query:

 

$query = "INSERT INTO users (username, club_id, member_type, first_name, last_name, email, password, registration_date) VALUES ('$u', $_POST['clubdrop'], 'Member', '$fn', '$ln', '$e', PASSWORD('$p'), NOW() )";

$result = @mysql_query ($query);

 

However by adding in the $_POST['clubdrop'] section has caused an error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\easyphp1-8\www\html\registermember.php on line 63

 

Appreciate your help

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.