hey guys ok my issue is a have a register page where you enter data into textboxes and they are in an array which is sent to a db! all that is fine, however, now iv added a dropbox where you select a school, then once a school has been selected the subjects the school offers appears with radio buttons attached to them…my problem is i dont know how to add them to the db… with the inputboxes it was easier as they were named, i had no problems adding to db then
register.php
[php]<?php
include ‘core/init.php’;
logged_in_redirect();
include ‘includes/overall/overallheader.php’;
if (empty($_POST) === false) {
$required_fields = array(‘username’, ‘password’, ‘first_name’, ‘last_name’, ‘email’);
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true){
$errors[] = ‘Fields marked with an asterisk are required’;
break 1;
}
}
if (empty($errors) === true) {
if (user_exists($_POST['username']) === true){
$errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken.';
}
if (preg_match("/\\s/", $_POST['username']) == true) {
$errors[] = 'Your username must not contain any spaces.';
}
if (strlen($_POST['password']) < 6) {
$errors[] = 'Your password must be at least 6 characters';
}
if ($_POST['password'] !== $_POST['password_again']) {
$errors[] = 'Your passwords do not match';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'A valid email address is required';
}
if (email_exists($_POST['email']) === true){
$errors[] = 'sorry the email \'' . $_POST['email'] . '\' is already in use';
}
}
}
?>
Register
<?php if (isset($_GET['success']) && empty($_GET['success'])) { //if success is added to end of url echo 'You\'ve been registered successfully!'; } else { if (empty($_POST) === false && empty($errors) === true) { //if post data is not empty and there are no errors we can register user $register_data = array( 'username' => $_POST['username'], 'password' => $_POST['password'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'], 'school' => $_POST['school'], 'subject_name' => $_POST['subject_name'], 'email_code' => md5($_POST['username'] + microtime()) ); register_user($register_data); header('Location: register.php?success'); exit(); }else if (empty($errors) === false){ echo output_errors($errors); } ?><ul>
<li>--------------Personal Details-----------------</li>
<br />
<li>
Username*:<br>
<input type="text" name="username">
</li>
<li>
Password*:<br>
<input type="password" name="password">
</li>
<li>
Password again*:<br>
<input type="password" name="password_again">
</li>
<li>
First Name*:<br>
<input type="text" name="first_name">
</li>
<li>
Last Name:<br>
<input type="text" name="last_name">
</li>
<li>
Email*:<br>
<input type="text" name="email">
</li>
<br />
<br />
<li>
-----------------Subjects Area ------------------
</li>
<br />
Select your school:
St Marys, Charleville
CBS, Charleville
<li>
<input type="submit" value="register">
</li>
</ul>
<?
}
include 'includes/overall/overallfooter.php'; ?>
[/php]
getuser.php
[php]<?php
$q=$_GET[“q”];
$con = mysql_connect(‘localhost’, ‘root’, ‘root’);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
mysql_select_db(“lr”, $con);
$sql=“SELECT subject_name FROM subjects WHERE id = '”.$q."’";
$result = mysql_query($sql);
echo "
Please Select your subjects | |
---|---|
” . $row[‘subject_name’] . “ | ”;”; echo “”; echo “ | ”;
mysql_close($con);
?>[/php]
something is stopping it all from working but i dont know what!! i just need all the register input info to add to db…please help