Jump to content

DeanWhitehouse

Members
  • Posts

    2,527
  • Joined

  • Last visited

Everything posted by DeanWhitehouse

  1. i think i might be able to "dynamically create links" but i'm not sure, do i just make an echo for each link and then it will only display them if they are in the database?
  2. is this the right thing <?php if (isset($_GET['id'])) { $user_id = '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 "Invalid user ID passed to page!"; } ?> <a href="?id=1">Blade</a>
  3. i have a user profile page, this page works by checking the users session_id and then gets this data from the database. Now how can i display this to other users, for example, so other users can view other users profiles(this is a really bad explanation). this is my current page <?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 "Username:<a href='mailto:$email'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } } else { echo "Please login to view this page."; } ?>
  4. ok, works now thanks, i dunno what you changed as i can't see where but thanks
  5. can this work, or do i need to redirect them
  6. no, where saying that we don't know what is happening in each include
  7. ok, so what do i need to change it to. because i want it to log them in on the same page there on
  8. well this is my whole code, <?php if (isset($_GET['logout'])) { setcookie("cookname", $_SESSION['username'], time() - 3600, "/"); setcookie("cookpass", $_SESSION['user_password'], time() - 3600, "/"); session_unset(); session_destroy(); } if ($_SESSION['is_valid'] == true){ if ($_SESSION['user_level'] == 2){ ?> <table class='logged_in'><tr><td> <p>Welcome, <br><?php echo $_SESSION['username']; ?> <br><a href='user_profile.php?id=<?php echo $_SESSION['user_id']; ?>'>User Profile</a><br> <a href='user_setting.php'>Settings</a><br> <a href="<?php print $_SERVER["PHP_SELF"]; ?>?logout=true">Logout</a><br /> </td></tr><tr><td>Logged In</td></tr></table></p> <?php } if ($_SESSION['user_level'] == 1){ ?> <table class='logged_in'><tr><td> <p>Welcome, <?php echo $_SESSION['username']; ?> <br><a href='user_profile.php?id=<?php echo $_SESSION['user_id']; ?>'>User Profile</a><br> <a href='user_setting.php'>Settings</a><br> <a href='admin_centre.php'>Admin Area</a><br> <a href="<?php print $_SERVER["PHP_SELF"]; ?>?logout=true">Logout</a><br /> </td></tr><tr><td>Logged In</td></tr></table></p> <?php } } else { require_once 'db_connect.php'; if ($_SESSION['is_valid'] == false){ if (isset($_POST['login'])){ $user_name = $_POST["user_name"]; $user_password = $_POST["user_password"]; $cookiename = forumcookie; $verify_username = strlen($user_name); $verify_pass = strlen($user_password); if ($verify_pass > 0 && $verify_username > 0) { $salt = substr($user_password, 0, 2); $userPswd = crypt($user_password, $salt); $sql = "SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd' LIMIT 1;"; $result = mysql_query($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].$_SERVER[REQUEST_URI]); $_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].$_SERVER[REQUEST_URI]); $_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]); } } ?> as you can see it has the login form intergrated
  9. i am having another problem now, i am using this code if (isset($_GET['logout'])) { session_unset(); session_destroy(); setcookie("cookname", $_SESSION['username'], time() - 3600, "/"); setcookie("cookpass", $_SESSION['user_password'], time() - 3600, "/"); } with this <a href="<?php print $_SERVER["PHP_SELF"]; ?>?logout=true">Logout</a><br /> but now when i have been logged out, the page displays a login form but it doesn't work. i get this address when i log out http://deanwhitehouse.awardspace.co.uk/test/main_forum.php?logout=true but if i delete the logout=true bit , i can login ,but not if its theres
  10. good thinking darkwater, i didin't even look for that
  11. with this code } if(isset($_POST['hideemail']) == 0) { mysql_query("UPDATE $user SET show_email = '0' WHERE user_id = '$user_id'")or die('Could not change settings: ' . mysql_error()); } elseif(isset($_POST['hideemail']) == 1) { mysql_query("UPDATE $user SET show_email = '1' WHERE user_id = '$user_id'")or die('Could not change settings: ' . mysql_error()); } echo "Settings Saved"; } its changing the show_email even when i don't tick either box, it shouldn't be doing this, it should only do this if it is ticked.
  12. are there any errors, and change the code to this. <?php $company = $_POST['company']; $name = $_POST['name']; $city = $_POST['address']; $postal = $_POST['postal']; $tel = $_POST['tel']; $email = $_POST['email']; $comments = $_POST['comments']; if(isset($_POST['submit'])) { echo "$company<br>$name<br>$city<br>$postal<br>$tel<br>$emaili<br>$comments"; // add anything you want displayed } else { ?> <u>Input a user</u> <br /> <form method="post" action='<?php $_SERVER['PHP_SELF']; ?>'> <table> <tr> <td>Company: <td><input type="text" name="company"> </tr> <tr> <td>Name: <td><input type="text" name="name"> </tr> <tr> <td>Address: <td><input type="text" name="address"> </tr> <tr> <td>City: <td><input type="text" name="city"> </tr> <tr> <td>Postal Address: <td><input type="text" name="postal"> </tr> <tr> <td>Telephone Number: <td><input type="text" name="tel"> </tr> <tr> <td>Email Address: <td><input type="text" name="email"> </tr> <tr> <td>Comments: <td><input type="text" name="comments"> </tr> <tr> <td><input type="submit" value="Submit"> </tr> </table> <?php } ?> first of all and once this bit works, work on the search.
  13. ok, let me change the code a bit <?php $company = $_POST['company'] $name = $_POST['name'] $city = $_POST['address'] $postal = $_POST['postal] $tel = $_POST['tel'] $email = $_POST['email'] $comments = $_POST['comments'] if(isset($_POST['submit'])) { echo $company<br>$name<br>$city<br>$postal<br>$tel<br>$email<br>$comments; // add anything you want displayed } else { ?> <html> <body> <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'> <table> <tr> <td>Company: <td><input type="text" name="company"> </tr> <tr> <td>Name: <td><input type="text" name="name"> </tr> <tr> <td>Address: <td><input type="text" name="address"> </tr> <tr> <td>City: <td><input type="text" name="city"> </tr> <tr> <td>Postal Address: <td><input type="text" name="postal"> </tr> <tr> <td>Telephone Number: <td><input type="text" name="tel"> </tr> <tr> <td>Email Address: <td><input type="text" name="email"> </tr> <tr> <td>Comments: <td><input type="text" name="comments"> </tr> <tr> <td><input type='submit' value='Submit' name='submit' /> </tr> </table> <?php } ?>
  14. if(isset($_POST['update'])) { if($user_email) { if($user_email == $user_email2) { mysql_query("UPDATE $user SET user_email = '$user_email' WHERE user_id = '$user_id'")or die('Could not update email: ' . mysql_error()); } else { echo "Email Addresses do not match"; } } if($user_password) { if($user_password == $user_password2) { mysql_query("UPDATE $user SET user_password = '$user_password' WHERE user_id = '$user_id'")or die('Could not change password: ' . mysql_error()); } else { echo "Passwords do not match"; } } if(isset($_POST['hideemail'])) { mysql_query("UPDATE $user SET show_email = '0' WHERE user_id = '$user_id'")or die('Could not change settings: ' . mysql_error()); } elseif(isset($_POST['hideemail'])) { mysql_query("UPDATE $user SET show_email = '1' WHERE user_id = '$user_id'")or die('Could not change settings: ' . mysql_error()); } } ?> <html> <table bgcolor='#999999' align='center' width="400px"> <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'> <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' value="<?php echo "$email"; ?>" /><br /></td></tr> <tr><td width="10px">Confirm E-mail Address: </td><td><input type='text' name='user_email2' value="<?php echo "$email"; ?>" /><br /></td></tr> <tr><td width="10px">Maximum Length<br /> 30 characters.</td></tr> <tr><td width="10px">New Password:</td><td> <input type='password' name='user_password' maxlength="30" /><br /></td></tr> <tr><td width="10px">Confirm Password:</td><td> <input type='password' name='user_password2' maxlength="30" /><br /></td></tr> <tr><td width="10px">Hide Email</td><td width="10px">Yes<input type="radio" value="0" name="hideemail"/> No<input type="radio" value="1" name="hideemail"/> </td></tr> <tr><td><input type='submit' value='Save Changes' name='update' /></td> </form> </table> </html> this is my code for the page where they can check the box, i want it so that if they check one it updates the database and if another updates it differently
  15. so if im right? you want to display what they enter in the form on the page, try this <?php $array = array("company","name","address","city","postal","tel","email","comments"); // i've never used arrays so im not sure if this way works if(isset($_POST['submit'])) { echo $array["company"]; // add anything you want displayed } else { ?> <html> <body> <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'> <table> <tr> <td>Company: <td><input type="text" name="company"> </tr> <tr> <td>Name: <td><input type="text" name="name"> </tr> <tr> <td>Address: <td><input type="text" name="address"> </tr> <tr> <td>City: <td><input type="text" name="city"> </tr> <tr> <td>Postal Address: <td><input type="text" name="postal"> </tr> <tr> <td>Telephone Number: <td><input type="text" name="tel"> </tr> <tr> <td>Email Address: <td><input type="text" name="email"> </tr> <tr> <td>Comments: <td><input type="text" name="comments"> </tr> <tr> <td><input type='submit' value='Submit' name='submit' /> </tr> </table> <?php } ?>
  16. in case the title didn't make sense , i will explain. how can i have it so if a user checks a box it stays checked and if they don't check it , it isn't checked?? also is there a way to have multiple check boxes with the same, but then how can i differ them when using an if(isset($_POST[''])) function as they have the same name(how else can they be intetifed)
  17. so would this be right, to edit details for this getting the row from there id no. $user_id = $_SESSION['user_id']; mysql_query("UPDATE SET user_id = '$user_id' WHERE user_name = $user_name AND user_password = $user_password AND user_email = $user_email")
×
×
  • 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.