-2

My issue is that I am making a dating site form with following categories

firstname,lastname,username,password,email,mysex,yoursex,relationship,date of birth, and country

I did the whole php code so when submitted would send info to sql server. But there is some error on php half, date of birth(DOB) day,month,year. And mysex and yoursex values are not submitting. Sql gives undefined index. Here is my code.(The falf that is not submitting)

<form action="process.php" method="post" id="register" class="col-xs-12"> 
<input class="register-switch-input" type="radio" name="mysex" value="hombre" id="me-male" > <label class="register-switch-label" for="me-male"> Hombre </label>
<input class="register-switch-input" type="radio" name="mysex" value="mujer" id="me-female"> <label class="register-switch-label" for="me-female"> Mujer </label> <br>  

<input type="radio" name="yoursex" value="hombre" id="your-male" checked> <label for="your-male"> Hombre </label>
<input  type="radio" name="yoursex" value="mujer" id="your-female"> <label for="your-female"> Mujer </label> 
<input type="radio" name="yoursex" value="cualquiera" id="cualquiera">  <label for="cualquiera">Cualquiera </label> <br> 

<label class="form-label">Nacimiento:</label>
   <select name="DOBMonth" >
   <option> - Month - </option>
   <option value="January">January</option>
   <option value="Febuary">Febuary</option>
    ""

<select name="DOBDay" >
 <option> - Day - </option>
 ""

<select name="DOBYear">
  <option> - Year - </option>
  <option value="2003">2003</option>

The "" is because the selects have a million options and are unnessecary. Here is my php code

 <?php
$servername = "localhost";
$username = "diego966";
$password = "ddddd966";
$dbname= "signup";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$mysex = $_POST["mysex"];
$yoursex = $_POST["yoursex"];
$relationship = $_POST['relationship'];
$DOBday = $_POST['DOBday'];
$DOBmonth = $_POST['DOBmonth'];
$DOByear = $_POST['DOByear'];
$country = $_POST['country'];




$sql="INSERT INTO accounts(firstname, lastname, username, password, email, mysex, yoursex, relationship, DOBday, DOBmonth, DOByear, country)
        VALUES ('$firstname', '$lastname','$username', '$password', '$email','$mysex', '$yoursex', '$relationship', 'DOBday', 'DOBmonth ','DOByear', '$country')"; 

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
9
  • 1
    sanitise your inputs, don't trust user data. ever. Also you probably have a typo $DOBday = $_POST['DOBday']; should be $DOBday = $_POST['DOBDay']; - notice the capital on D for day. M for month. Y for year in your POST Also for radio buttons your error is probably because the returned value for $yoursex is an array Commented Mar 17, 2016 at 21:51
  • what do you mean by sanitize my inputs? And yeah i discovered that just before i saw this comment haha. But cant fix the sex yet... Commented Mar 17, 2016 at 21:53
  • see css-tricks.com/snippets/php/sanitize-database-inputs basically with your code someone could hack your database really easily. get all your customer data. you'll get sued. Commented Mar 17, 2016 at 21:56
  • @ChelseaStats if by an array your refering to the double quotation marks i fixed that just now but still no progress :/ Commented Mar 17, 2016 at 21:57
  • Then also look at using bind variables php.net/manual/en/mysqli-stmt.bind-param.php Commented Mar 17, 2016 at 21:57

1 Answer 1

1

As partly mentioned in the comments:

  • DOBMonth is DOBmonth in PHP
  • DOBYear is DOByear in PHP
  • DOBDay is DOBday in PHP
  • your radio-field needs to be defined by name="yoursex[]" in HTML and then you check in PHP if isset($_POST["yoursex"]) and then you can use $_POST["yoursex"][0]

Sanitizing has been mentioned but can not be mentioned enough

Sign up to request clarification or add additional context in comments.

1 Comment

why the 0 array after your sex?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.