jasonhardwick Posted May 13, 2008 Share Posted May 13, 2008 Can anyone tell me whats wrong with this code it isnt producing any results <?php include "config.php"; $user=($_SESSION['username']); $tbl_name="user"; $sql="SELECT * FROM $tbl_name WHERE uname =$user"; $result=mysql_query($sql); $f_name=$_GET['f_name']; echo "$f_name"; ?> Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/ Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 you need session_start() before you do anything with sessions. i also don't see where you're connecting to a database. are you seeing any errors? and, unless you are passing f_name in the URL, $_GET['fname'] will be empty. Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540041 Share on other sites More sharing options...
benphp Posted May 13, 2008 Share Posted May 13, 2008 Here's a problem: $sql="SELECT * FROM $tbl_name WHERE uname =$user"; should be $sql="SELECT * FROM $tbl_name WHERE uname = '$user' "; Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540043 Share on other sites More sharing options...
jasonhardwick Posted May 13, 2008 Author Share Posted May 13, 2008 here is my session start <? session_start(); if (empty($_SESSION['username'])){ header("location:index1.php"); exit; } ?> and i call the database via the config.php I tried the solution by BENPHP with no luck... also i am not getting any errors Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540049 Share on other sites More sharing options...
revraz Posted May 13, 2008 Share Posted May 13, 2008 Using mysql_error() after your queries will show you sql errors. Post the whole code instead of just bits. Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540050 Share on other sites More sharing options...
paul2463 Posted May 13, 2008 Share Posted May 13, 2008 what are you trying to do??? are you trying to use $_GET to get the value of f_name from the database based on the uname being the same as $user?? Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540052 Share on other sites More sharing options...
revraz Posted May 13, 2008 Share Posted May 13, 2008 $f_name=$_GET['f_name']; echo "$f_name"; So what is the URL that you are using to pass your GET? Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540054 Share on other sites More sharing options...
jasonhardwick Posted May 13, 2008 Author Share Posted May 13, 2008 ok... sorry what i am trying to do is create a my account page so you can review and edit your information and i am trying to pull the proper record by using the session "username" here is the code <? session_start(); if (empty($_SESSION['username'])){ header("location:index1.php"); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>My Creative Process</title> <style type="text/css"> <!-- .style1 {color: #666666} --> </style> <link href="/css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style2 { color: #f73602; font-weight: bold; } .style3 { color: #FFFFFF } .style4 {color: #F15A25} --> </style> </head> <body> <table width="972" border="0" cellspacing="0" cellpadding="5"> <tr> <td><div align="right">Logged in as: <? echo $_SESSION['username'];?></div></td> </tr> </table> <table width="972" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#F73602" id="frame"> <tr bordercolor="#F15A25"> <td colspan="4"><div align="center"> <p><img src="/images/header.jpg" width="942" height="84" /></p> <table width="902" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="728"><p><span class="style1"><a href="/index.php">home</a> | <a href="/main_forum.php">review</a> | <a href="/create_topic.php">post</a> | <a href="/mindgames.php">mindgames</a> | <a href="/archive.php">archive</a> | <a href="/brainstorm.php">brainstorm</a> | <a href="/my_account.php">my account</a> | <a href="/suggestion_box.php">suggestion box</a></span></p> </td> <td colspan="-1"><div align="right"> <? //echo "You've been logged in since" . $_SESSION['time'] . "<br>"; echo '<a href="logout.php">Click here to logout</a>'; //echo "<br>"; // echo '<a href="' .$_SERVER['PHP_SELF']. '?action=change"> Change Password</a>'; ?> <? include "fns.php"; $action=$_GET['action']; if($action=="change"){ changepw($_SESSION['username']); update($newpass,$_SESSION['username']); }else{ } ?> </div></td> </tr> </table> <table width="902" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="728" valign="top"><p> <?php include "config.php"; $user=($_SESSION['username']); $tbl_name="user"; $sql="SELECT * FROM $tbl_name WHERE uname = '$user' "; $result=mysql_query($sql); $f_name=$_GET['f_name']; echo $_SESSION['username']; echo $f_name; ?> Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540059 Share on other sites More sharing options...
jasonhardwick Posted May 13, 2008 Author Share Posted May 13, 2008 any ideas... I'm lost. ??? Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540090 Share on other sites More sharing options...
benphp Posted May 13, 2008 Share Posted May 13, 2008 Start your code with <?php The following works: <?php session_start(); $_SESSION['username'] = "Joe Shmo"; if(!isset($_SESSION['username'])) { header("location:index1.php"); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>My Creative Process</title> <style type="text/css"> <!-- .style1 {color: #666666} --> </style> <link href="/css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style2 { color: #f73602; font-weight: bold; } .style3 { color: #FFFFFF } .style4 {color: #F15A25} --> </style> </head> <body> <table width="972" border="0" cellspacing="0" cellpadding="5"> <tr> <td><div align="right">Logged in as: <? echo $_SESSION['username'];?></div></td> </tr> </table> <table width="972" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#F73602" id="frame"> <tr bordercolor="#F15A25"> <td colspan="4"><div align="center"> <p><img src="/images/header.jpg" width="942" height="84" /></p> <table width="902" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="728"><p><span class="style1"><a href="/index.php">home</a> | <a href="/main_forum.php">review</a> | <a href="/create_topic.php">post</a> | <a href="/mindgames.php">mindgames</a> | <a href="/archive.php">archive</a> | <a href="/brainstorm.php">brainstorm</a> | <a href="/my_account.php">my account</a> | <a href="/suggestion_box.php">suggestion box</a></span></p> </td> <td colspan="-1"><div align="right"> <? //echo "You've been logged in since" . $_SESSION['time'] . "<br>"; echo '<a href="logout.php">Click here to logout</a>'; //echo "<br>"; // echo '<a href="' .$_SERVER['PHP_SELF']. '?action=change"> Change Password</a>'; ?> <? // $action=$_GET['action']; $action="sdfasdfasdfa"; if($action=="change"){ changepw($_SESSION['username']); update($newpass,$_SESSION['username']); }else{ } ?> </div></td> </tr> </table> <table width="902" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="728" valign="top"><p> <?php //include "config.php"; //I don't know what this does, so I got rid of it. $user=($_SESSION['username']); $tbl_name="user"; $sql="SELECT * FROM $tbl_name WHERE uname = '$user' "; print $sql; //$result=mysql_query($sql); //$f_name=$_GET['f_name']; $f_name="Joe"; echo $_SESSION['username']; echo $f_name; ?> Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540111 Share on other sites More sharing options...
jasonhardwick Posted May 13, 2008 Author Share Posted May 13, 2008 my config file connects me to my database so i can access my users information. and i need to check their username aginst the seccion that was greated when they login... then i need to pull that record. Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540125 Share on other sites More sharing options...
benphp Posted May 13, 2008 Share Posted May 13, 2008 yah that's fine, but your problem is that you start your code with <? and not <?php at least that's the problem I found. The code I posted works, just uncomment my comments and remove my session username Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540180 Share on other sites More sharing options...
jasonhardwick Posted May 13, 2008 Author Share Posted May 13, 2008 ok i tried it but i have a question reguarding this line $f_name="Joe"; So what would i change this to? Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540188 Share on other sites More sharing options...
benphp Posted May 13, 2008 Share Posted May 13, 2008 Doood - it's your code - $result=mysql_query($sql); $f_name=$_GET['f_name']; echo $_SESSION['username']; echo $f_name; ?> I just changed it so I wouldn't get errors. The answer to your question is: $f_name=$_GET['f_name']; Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540191 Share on other sites More sharing options...
revraz Posted May 13, 2008 Share Posted May 13, 2008 Do either of you know what $_GET even does? Doesn't seem like it. Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540217 Share on other sites More sharing options...
benphp Posted May 13, 2008 Share Posted May 13, 2008 revraz are you posting just to be a prick? Seems like it. Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540219 Share on other sites More sharing options...
jasonhardwick Posted May 13, 2008 Author Share Posted May 13, 2008 I know... I thought I was using it right but if not offer some help... anyway I'm still not getting anything with my echo line... i guess there is a problem with my $f_name = $_GET['f_name'] any other ideas would be great... below is the whole code revised <?php session_start(); if(!isset($_SESSION['username'])) { header("location:index1.php"); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>My Creative Process</title> <style type="text/css"> <!-- .style1 {color: #666666} --> </style> <link href="/css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style2 { color: #f73602; font-weight: bold; } .style3 { color: #FFFFFF } .style4 {color: #F15A25} --> </style> </head> <body> <table width="972" border="0" cellspacing="0" cellpadding="5"> <tr> <td><div align="right">Logged in as: <? echo $_SESSION['username'];?></div></td> </tr> </table> <table width="972" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#F73602" id="frame"> <tr bordercolor="#F15A25"> <td colspan="4"><div align="center"> <p><img src="/images/header.jpg" width="942" height="84" /></p> <table width="902" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="728"><p><span class="style1"><a href="/index.php">home</a> | <a href="/main_forum.php">review</a> | <a href="/create_topic.php">post</a> | <a href="/mindgames.php">mindgames</a> | <a href="/archive.php">archive</a> | <a href="/brainstorm.php">brainstorm</a> | <a href="/my_account.php">my account</a> | <a href="/suggestion_box.php">suggestion box</a></span></p> </td> <td colspan="-1"><div align="right"> <?php echo '<a href="logout.php">Click here to logout</a>'; $action="sdfasdfasdfa"; if($action=="change"){ changepw($_SESSION['username']); update($newpass,$_SESSION['username']); }else{ } ?> </div></td> </tr> </table> <table width="902" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="728" valign="top"><p> <?php include "config.php"; //I don't know what this does, so I got rid of it. $user=($_SESSION['username']); $tbl_name="user"; $sql="SELECT * FROM $tbl_name WHERE uname = '$user' "; $f_name=$_GET['f_name']; echo $f_name; ?> Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540235 Share on other sites More sharing options...
jasonhardwick Posted May 13, 2008 Author Share Posted May 13, 2008 Any sugestions would be great.... anything Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540284 Share on other sites More sharing options...
runnerjp Posted May 13, 2008 Share Posted May 13, 2008 ok this ----> include "config.php"; (//I don't know what this does, so I got rid of it. ) will have all ur username password ect for msql so that way you dont have to keep adding it to scripts and so its more safe now could you post this code and tell me what you get <?php session_start(); if(!isset($_SESSION['username'])) { header("location:index1.php"); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>My Creative Process</title> <style type="text/css"> <!-- .style1 {color: #666666} --> </style> <link href="/css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style2 { color: #f73602; font-weight: bold; } .style3 { color: #FFFFFF } .style4 {color: #F15A25} --> </style> </head> <body> <table width="972" border="0" cellspacing="0" cellpadding="5"> <tr> <td><div align="right">Logged in as: <? echo $_SESSION['username'];?></div></td> </tr> </table> <table width="972" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#F73602" id="frame"> <tr bordercolor="#F15A25"> <td colspan="4"><div align="center"> <p><img src="/images/header.jpg" width="942" height="84" /></p> <table width="902" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="728"><p><span class="style1"><a href="/index.php">home</a> | <a href="/main_forum.php">review</a> | <a href="/create_topic.php">post</a> | <a href="/mindgames.php">mindgames</a> | <a href="/archive.php">archive</a> | <a href="/brainstorm.php">brainstorm</a> | <a href="/my_account.php">my account</a> | <a href="/suggestion_box.php">suggestion box</a></span></p> </td> <td colspan="-1"><div align="right"> <?php echo '<a href="logout.php">Click here to logout</a>'; $action="sdfasdfasdfa"; if($action=="change"){ changepw($_SESSION['username']); update($newpass,$_SESSION['username']); }else{ } ?> </div></td> </tr> </table> <table width="902" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="728" valign="top"><p> <?php include "config.php"; //I don't know what this does, so I got rid of it. $user=($_SESSION['username']); $tbl_name="user"; $sql="SELECT * FROM $tbl_name WHERE uname = '$user' " or die(mysql_error()); $f_name=$_GET['f_name']; echo $f_name; ?> (bare with me as im also learning lol) Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540315 Share on other sites More sharing options...
revraz Posted May 14, 2008 Share Posted May 14, 2008 Nope, I just think it's funny when people reply with worse advice than what the OP had to start with. revraz are you posting just to be a prick? Seems like it. Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540594 Share on other sites More sharing options...
paul2463 Posted May 14, 2008 Share Posted May 14, 2008 I am making an assumption that you are using $_GET incorrectly and have adjusted and commented this part of your code $user=($_SESSION['username']); $tbl_name="user"; $sql="SELECT * FROM $tbl_name WHERE uname = '$user' " or die(mysql_error()); $f_name=$_GET['f_name']; Instead try this if my comments make sense to what you want $user=($_SESSION['username']); //create the user variable $tbl_name="user"; //create the table variable $sql="SELECT * FROM $tbl_name WHERE uname = '$user' "; //create the query $result = mysql_query($sql) or die ("error in the query" . mysql_error()); //execute the query $row = mysql_fetch_assoc($result); //return the row information in an array $f_name = $row['f_name']; //pull the forename from that array //if I am correct in my assumption then the following line does not do what you want it to //$f_name=$_GET['f_name']; Link to comment https://forums.phpfreaks.com/topic/105445-whats-wrong-with-this-code/#findComment-540746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.