Ell20 Posted October 13, 2007 Share Posted October 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/ Share on other sites More sharing options...
Ell20 Posted October 13, 2007 Author Share Posted October 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368678 Share on other sites More sharing options...
redarrow Posted October 13, 2007 Share Posted October 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368679 Share on other sites More sharing options...
Ell20 Posted October 13, 2007 Author Share Posted October 13, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368683 Share on other sites More sharing options...
cmgmyr Posted October 13, 2007 Share Posted October 13, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368692 Share on other sites More sharing options...
Ell20 Posted October 13, 2007 Author Share Posted October 13, 2007 Thanks cmgmyr, your code works, however its the getting the club_id value to go into the database that I am having difficulties with? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368694 Share on other sites More sharing options...
cmgmyr Posted October 13, 2007 Share Posted October 13, 2007 INSERT INTO `table` (club_id) VALUES ($_POST['clubdrop']) does that work? Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368695 Share on other sites More sharing options...
Ell20 Posted October 13, 2007 Author Share Posted October 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368699 Share on other sites More sharing options...
cmgmyr Posted October 13, 2007 Share Posted October 13, 2007 <?php $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() )"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368702 Share on other sites More sharing options...
Ell20 Posted October 13, 2007 Author Share Posted October 13, 2007 Thank you very much, seems to be working perfectly!! Quote Link to comment https://forums.phpfreaks.com/topic/73100-solved-storing-from-dynamic-drop-down-box/#findComment-368703 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.