-
Posts
2,527 -
Joined
-
Last visited
Everything posted by DeanWhitehouse
-
how can i insert into a certain row in my database mysql_query("INSERT INTO `$user` (user_name, user_password, user_email) VALUES ('$user_name','$userPswd','$user_email')") this is the code, i want to use there user_id and/or there user_name to find the row to insert into
-
o yer, soz my fault, i thought i had tried it with that added. Thanks for all the help.
-
no, db_connect.php has the session_start() on it also when i try to echo like this <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $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'] echo "$username"; ?> i get an "unexpected" error with this, it doesn't expect the echo
-
this code is right but, it doesn't display anything from the database <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $user_id = addslashes($_GET['id']); $sql = "SELECT * FROM `$user` WHERE `user_id`='{$user_id}' LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name'] ?> i tried changing it to this but, it still isn't displaying anything <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $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'] ?> do i need to echo it?
-
i get this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/deanwhitehouse.awardspace.co.uk/test/user_profile.php on line 9 with this code <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $user_id = addslashes($_GET['id']); $sql = "SELECT * FROM `$user` WHERE `id`='{$user_id}' LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name'] ?>
-
how would i arrange this data
-
i have this code for the user profile link <a href='user_profile.php?id=<?php echo $_SESSION['user_id']; ?>'>Settings</a><br> now on the user_profile.php page how do i display this users profile, can i call all there details from the database using there user_id
-
how do i do the issest check as i only no how to do it for $_POST i no if (isset($_POST['login'])){ but how can i make it work for me
-
i think its the right title, anyhow how can i make a login code so the link is like <a href="whateverpageon?logout">Logout</a> instead of my <a href="logout.php">Logout</a> basically ,so that when they logout they are kept on the same page
-
soz, add session_start() at the beggining of it
-
session_unset(); session_destroy(); logout
-
try this <?php session_start(); if ($_SESSION['logged_in'] == true){ echo "You are logged in."; } else { echo "You are not logged in."; } ?> and this <?php session_start(); $username = "lemon"; $password = "123"; if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { ?> <form name="login" method="post" action="<?=$_SERVER['PHP_SELF']; ?>"> <table> <tr><td>Username: <td><input type="text" title="Enter your Username" name="txtUsername" /> <tr><td>Password: <td><input type="password" title="Enter your password" name="txtPassword" /> <tr><td colspan=2 align=right><input type="submit" name="Submit" value="Login" /> </table> </form> <?php } else { $_SESSION['logged_in'] == true; echo "Hello "; echo "$username"; echo ".<br>You will be redirected to the admin page in a couple of seconds..."; ?> <META http-equiv="refresh" content="2;URL=/admin/"> <?php } ?>
-
lol, yer, thanks(i thought that just before i read this) do u no how i can make a minimum input for the form, for the password area?
-
soz, and if there username is already taken.
-
try this and tell me what it says. <?php if ($_SESSION['logged_in'] == true){ ?> You are logged in. <?php } elseif($_SESSION['logged_in'] == false) { ?> You are not logged in. <?php } ?>
-
this code was meant to check if the email is already in use but doesn't. why? <?php // Random Game Design: PHP Website Template // Version 1 // Copyright Dean Whitehouse, 2008 require_once 'db_connect.php'; // Connect to database mysql_connect($dbhost,$dbuser,$dbpass) or die('Could not connect: ' . mysql_error()); $user_name = $_POST["user_name"]; $user_password = $_POST["user_password"]; $user_password2 = $_POST["user_password2"]; $user_email = $_POST["user_email"]; $user_email2 = $_POST["user_email2"]; $ip = $_SERVER['REMOTE_ADDR']; $success = "/reg_success.php"; if ($_SESSION['is_valid'] == false) { //if(isset($_POST['agree'])){ if(isset($_POST['signup'])) { if ($user_name && $user_password && $user_password2 && $user_email && $user_email2) { $user_check = mysql_num_rows(mysql_query("SELECT * FROM $user WHERE user_name='$user_name' AND user_email='$user_email'")); 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) { $salt = substr($user_password, 0, 2); $userPswd = crypt($user_password, $salt); mysql_query("INSERT INTO `$user` (user_id, user_name, user_password, user_email, user_ip, userlevel) VALUES ('','$user_name','$userPswd','$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"); } else { require_once 'register.php'; echo "Either the passwords or emails you entered do not match. Please check these details and try again"; } } 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">Maximum Length<br /> 30 characters.</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]); } ?> also the header under the echo "Succesfully Registered. You will recieve a confirmation email shortly."; doesn't do anything
-
are you starting the session in the login script for when they login
-
$user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name'")); i need this code to be this one , but work. $user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name' AND WHERE user_email='$user_email'"));
-
session_start(); has to be at the very top of the page, the first thing after <?php
-
Problem with cookies, remember and registration page
DeanWhitehouse replied to DeanWhitehouse's topic in PHP Coding Help
am i ending the cookie wrong -
ok, at the top of everypage put session_start(); put this on the login page for when they login $_SESSION['logged_in] = true; then on the index page put if ($_SESSION['logged_in] == true) { // what ever the index page is } else { //what ever if there not logged in }
-
create a session when they login, then check for the session on the index.page and if its there display it if it isn't display something else
-
its not a simple task, it will take some kind of database or flatfiles storage, and it take a fair bit of code. If you want i can email you some of the code you will need.
-
Problem with cookies, remember and registration page
DeanWhitehouse replied to DeanWhitehouse's topic in PHP Coding Help
the commented part doesn't work when i use it, and when i go the registration page it has the data from the remember me , although i used this to kill the cookie in the logout script logout.php <?php require_once 'db_connect.php'; session_unset(); session_destroy(); setcookie("cookname", $_SESSION['username'], time() - 3600, "/"); setcookie("cookpass", $_SESSION['user_password'], time() - 3600, "/"); header("Location:http://".$_SERVER[HTTP_HOST]); ?>