Jump to content

Not outputting selected values?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
Hi, I am curently working on a private messaging system in php. I started working on the final page (the view mail) and have ran into a snag. When you select the message it sends you to a page name view_sent.php?id="id here" it takes me to the new page and the corect Id shows in the address bar and no errors come out but the page does not return any information. right now i just have it returning the value of sender so i can get it working before i code the layout and return all of the information. Here is my code for the view_sent



<?php

$id=$_Get['id'];

$user="blah"; // need to change to session later

$host="--------------"; 

$username="---------"; 

$password="---------";

$db_name="---------";  

$tbl_name="---------"; 



mysql_connect("$host", "$username", "$password")or die("cannot connect"); 

mysql_select_db("$db_name")or die("cannot select DB");


$sql="SELECT * FROM $tbl_name Where id='$id'";

$result=mysql_query($sql);

$row = mysql_fetch_row($result);

echo $row['sender'];

?>


Posted Image

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Does
echo $sql
display what you are expecting? Does
$result=mysql_query($sql) or die("Query Error: " . mysql_error());
provide you with an error? What does
print_r($result)
yield?

#3
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
1) Returns half of the sql statement cutting off at $id
2) No result
3) Resource id #2 (googleing this now, so far no usefull results)


Edit:
Hey John thanks for all the help. I got it working. I went and got the code from an old project from back when i used tutorials (now I make the schema and try to do it all myself)

the code looks simular and i still dont see what the problem was hertrs the working code


$id=$_GET['id'];


$sql="SELECT * FROM $tbl_name WHERE id='$id'";


$result=mysql_query($sql);


$rows=mysql_fetch_array($result);

echo $rows['sender'];

(i had tryed array befor i posted and it was not working)

Edited by zeroradius, 17 May 2008 - 06:44 AM.

Posted Image

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
I know the problem.

you used mysql_fetch_row() instead of mysql_fetch_array()

mysql_fetch_row() makes an array with index numbers only, mysql_fetch_array() makes an named array with fieldnames as keys to the field information.

it's simple, but hard to find in code.

then, you wrote $_Get first, and now $_GET, don't know if that makes difference ...

Edited by Orjan, 24 May 2008 - 06:59 AM.


#5
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
as i said in my last post i had tried array before i posted here, and the capitals in get may have made a diffrence, but i do not think it will
Posted Image

#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
well, as $id was empty before, I think the capital thing was the matter :-)