Jump to content

Registration form with drop down menu


Pcelica

Recommended Posts

Hi I'm new here, also I'm new in php. What I need to do is to write registration form with drop down menu. Actually, I need to have drop down menu which would write data into database when someone fill registration form. Also I need when someone choose one of the city name in drop down menu, to display certain image in specific php page. Can anyone help me.

Here is my code for registration form :

register.php

<?PHP

 

//Database Information

 

$dbhost = "";

$dbname = "";

$dbuser = "";

$dbpass = "";

 

//Connect to database

 

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());

mysql_select_db($dbname) or die(mysql_error());

 

   

$name = $_POST['name'];

$email = $_POST['email'];   

$username = $_POST['username'];

$password = md5($_POST['password']);

$grad = $_POST['grad'];

 

// lets check to see if the username already exists

 

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");

 

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){

    echo "I'm sorry but the username you specified has already been taken.  Please pick another one.";

    unset($username);

    include 'register.html';

    exit();

}

$checkemail = mysql_query("SELECT email FROM users WHERE email='$email'");

$email_exist = mysql_num_rows($checkemail);

if($email_exist > 0){

    echo "Email koji ste izabrali vec postoji.";

    unset($email);

    include 'register.html';

    exit();

}

$checkname = mysql_query("SELECT name FROM users WHERE name='$name'");

$name_exist = mysql_num_rows($checkname);

if($name_exist > 0){

    echo "Ime koje ste izabrali vec postoji.";

    unset($name);

    include 'register.html';

    exit();

}

// lf no errors present with the username

// use a query to insert the data into the database.

 

$query = "INSERT INTO users (name, email, username, password, grad) VALUES('$name', '$email', '$username', '$password','$grad')";

 

mysql_query($query) or die(mysql_error());

mysql_close(); 

if(empty($name) || empty($email) || empty($username))

{

echo "Nisu uneseni svi podaci.";

}

/*else if(empty(($password))) //ovaj uslov ne prolazi !!!

{

echo "Niste uneli lozinku.";

}*/

else

{

echo "Uspesno ste se registrovali";

}

?>

 

and for form :

register.html

<form name="login" method="post" action="register.php">

<table border="0" width="225" align="center">

    <tr>

        <td width="219" bgcolor="#ff6600">

            <p align="center"><font color="white"><span style="font-size:14pt;"><b>Registration</b></span></font></p>

        </td>

    </tr>

    <tr>

        <td width="555">

            <table border="0" width="555" align="center">

                    <tr>

                        <td width="116"><span style="font-size:12pt;">Name:</span></td>

                        <td width="156"><input type="text" name="name" maxlength="100"></td>

<td width="200"><p align="left"><span style="font-size:11pt;"><i>*Ukucajte vase puno ime i prezime*</i></span></p></td>

                    </tr>

 

<tr>

                        <td width="116"><span style="font-size:12pt;">Email:</span></td>

                        <td width="156"><input type="text" name="email" maxlength="100"></td><br/>

 

                    </tr>

                <tr>

                    <td width="116"><span style="font-size:12pt;">Username:</span></td>

                    <td width="156"><input type="text" name="username"></td><br/>

 

                </tr>

                <tr>

                    <td width="116"><span style="font-size:12pt;">Password:</span></td>

                    <td width="156"><input type="password" name="password"></td><br/>

 

                </tr>

                <tr>

                    <td width="116"> </td>

                        <td width="156">

                            <p align="right"><input type="submit" name="submit" value="Submit"></p>

                        </td>

                </tr>

<tr>

<td>

<select name = "dropdown" value="options">

<option value "register.php">Izaberi grad</option>

<option value = "Beograd">Beograd</option>

<option value = "Nis">Nis</option>

<option value = "Novi Sad">Novi Sad</option>

</select>

</td>

</tr>

            </table>

        </td>

    </tr>

    <tr>

        <td width="219" bgcolor="#ff6600"> </td>

    </tr>

 

</table>

</form>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/213579-registration-form-with-drop-down-menu/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.