Jump to content

Session name


TehBlizzy

Recommended Posts

  • Replies 54
  • Created
  • Last Reply

This isn't right:else if(empty($myusername[$mypassword])) {You're using their password as an index in the array. So if they type in "secretcode" as their password, then you create an entry called $myusername["secretcode"]. You probably want to use $myusername["mypassword"], and store the value in there.$myusername["mypassword"] = $mypassword;...else if(empty($myusername["mypassword"])) {Check if you do that in other places also. If you want to store the array index in the variable name then you can use the variable as the index. If you only want to use a word as the index (like "password") then don't use a variable, put it in quotes.If you want to replace a string you can use str_replace:http://www.php.net/manual/en/function.str-replace.phpTo check characters you can either use a regular expression or strposhttp://www.php.net/manual/en/function.strpos.phpCheck the examples on those pages.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Its been a while and I've decided that I had too many things to work on so I pretty much cut out everything on the site. All it will have is an index with the login boxes, a register page that sends an email to the specified email by the user, a verify page, and the chatrooms. At the moment, I'm copying all the files to the original randomchatroom.zxq.net because the PHPMyAdmin for my MySQL database doesn't load anymore. While I'm doing that, I'm trying to get the register.php page to echo certain texts above the register form if the username is taken(which works) and if the form isn't filled out(which isn't working). When the page loads after clicking the link, it already says "Please fill out the form..". This is the register.php code:

<?php$err=$_GET["error"];$name=$_GET["myusername"];$pass=$_GET["mypassword"];$email=$_GET["myemail"];echo("<html>  <head>  <title>Random Chatrooms - Index</title>  <link href='css/red.CSS' rel='stylesheet' type='text/css'>  </head>  <body><center>  <table border='1' width='800'>  <tr>  <td colspan='3' height='100' width='800'><img src='imgz/red_logo.jpg'>  </td>  </tr>  <tr height='400'>  <td width='100'><div align='center'><h2>Navigation</h2><br><br><a href='register.php'>Register</a><br><a href='verify.php'>Verify</a><br></div></td>  <td width='550'><div align='center'><h2>Register by filling out the form below.</h2><form name='form1' method='post' action='reg.php'><br><br>");if($err=="nametaken") {echo("Sorry, but that Username is taken. Please try another.<br><br>");}elseif($err="empty") {  echo("Please fill out the whole form to register.<br><br>");}elseif($err="NULL") {echo(" ");}echo("<p>Your Username: <input name='myusername' type='text' id='myusername' value='$name'><br><br>Your Password: <input name='mypassword' type='text' id='mypassword' value='$pass'><br><br>   Your Email: <input name='myemail' type='text' id='email' value='$email'></p><br><br><input type='submit' name='Submit' value='Register'></form></div></td></tr></table></body></html>");?>

and this is my reg.php code (the part that does the MySQL and stuff):

<?phpob_start();$host="localhost"; // Host name$username=""; // Mysql username$password=""; // Mysql password$db_name=""; // Database name$tbl_name="members"; // Table name// Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// Define $myusername and $mypassword$username=$_POST['myusername'];$password=$_POST['mypassword'];$email=$_POST['myemail'];$sql="SELECT * FROM $tbl_name WHERE username='$username'";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result);// If result matched $myusername and $mypassword, table row must be 1 rowif($count==1){header("location:register.php?error=nametaken");}else {header("location:register.php?error=empty&myusername=$username&mypassword=$password&myemail=$email");}ob_end_flush();?>

**Note:I accidentally removed the part where it inserts the data if the fields are ok so if anyone puts up the correct coding,it would be cool if it could include where I put the code for the MySQL insertion stuff.. Thanks >_<

Link to comment
Share on other sites

You're using one equal sign instead of two:elseif($err="empty") {That's an assignment expression, not a logical test. You need to add your insert SQL statement anywhere after you validate the form inputs. Add exit statements after you redirect so that if you redirect the script ends, and then add the SQL statements after that.

Link to comment
Share on other sites

Archived

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


×
×
  • Create New...