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">
- Only one blog can be nominated per category.
- You don’t have to nominate a blog in each category.
- Enter the blog address of the blog you are nominating using the format blogaddress.com (omit http:// and www).
- Provide a valid email address for yourself so that your nomination will be counted.
- 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.
- Blogs nominated in categories they do not fit will not be counted—read the description of each category before nominating a blog.
- Do not nominate the same blog for more than three categories.
- 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
Name
|
Email (required)
|
If selected, will you be a panelist? (required)
Select...
Yes
No
|
<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]