Jump to content

Whats wrong with this code?


jasonhardwick

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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 :P

 

 

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.