Jump to content

DeanWhitehouse

Members
  • Posts

    2,527
  • Joined

  • Last visited

Everything posted by DeanWhitehouse

  1. Does anyone have a code that will display the local time of the viewer? And that is real time, eg. every second the seconds increase, instead of time updating on page reload.
  2. thats a subdomain, not created by PHP(i don't think) but created on the host
  3. looking through my other codes shows there is a table infront of the button
  4. When i view my home page, the submit button isn't clickable. Can someone check if this is just me or the site. this is the link http://deanwhitehouse.awardspace.co.uk/home.php this is the code for the form <table bgcolor='#999999' align='right'><form action=" <?php echo "$server"; ?> " method='POST'> <tr><td>Username: </td><td><input type='text' name='user_name' value="<?php echo $_COOKIE['uname']; ?>" /><br /></td></tr> <tr><td>Password:</td><td> <input type='password' name='user_password' value="<?php echo $_COOKIE['userpw'] ?>" /><br /></td></tr> <tr><td><input type="hidden" name="login" value="true"><input type="submit" value="Submit"></td></tr> <tr><td><input type="checkbox" name="remember" <?php echo $_COOKIE['check'] ?>> Remember Me </td></tr><tr><td><a href="register.php">[Register]</a></td></tr><tr><td><a href="forgot_password.php">[Forgot Password?]</a></td></tr></table> </form>
  5. yep, here we go http://www.phpeasystep.com/workshopview.php?id=12
  6. also, i have tried using else aswell. and that didn't work.
  7. ok, this is my code, <?php if ($_SESSION['is_valid'] == false) { if(isset($_POST['signup'])) { if ($user_name && $user_password && $user_password2 && $user_email && $user_email2) { if (strstr($user_email, '@')) { $user_check = mysql_num_rows(mysql_query("SELECT * FROM $user WHERE user_email='$user_email' OR user_name='$user_name'")); $length = strlen($user_password); $length1 = strlen($user_name); if ($length >= 6) { if ($length1 >= 4) { if ($user_check >= 1) { require_once 'register.php'; echo "Sorry, but the username or email you requested is already in use. Please enter a different username."; } elseif ($user_password == $user_password2 && $user_email == $user_email2) { $userPswd = md5($user_password); $userpwsd = sha1($userPswd); mysql_query("INSERT INTO `$user` (user_id, user_name, user_password, user_email, user_ip, userlevel ) VALUES ('','$user_name','$userpwsd','$user_email','$ip','2')") or die('Error ' . mysql_error()); echo "Succesfully Registered. You will recieve a confirmation email shortly."; header ("http://".$_SERVER[HTTP_HOST].$success); } } } } } if(!strstr($user_email, '@')) { echo "Invalid Email<br>"; } if($length <= 5) { require_once 'register.php'; echo "Password Too Short<br>"; } if($length1 <= 3) { require_once 'register.php'; echo "Username Too Short.<br>"; } if(!$checkpw) { require_once 'register.php'; echo "The passwords you entered do not match. Please check these details and try again.<br>"; } if(!$checkem) { require_once 'register.php'; echo "The emails you entered do not match. Please check these details and try again.<br>"; } else { require_once 'register.php'; echo "Please fill in all of the required fields."; } } ?> Can someone see if they can see why it isn't working properly, my problem is that it echoes some of the other IF's , if the email is incorrect. i have tried for a long time to try and fix it, can someone just have a look and see.
  8. I no how to do if-else, but i want the code to check each bit, but anway. How can i stop these errors appearing when the user enters nothing Warning: preg_match() [function.preg-match]: Empty regular expression in /home/www/deanwhitehouse.awardspace.co.uk/register.php on line 80 line 80 if (!preg_match($checkmail, $user_email)) { echo "Invalid e-mail address<br>"; }
  9. As i thought that code doesn't work, it now doesn't echo anything or do anything. Please check your code before posting, and stop with the comments. I dunno what you have against me.
  10. soz, i thought that ==0 did't work, it's my fault i was wrong, i thought that didn't work, and i wasn't going to try the code as i am just looking and saying what i thought was wrong. And i never said the if=else statement wouldn't work, i said it was wrong ,the correct way to write it is with the {}
  11. yer, but you will need to know what to delete from the code.
  12. this is wrong if(mysql_num_rows($res)==0) echo "there is no data in table.."; else for($i=0;$i<mysql_num_rows($res);$i++) { $row=mysql_fetch_assoc($res); echo"<option>$row[cat]</option>"; } ?> it should be if(mysql_num_rows($res)==0) { echo "there is no data in table.."; } else { for($i=0;$i<mysql_num_rows($res);$i++) { $row=mysql_fetch_assoc($res); echo"<option>$row[cat]</option>"; } ?>
  13. ok, but that still leaves the error, this is part of the code, where it is happening $checkmail = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/"; if (preg_match($checkmail, $user_email)) { $user_check = mysql_num_rows(mysql_query("SELECT * FROM $user WHERE user_email='$user_email' OR user_name='$user_name'")); $length = strlen($user_password); $length1 = strlen($user_name); if ($length >= 6) { if ($length1 >= 4) { if ($user_check >= 1) { require_once 'register.php'; echo "Sorry, but the username or email you requested is already in use. Please enter a different username."; } elseif ($user_password == $user_password2 && $user_email == $user_email2) { $userPswd = md5($user_password); $userpwsd = sha1($userPswd); mysql_query("INSERT INTO `$user` (user_id, user_name, user_password, user_email, user_ip, userlevel) VALUES ('','$user_name','$userpwsd','$user_email','$ip','2')") or die('Error ' . mysql_error()); echo "Succesfully Registered. You will recieve a confirmation email shortly."; header ("http://".$_SERVER[HTTP_HOST].$success); } } } } if($length <= 5) { require_once 'register.php'; echo "Password Too Short<br>"; } if($length1 <= 3) { require_once 'register.php'; echo "Username Too Short.<br>"; } if(!$checkpw) { require_once 'register.php'; echo "The passwords you entered do not match. Please check these details and try again.<br>"; } if(!$checkem) { require_once 'register.php'; echo "The emails you entered do not match. Please check these details and try again.<br>"; } } if (!preg_match($checkmail, $user_email)) { echo "Invalid e-mail address<br>"; } else { require_once 'register.php'; echo "Please fill in all of the required fields."; } }
  14. you need a space after == numbers need to have spaces between them eg. $word == number not $word ==number same with all numbers they need a space before and after
  15. ok, if you get any errors post the code aswell as the error and i will try and help
  16. but when i use this code, <?php // Random Game Design: PHP Website Template // Version 1 // Copyright Dean Whitehouse, 2008 require_once 'includes/db_connect.php'; // Connect to database mysql_connect($dbhost,$dbuser,$dbpass) or die('Could not connect: ' . mysql_error()); $user_name = mysql_real_escape_string($_POST["user_name"]); $user_password =mysql_real_escape_string($_POST["user_password"]); $user_password2 =mysql_real_escape_string ($_POST["user_password2"]); $user_email =mysql_real_escape_string ($_POST["user_email"]); $user_email2 =mysql_real_escape_string ($_POST["user_email2"]); $ip = $_SERVER['REMOTE_ADDR']; $success = "/reg_success.php"; $checkpw = $user_password == $user_password2; $checkem = $user_email == $user_email2; if ($_SESSION['is_valid'] == false) { //if(isset($_POST['agree'])){ if(isset($_POST['signup'])) { if ($user_name && $user_password && $user_password2 && $user_email && $user_email2) { $checkmail = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/"; if (preg_match($checkmail, $user_email)) { $user_check = mysql_num_rows(mysql_query("SELECT * FROM $user WHERE user_email='$user_email' OR user_name='$user_name'")); $length = strlen($user_password); $length1 = strlen($user_name); if ($length >= 6) { if ($length1 >= 4) { if ($user_check >= 1) { require_once 'register.php'; echo "Sorry, but the username or email you requested is already in use. Please enter a different username."; } elseif ($user_password == $user_password2 && $user_email == $user_email2) { $userPswd = md5($user_password); $userpwsd = sha1($userPswd); mysql_query("INSERT INTO `$user` (user_id, user_name, user_password, user_email, user_ip, userlevel) VALUES ('','$user_name','$userpwsd','$user_email','$ip','2')") or die('Error ' . mysql_error()); echo "Succesfully Registered. You will recieve a confirmation email shortly."; header ("http://".$_SERVER[HTTP_HOST].$success); } } } } if($length <= 5) { require_once 'register.php'; echo "Password Too Short<br>"; } if($length1 <= 3) { require_once 'register.php'; echo "Username Too Short.<br>"; } if(!$checkpw) { require_once 'register.php'; echo "The passwords you entered do not match. Please check these details and try again.<br>"; } if(!$checkem) { require_once 'register.php'; echo "The emails you entered do not match. Please check these details and try again.<br>"; } } if (!preg_match($checkmail, $user_email)) { echo "Invalid e-mail address<br>"; } else { require_once 'register.php'; echo "Please fill in all of the required fields."; } } ?> <html> <table bgcolor='#999999' align='center' width="400px"> <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'> <tr><td width="10px">Username: </td><td><input type='text' name='user_name' maxlength="20" width="400px" /><br /></td></tr> <tr><td width="10px">Maximum Length<br /> 20 characters.</td></tr> <tr><td width="10px">E-mail Address:</td> <td><input type='text' name='user_email' /><br /></td></tr> <tr><td width="10px">Confirm E-mail Address: </td><td><input type='text' name='user_email2' /><br /></td></tr> <tr><td width="10px">Password:</td><td> <input type='password' name='user_password' maxlength="30" /><br /></td></tr> <tr><td width="10px">Min. 6<br>Max. 10</td></tr> <tr><td width="10px">Confirm Password:</td><td> <input type='password' name='user_password2' maxlength="30"/><br /></td></tr> <tr><td><input type='submit' value='Complete Registration' name='signup' /></td><td><input type="reset" value="Reset Fields" name="reset" /></td></tr> </form> </table> </html> <?php mysql_close(); } else { header("Location:http://".$_SERVER[HTTP_HOST]); } ?> if it is a valid email it works if it isn't i get echoed there aswell Password Too Short Username Too Short. even when it isn't, and this only happens when the regex is there
  17. well, with this you will get dynamic links that show user_profile?id=1 etc. this is my login code, showing how to add the sessions, and yes this will get you what you want <?php require_once 'includes/db_connect.php'; if ($_SESSION['is_valid'] == false){ if (isset($_POST['login'])){ $user_name = mysql_real_escape_string($_POST["user_name"]); $user_password =mysql_real_escape_string($_POST["user_password"]); $cookiename = forumcookie; $verify_username = strlen($user_name); $verify_pass = strlen($user_password); if ($verify_pass > 0 && $verify_username > 0) { $userPswd = md5($user_password); $userpwsd = sha1($userPswd); $sql = "SELECT * FROM $user WHERE user_name='$user_name' AND user_password='$userpwsd' LIMIT 1;"; $result = mysql_query($sql) or die(mysql_error(). " in $sql"); if (mysql_num_rows($result) == 1){ $row = mysql_fetch_assoc($result); $user_level = $row['userlevel']; if ($user_level == 1) { $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); $_SESSION['username'] = $row['user_name']; $_SESSION['user_password'] = $row['user_password']; $_SESSION['user_level'] = $row['userlevel']; $_SESSION['user_id'] = $row['user_id']; header("Location:http://".$_SERVER[HTTP_HOST]); $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files if(isset($_POST['remember'])){ setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/"); setcookie("cookpass", $_SESSION['user_password'], time()+60*60*24*100, "/"); } } elseif ($user_level == 2){ $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); $_SESSION['username'] = $row['user_name']; $_SESSION['user_password'] = $row['user_password']; $_SESSION['user_level'] = $row['userlevel']; $_SESSION['user_id'] = $row['user_id']; header("Location:http://".$_SERVER[HTTP_HOST]); $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files if(isset($_POST['remember'])){ setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/"); setcookie("cookpass", $_SESSION['user_password'], time()+60*60*24*100, "/"); } } } else{ echo "Login failed. Username and Password did not match database entries."; } } else { echo "Form was not completed. Please go back and make sure that the form was fully completed."; } } ?> <html> <table bgcolor='#999999' align='right'><form action="<?php $_SERVER['PHP_SELF']; ?>" method='POST'> <tr><td>Username: </td><td><input type='text' name='user_name' /><br /></td></tr> <tr><td>Password:</td><td> <input type='password' name='user_password' /><br /></td></tr> <tr><td><input type="hidden" name="login" value="true"><input type="submit" value="Submit"></td></tr> <tr><td><input type="checkbox" value="1" name="remember"> Remember Me </td></tr><tr><td><a href="register.php">[Register]</a></td></tr><tr><td><a href="forgot_password.php">[Forgot Password?]</a></td></tr></table> </form> </html> <?php mysql_close(); } else { header("Location:http://".$_SERVER[HTTP_HOST]); } ?>
  18. u need to use sessions on the login, there make dynamic links using there sessions. here is an example <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; if ($_SESSION['is_valid'] == true){ $user_id = $_SESSION['user_id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name']; $email = $row['user_email']; echo "$username<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Email:<a href='mailto:$email'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } } else { echo "Please login to view this page."; } ?> and a members page, <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; if ($_SESSION['is_valid'] == true){ if (isset($_GET['id'])) { if ((int) $_GET['id'] > 0) { $user_id = $_GET['id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $userprofname = $row['user_name']; $profemail = $row['user_email']; echo "$userprofname<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Email:<a href='mailto:$profemail'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } exit(); } else { echo "Invalid user ID passed to page! <br />"; echo "<a href=\"members.php\">Return to user list</a>"; exit(); } } //No ID passed to page, display user list: $query = "SELECT user_id, user_name FROM $user"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { echo "User List:<br />"; while ($row = mysql_fetch_assoc($result)) { echo '<a href="?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />'; } } } else { echo "Please login to view this page."; } ?> this is my user profile link <br><a href='user_profile.php?id=<?php echo $_SESSION['user_id']; ?>'>User Profile</a><br>
  19. Ok, i now have this if(isset($_POST['signup'])) { if ($user_name && $user_password && $user_password2 && $user_email && $user_email2) { $checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i"; if (preg_match($checkemail, $user_email)) { $user_check = mysql_num_rows(mysql_query("SELECT * FROM $user WHERE user_email='$user_email' OR user_name='$user_name'")); $length = strlen($user_password); $length1 = strlen($user_name); if ($length >= 6) { if ($length1 >= 4) { if ($user_check >= 1) { require_once 'register.php'; echo "Sorry, but the username or email you requested is already in use. Please enter a different username."; } elseif ($user_password == $user_password2 && $user_email == $user_email2) { $userPswd = md5($user_password); $userpwsd = sha1($userPswd); mysql_query("INSERT INTO `$user` (user_id, user_name, user_password, user_email, user_ip, userlevel) VALUES ('','$user_name','$userpwsd','$user_email','$ip','2')") or die('Error ' . mysql_error()); echo "Succesfully Registered. You will recieve a confirmation email shortly."; header ("http://".$_SERVER[HTTP_HOST].$success); } } } } if($length <= 5) { require_once 'register.php'; echo "Password Too Short<br>"; } if($length1 <= 3) { require_once 'register.php'; echo "Username Too Short.<br>"; } if(!$checkpw) { require_once 'register.php'; echo "The passwords you entered do not match. Please check these details and try again.<br>"; } if(!$checkem) { require_once 'register.php'; echo "The emails you entered do not match. Please check these details and try again.<br>"; } } elseif (!preg_match($checkemail, $user_email)) { echo "Invalid e-mail address<br>"; } else { require_once 'register.php'; echo "Please fill in all of the required fields."; } } ?> but i get an error when there is nothing entered and it also stops anything below it working properly
  20. is this part, ok, because it doesn't show, am i doing it right? <tr><td>Username: </td><td><input type='text' name='user_name' value="<?php echo $_COOKIE["cookname"]; ?>" /><br /></td></tr> </form>
  21. from what i gather i can use either ereg or preg_match, to check for a certain character in a string. but i can't understand how to do it using either ereg() or preg_match can someone explain, i wan2 be able to check for this symbol @ in a $_POST
×
×
  • 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.