Search code examples
phpmysqlregistration

Registration php


I have created a registration form in which you can submit your details and they are saved in the database. I have a drop-down box for one of the fields called "Title" and this data is not submitted. I am hoping that I could get some feedback on this issue and maybe resolve the issue.

 <!DOCTTYPE html>
<head><link rel="stylesheet" type="text/css" href="style/style.css"></head>
<title>Registration</title>
<body>  

    <form name="form1" method="post" action="register_ac.php">

        <li>Title<select name="title" id="title"><option value="MR">MR</option><option value="MRS">MRS</option></option><option value="MISS">MISS</option></select></li>
        <li>FirstName<input type="text" name="firstname" class="#" id="firstname"/></li>
        <li>Surname<input type="text" name="surname" class="#" id="surname"/></li>
        <li>Username<input type="text" name="username" class="#" id="username"/></li>
        <li>Password<input type="password" name="password" class="#" iid="password"/></li>
        <li>Email<input type="text" name="email" class="#" id="email"/></li>
        <li>Addressline1<input type="text" name="addressline1" class="#" id="addressline1"/></li>
        <li>Addressline2<input type="text" name="addressline2" class="#" id="addressline2"/></li>
        <li>City<input type="text" name="city" class="#"  id="city"/></li>
        <li>County<input type="text" name="county" class="#"  id="county"/></li>
        <li>Postcode<input type="text" name="postcode" class="#"  id="postcode"/></li>


        <input type="submit" id="textarea" name="submit" value="Submit" class="button"/>
    </form>

</body>
</html>



<?php

$host="localhost"; // Host name
$username="#####"; // Mysql username
$password="#####"; // Mysql password
$db_name="#####"; // Database name
$tbl_name="Register"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$username=$_POST['username'];
$title=$_POST['title'];
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$password=$_POST['password'];
$email=$_POST['email'];
$addressline1=$_POST['addressline1'];
$addressline2=$_POST['addressline2'];
$city=$_POST['city'];
$county=$_POST['county'];
$postcode=$_POST['postcode'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(username, title, firstname, surname, password, email, addressline1, addressline2, city, county, postcode)
VALUES('$username', '$title', '$firstname','$surname','$password','$email','$addressline1','$addressline2','$city','$county','$postcode')";
$result=mysql_query($sql);


// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='index.php'>Back to main page</a>";
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_close();
?>

Solution

  • You have an error in this line:

    <li>Title<select name="title" id="title"><option value="MR">MR</option><option value="MRS">MRS</option></option><option value="MISS">MISS</option></select></li>
    

    One too many </option> tags. Try:

    <li>Title<select name="title" id="title"><option value="MR">MR</option><option value="MRS">MRS</option><option value="MISS">MISS</option></select></li>