jcl43 Posted December 3, 2008 Share Posted December 3, 2008 Hi all, I am creating a login system for my site. So far the registration and login both work great, but I am having a problem redirecting a user to the myaccount.php page after a successful login. I was planning on having a link to continue to their profile page and was doing it like so: <?php echo "<h2>Success! You are now logged in " . $_SESSION['username'] . "</h2><br><br>"; ?> <h2>Click here to continue to your profile: <a href="myaccount.php?username However, i am unsure of how to complete the link, or if that is even the correct way to do it. Would it be recommended to use header() instead? And if so how would I implement that in this situation so it doesnt automatically redirect? Thanks in advance for any help! Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/ Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 You can use a meta redirect. Look that up on google, "meta redirect html" Header does not have a delay unless you sleep the script for x seconds. Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/#findComment-705217 Share on other sites More sharing options...
DeanWhitehouse Posted December 3, 2008 Share Posted December 3, 2008 myaccount.php?username Bad idea, could end up leaving security gaps, best to just have myaccount.php And use a session to get the db data Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/#findComment-705222 Share on other sites More sharing options...
revraz Posted December 3, 2008 Share Posted December 3, 2008 Header would not work since you have output to the browser. The best way to do this is to pass the user id over via a Session that way it can't be compromised. So just send them to myaccount.php but in that page, use the Session for thier user id to pull up their relavent data. Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/#findComment-705226 Share on other sites More sharing options...
jcl43 Posted December 3, 2008 Author Share Posted December 3, 2008 Thanks a lot to you all, it seems to be working. I will report back if I have any need for further help. thanks again edit: btw i am using the myaccount.php method and grabbing session data. Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/#findComment-705241 Share on other sites More sharing options...
jcl43 Posted December 4, 2008 Author Share Posted December 4, 2008 Thanks for the previous help, I am now getting an error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /d3/home/univ/cis450rb/public_html/index.php on line 194 The code that is trying to run is here: if (!$con) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($dbusername) or die("Unable to select database"); $query = "select * from Opportunity" . "where oppId = 10"; $results = mysql_query( $query, $con ); while ($row = mysql_fetch_array($results)) { echo "<p>" . $results . "</p>"; } The while loop is where the error is being thrown. I know there is something I am missing, but cannot figure it out for the life of me. Any help is appreciated..thanks! Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/#findComment-705685 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 Chances are the opportunity and where are combined which is throwing an error: $query = "select * from Opportunity" . " where oppId = 10"; // added space here $results = mysql_query( $query, $con ); To have gotten the error this would have thrown it: $results = mysql_query( $query, $con ) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/#findComment-705688 Share on other sites More sharing options...
jcl43 Posted December 4, 2008 Author Share Posted December 4, 2008 Thanks, I added a space after Opportunity and that got rid of the error. However, it is now only outputting Resource id #3 instead of the contents of $results. Should I not be using my_sql_fetch_array? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/#findComment-705697 Share on other sites More sharing options...
jcl43 Posted December 4, 2008 Author Share Posted December 4, 2008 Ok, nm i got it working. I replaced echo "<p>" . $results . "</p>"; with... echo "<p>" . $row['title']. $row['deadline'] . $row['descrip'] . $row['link'] . $row['postDate'] . "</p>"; Now it just needs some better formatting....thanks anyways! Quote Link to comment https://forums.phpfreaks.com/topic/135389-help-with-user-account-page/#findComment-705714 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.