winmastergames Posted February 5, 2008 Share Posted February 5, 2008 Firstly Sorry if this is already answered.. I need some help with storing and displaying Mysql data I have a MYSQL user auth script multiuser one I need to make a script that would get the user thats logged in like "Bob" or something then be able to get that data from a MYSQL database so the user can See the Data they inputted in Registration so they can edit it and stuff We bit confusing please ask questions Its really annoying me im trying to rip my head out trying to make this so i hope you guys can help me Thanks Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/ Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Here is a login tutorial http://www.roscripts.com/PHP_login_script-143.html Here is a MySQL and PHP Tutorial http://www.freewebmasterhelp.com/tutorials/phpmysql/4 When you get that absorbed, I'll show you how a user can load their data to edit/update it. Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459034 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 And read up on sessions and cookies http://devzone.zend.com/article/646-PHP-101-part-10-A-Session-In-The-Cookie-Jar Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459037 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 Thanks but i already have the Login script i just need some kind of script that when the user logs in then it gets the username and finds the other MYSQL data assigned to that user if you know what i mean Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459041 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Make a session and store the user's ID when they log in. Create a new page like myprofile.php and in that file use $_GET to get the $_SESSION['id'] and then populate a form with the entries. Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459044 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 Well I have a simple script here i made using the tutorials you gave me View Data Script: <html> <head> <title>Displaying MySQL Data</title> </head> <body> <?php $db_host = "localhost"; $db_user = "root"; $db_pwd = "mypass"; $db_name = "test"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <table> <?php $sql = "SELECT * FROM data"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "<tr>"; echo "<td>".$row['title']."</td>"; echo "<td>".$row['slogan']."</td>"; echo "</tr>"; } ?> </table> </body> </html> Store Data Script: <?php $db_host = "localhost"; $db_user = "root"; $db_pwd = "mypass"; $db_name = "test"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <html> <head> <title>My first MySQL form submission</title> </head> <body> <?php if (!isset($_POST['submit'])) { ?> <form action="" method="post"> Title: <input type="text" name="title"><br> Slogan: <input type="text" name="slogan"><br> <input type="submit" name="submit" value="Submit!"> </form> <?php } else { $title = $_POST['title']; $slogan = $_POST['slogan']; mysql_query("INSERT INTO `data` (title, slogan) VALUES ('$title', '$slogan')"); echo "Success! Your favourite colour has been added!"; } ?> </body> </html> Is that Ok? no problems with that? And how will i do the GET thing with the sesson would you please be able to give me an example and maybe what it does like explained if possible Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459065 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 This is quite confusing ??? isnt it? ill explain it in more detail The user will login into their profile they will then be able to change Data that is in the MYSQL database under there name only.. Then in another PHP script i want it to be able to connect to the MYSQL database and let the user have like index.php?user=bob if their user name is bob and it will view the MYSQL data for their name Is that a bit better Well hopefully Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459077 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 What is wrong with me do people just get scared away from me am i that ugly Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459096 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Not confusing at all. My post above explained how to do that except I used a session in my example with a id instead of their username. Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459097 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Need patience, we're not just sitting here at our PC's waiting for you to ask a question. What is wrong with me do people just get scared away from me am i that ugly Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459100 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 Oh sorry its just Sessions are annoying is there any other way to do this why do i need sessions anyway im just getting the username and getting MYSQL data based on that Username Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459106 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Then by all means, feel free to do it that way. Use my example and modify to your method. Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459109 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 Oh ive just done some Searching and finally found a tut cause the one you gave me was confussing so the tut told me to use this for storing Sessions is that right <?php session_start(); //Start Session _SESSION['views'] = 1; // store session data echo "Pageviews = ". $_SESSION['views']; //retrieve data ?> EDIT: forgot some code in it Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459112 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Yes, thats the way you start a session. Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459114 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 but using this _SESSION['views'] = 1; // store session data How will you change the store session data to the username well what i thought i guess you change the "1" to the data in the username textbox Am i right how will i do that? Yay im learning something thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459118 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 On your login page, when you authenticate them, do a SELECT ID (or whatever field you want to store, ID, username, email..blah blah). Then fetch that data and use: $_SESSION['id'] = $row[0]; Assuming the first field is the ID field, change to the field you want to store. Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459125 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 Yes i know that but look at the code to store the session _SESSION['views'] = 1; // store session data doesnt that need editing to work with my Login Script well i thought it did i may be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459128 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 It has an error when i try to make sessions work anyway heres the login script see if you can make it work <?php // Connects to your Database mysql_connect("localhost", "root", "mypass") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } else { // if they are not logged in ?> <?php $userlog = $_POST['username'] session_start(); //Start Session _SESSION['log31531'] = $userlog; // store session data ?> $_SESSION['views'] = 1; // store session data <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> I tried getting the data using POST but normally i use GET so it wont work using they way i tried it I really dont know how to do sessions how do you make it store the Username as a session it just displays this error Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\userauthttt\login.php on line 77 Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459139 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 Is this too hard? is there a better way i should do this because no one here seems to be getting me a straight answer Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459144 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 It's not too hard at all. You're getting a straight answer, but you don't understand it. You need to read some more tutorials and learn more PHP it seems. Is this too hard? is there a better way i should do this because no one here seems to be getting me a straight answer Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459152 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 I think ive got it now Cause it used Cookies In the members area of the Login script made it retrive the Cookie of the username it works but is that a good way i should do it is it safe? Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459154 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 Um but how do i now get like the data from the username and display the data for it like Email and stuff Quote Link to comment https://forums.phpfreaks.com/topic/89601-solved-display-and-store-mysql-data/#findComment-459183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.