Jump to content

bong25

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bong25's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. THANKS for no response. But I finally made it after playing with it (for almost a day with such a few hours of sleep) by breaking the codes into three to minimized and concentrate only with the main code... blah blah blah. Then finally works, the only thing is the code is quite ugly maybe you wiz guys can simplify it. This is the working code I just crack down. <?php include ('config.php'); include ('connect.php'); ?> <?php $sql="SELECT rid, name FROM room"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_assoc($result)) { $rid=$row["rid"]; $rname=$row["name"]; $options.="<OPTION VALUE=\"$rid\">".$rname.'</option>'; } ?> <?php if (isset($_POST['Submit'])) { if($_POST['pass'] == $_POST['confirmpass']) { $pass = 'Ok'; $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']; $options = $_POST['rid']; $adduser = mysql_query("INSERT INTO user (name, rid, pass) VALUES ('$name', '$options', 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>'; } } ?> <html> <head> <title> Registration </title> <link rel="stylesheet" href="styles.css" type="text/css"> </head> <body> <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> <SELECT NAME=rid> <OPTION VALUE=0>Choose <?echo $options?> </SELECT> </td></tr> <tr><td></td><td><input type="Submit" name="Submit" value="Register"></td></tr> </form> </table> <p><?php echo $error; ?></p> </body> </html>
  2. 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.
×
×
  • 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.