Hi! I'm new with php scripts and need some help here.
I have got a simple online chat which taken elsewhere (don't remember now) and want it to add additional feature..
I have copied somewhere here a "User Registration Scripts" and it work withuot any problem, but I have to add feature like dropdown selection.
As you can see in the php script I have commented the area that I needed to incorporate (dropdown selection). But I have tried so many things with my little knowledge without success.
Please help.
The database Tables:
The Registration Script:
<?php
if (isset($_POST['submit'])) {
if($_POST['pass'] == $_POST['confirmpass']) {
$pass = 'Ok';
$dbhost = "localhost";
$dbuser = "***";
$dbpass = "******";
$dbname = "chat";
$connect = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$connect) {
die('MySQL Error ' . mysql_error());
} else {
$selectdb = mysql_select_db($dbname);
if (!$selectdb){
die('MySQL Error ' . mysql_error());
} else {
$checkuser = mysql_query("SELECT * FROM user WHERE name = '".$_POST[name]."' ");
if (!$checkuser) {
die('MySQL Error' . mysql_error());
} else {
if(mysql_num_rows($checkuser) > 0) {
$error = '<font color="red"> User Already Exists </font>';
} else {
$name = $_POST['name'];
$pass = $_POST['pass'];
$rid = $_POST1['roomid'];
$adduser = mysql_query("INSERT INTO user (name, pass) VALUES ('$name', '$rid', PASSWORD('$pass'))");
if (!$adduser) {
die('MySQL Error ' . mysql_error());
} else {
$error = '<font color="green">User Added Succesfully </font>';
}
}
}
}
}
} else {
$error = '<font color="red"> Passwords Do Not Match </font>';
}
}
/*
$query=("select * from room order by name, name desc");
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
echo "<form action=select method=POST1>";
echo "<select name=roomid>";
while($row=mysql_fetch_array($result)) {
echo "<OPTION VALUE=".$row['rid'].">".$row['name']."</OPTION><br>"; }
echo "</select>";
echo "</form>";
*/
?>
<html>
<head>
<title> Registration </title>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<center>
<table width="300px">
<form action="<?php echo $PHP_SELF; ?>" method="POST">
<tr><td>Username:</td><td><input type="text" name="name"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Confirm Password:</td><td><input type="password" name="confirmpass"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Register"></td></tr>
</form>
</table>
<p><?php echo $error; ?></p>
</center>
</body>
</html>
Edit: While a user is trying to register a drop down menu should be available for a user to select which room he/she is trying to register, so once the register button is press values should be availble to insert to user table. The dropdown menu should throw a value of 'rid' column from room table that can be added to user table.