How to link a drop down menu to a mysql table

Hello; I’m so glad to find this forum.

A friend helped me create a form (please see it here: http://nigerianblogawards.com/testing2014/register.php). I added a question to the form (“If selected, will you be a panelist?”) and a drop-down menu for the answer to be selected from.

I also added a column called panel to an existing MySQL table that will be storing the other data from the form (the panel column is meant to store the results from this drop down menu).

However, because I don’t understand php, I don’t know how to make sure that the results of the drop down menu are stored properly. I was sent this http://stackoverflow.com/questions/17139501/using-post-to-get-select-option-value-from-html but can’t figure out what parts to insert, how to insert it, and where in the register.php document to insert it.

Thank you for your time.

Hello,

Please find the php code from my friend for http://nigerianblogawards.com/testing2014/register.php below.

I created a column on my MySQL table to capture the data from lines 157-161 below, but I don’t know how to link the two. I know it has something to do with the information found here (http://stackoverflow.com/questions/17139501/using-post-to-get-select-option-value-from-html/17139540#17139540), but due to my lack of php knowledge I’m stuck.

Thank you for your time and help!

[php]

<?php $page_title = 'NBA - Nominate'; include('./includes/header2014jums.html'); if(isset($_POST['submitted'])){//do error handling and submit data //db connect include('../../mysql_connect2014.php'); function escape_data($data){ global $dbc; if(ini_get('magic_quotes_gpc')){ $data = stripslashes($data); return mysql_real_escape_string(trim($data), $dbc); } } //check email if(eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9_\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))){ $email = $_POST['email']; }else{ $email = FALSE; echo '
Please enter a valid email address!
'; } $cat1 = mysql_real_escape_string($_POST['cat1']); $cat2 = mysql_real_escape_string($_POST['cat2']); $cat3 = mysql_real_escape_string($_POST['cat3']); $cat4 = mysql_real_escape_string($_POST['cat4']); $cat5 = mysql_real_escape_string($_POST['cat5']); $cat6 = mysql_real_escape_string($_POST['cat6']); $cat7 = mysql_real_escape_string($_POST['cat7']); $cat8 = mysql_real_escape_string($_POST['cat8']); $cat9 = mysql_real_escape_string($_POST['cat9']); $cat10 = mysql_real_escape_string($_POST['cat10']); $cat11 = mysql_real_escape_string($_POST['cat11']); $cat12 = mysql_real_escape_string($_POST['cat12']); $cat13 = mysql_real_escape_string($_POST['cat13']); $cat14 = mysql_real_escape_string($_POST['cat14']); $cat15 = mysql_real_escape_string($_POST['cat15']); $cat16 = mysql_real_escape_string($_POST['cat16']); $cat17 = mysql_real_escape_string($_POST['cat17']); $cat18 = mysql_real_escape_string($_POST['cat18']); $cat19 = mysql_real_escape_string($_POST['cat19']); $cat20 = mysql_real_escape_string($_POST['cat20']); $cat21 = mysql_real_escape_string($_POST['cat21']); $cat22 = mysql_real_escape_string($_POST['cat22']); $cat23 = mysql_real_escape_string($_POST['cat23']); $cat24 = mysql_real_escape_string($_POST['cat24']); $cat25 = mysql_real_escape_string($_POST['cat25']); $cat26 = mysql_real_escape_string($_POST['cat26']); $cat27 = mysql_real_escape_string($_POST['cat27']); $cat28 = mysql_real_escape_string($_POST['cat28']); $cat29 = mysql_real_escape_string($_POST['cat29']); $cat30 = mysql_real_escape_string($_POST['cat30']); if($email){ //make sure they aren't using the email again for another nomination. $query = "SELECT id FROM users WHERE email='$email'"; $result = mysql_query($query) or trigger_error("Query: $query\n
MySQL Error: " . mysql_error()); if (mysql_num_rows($result) == 0){ //Email is available //create activation code. $a = md5(uniqid(rand(), true)); //Add the user. $query = "INSERT INTO users (name, email, activate, voted) VALUES ('$name', '$email', '$a', 'N')"; $result = mysql_query($query) or trigger_error("Query: $query\n
MySQL Error: " . mysql_error()); //if it ran ok if(mysql_affected_rows() == 1){ $userid = mysql_insert_id(); $query = "INSERT INTO nominations (category1, userid, category2, category3, category4, category5, category6, category7, category8, category9, category10, category11, category12, category13, category14, category15, category16, category17, category18, category19, category20, category21, category22, category23, category24, category25, category26, category27, category28, category29, category30) VALUES ('$cat1', '$userid', '$cat2', '$cat3', '$cat4', '$cat5', '$cat6', '$cat7', '$cat8', '$cat9', '$cat10', '$cat11', '$cat12', '$cat13', '$cat14', '$cat15', '$cat16', '$cat17', '$cat18', '$cat19', '$cat20', '$cat21', '$cat22', '$cat23', '$cat24', '$cat25', '$cat26', '$cat27', '$cat28', '$cat29', '$cat30')"; $result = mysql_query($query) or trigger_error("Query: $query\n
MySQL Error: " . mysql_error()); if(mysql_affected_rows() == 1){ $from = "[email protected]"; $headers = "From:" . $from; $body = "Please click the link below so your submission is counted: \n\n"; $body .= "http://www.nigerianblogawards.com/testing2014/activate.php?x=$userid&y=$a \n\n"; $body .= "Thank you for participating in the 2014 Nigerian Blog Awards! \n"; $body .= "Back to the awards website: http://nigerianblogawards.com. \n"; mail($_POST['email'], 'Nigerian Blog Awards - Your nominations', $body, $headers); echo '

Thank you for submitting your nomination! A confirmation email has been sent to you. Please click the link in the email in order to have your submission counted.

'; include('./includes/footerjums.html'); exit(); } else{ echo "
System error
"; } } else{ echo "
System error
"; } }else{//email already used in the system echo "
A user with that email address has already submitted a nomination form.
"; } } else { echo "
Please try again
"; } mysql_close(); }//end of main submit conditional. ?>
<div id="content-sidebar-wrap">

<div id="errorContainer" style="color:red; margin-top:20px; font-weight:bold;"></div>

<span style="color:#b900b5; font-size:18px; font-family:'Droid serif'; serif">2014 Nomination form</span>
<br />
<div class="introText">
<div>
<strong>We are not responsible for nominations that are not counted due to failure to read the information below</strong>:<br /><br /> 
</div>
<div style="margin-left:20px">
  1. Only one blog can be nominated per category.
  2. You don’t have to nominate a blog in each category.
  3. Enter the blog address of the blog you are nominating using the format blogaddress.com (omit http:// and www).
  4. Provide a valid email address for yourself so that your nomination will be counted.
  5. After submitting your nomination form, check for an email from [email protected] and follow the instructions in the email to ensure your nominations are counted. If you don’t follow the instructions in the email your vote will not be counted.
  6. Blogs nominated in categories they do not fit will not be counted—read the description of each category before nominating a blog.
  7. Do not nominate the same blog for more than three categories.
  8. If you make errors on your nomination form, email [email protected].

If you're ready to fill out the nomination form, please continue below.

VIEW LIST OF NIGERIAN BLOGS

<br />
</table>	
<br />
<div><span style="font-family:'Open Sans', sans-serif; background:#F3FE15; color:#000000; position:relative; left:545px">Please OMIT <strong>http://</strong> and <strong>www</strong>!!</span></div>
</div>
<?php
//db connect
include('../../mysql_connect2014.php');

$query = "SELECT * FROM awards_categories_2014 WHERE nominatable=1";

//$result = @mysql_query($query);//Run it
$result = mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());

if($result){
	echo'<table>';


	while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
		echo'<tr><td style="width:600px; padding-bottom:20px;font-weight:bold; color:#008546;">'. $row['id'] .". " . $row['prefix'] . " " . $row['name'] . " " . $row['suffix'] . '<br /><span class="description">' . $row['description'] . '</span></td><td td style="width:340px; padding-bottom:20px; text-align:right"><input type="text" size="40" class="catClass" name="cat' . $row['id'] .'" value=""/> </td></tr> ';
	}
	echo'</table>';

	mysql_free_result($result);		
} else {
	echo'<div>error</div>';
}
//mysql_close();

?>
<input type="submit" name="submit" value="Submit" onclick="return checkValidation();"/>
<input type="hidden" name="submitted" value="TRUE" />
</form>



</div>



</div>

	<script type="text/javascript">
function checkValidation(){
	var errorMessage;
	var errorContainer = document.getElementById('errorContainer');
	errorContainer.innerHTML ="";
			
	var $inputs = $('input.catClass');
	var inptlength = $inputs.length;             
	var catCount= 0;
	for(k=0;k< inptlength;k++)
	{	
		if($($inputs[k]).val()){
			catCount++;
			break;
		}
	}
	
	if (catCount == 0){
		errorMessage = "Please enter a blog address in at least one category";
		errorContainer.innerHTML = errorMessage;
		errorContainer.style.display = "block";
		$('html,body').scrollTop(0);
		return false;
	}else{
		return true;
	}			

}

<?php
include(’./includes/footerjums.html’);
?>
[/php]

Name
Email (required)
If selected, will you be a panelist? (required) Select... Yes No

You have obsolete Mysql code. Dont use it.

I don’t know where to start when it comes to rectifying the errors. Any tips or pointers would be helpful.

I’m a complete newbie to php/mysql.

Thank you.

Do a google search for PDO tutorials and start there.

You know, [member=46186]Kevin Rubio[/member] has given you the best advice you probably never expected to receive.
Take his advice, come back with any problems you need clarifying. In 3 months you’ll thank him for it.

Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service