Jump to content


Photo

displays resource ID #


  • Please log in to reply
6 replies to this topic

#1 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 16 May 2006 - 10:33 PM

Okay so I have the following code:
$var_array = explode("?",$PATH_INFO);
$user = $var_array[1];

$first = mysql_query("SELECT user_first FROM user_info WHERE user_name='$user'");
$first = mysql_query("SELECT user_last FROM user_info WHERE user_name='$user'");
echo "<b>$first $last</b>";

Now the idea is that I break up the URL which would look something like this: mysite.com/index.htm?name=myusername?pass=true

Now instead of displaying the name like 'Jared Nance'
it displays Resource ID #5 Nance

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 16 May 2006 - 10:42 PM

well first off, you are overwriting the results of your first $first with your second (I assume you meant to do $last = msyql_query(...) for the 2nd one?)

2nd, doing the query returns a result resource. you need to actually get the results you want with mysql_fetch_array or mysql_fetch_assoc after the query like this:

$firstname = mysql_fetch_array($first);
echo $firstname['user_first'];
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 16 May 2006 - 10:48 PM

thanks for the help

#4 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 16 May 2006 - 11:37 PM

NEW PROBLEM:
I try to display a table row like this
echo "<tr><td>'$id'</td><td>'$adminuserid'</td><td>'$adminfname'</td><td>'$adminlname'</td><td>'$adminemail'</td><td>'$adminverified'</td></tr>";

and some how it returns an error unexpected '>' for that line of code.


#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 May 2006 - 11:54 PM

You do realize that the proper way of separating variables on the URL is with a "&". The "?" is only used to separate alll of the variables from the script name, so your URL should be written as
[!--html--][div class=\'htmltop\']HTML[/div][div class=\'htmlmain\'][!--html1--]mysite.com/index.php?name=myusername&pass=true[!--html2--][/div][!--html3--]
The the value of of "name" and "pass" would be available to your PHP script in $_GET['user'] and $_GET['true'] respectively.

Your code could then be written as
<?php
$q = "SELECT user_first, user_last FROM user_info WHERE user_name='" . $_GET['user'] ."'";
$rs = mysql_query($q) or die("Problem with query: $q <br>" . mysql_error());
$rw = mysql_fetch_assoc($rs);
echo '<b>' . $rw['user_first'] .' ' .  $rw['user_last'] . '</b>';
?>

For your new question ... do any of the values you're trying to echo contain a double quote (")?

If so, you want to use the function htmlentities() on each variable in the echo.

Ken

#6 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 May 2006 - 12:05 AM

I know about the amperstand thing, but that's not really what I am currently focused on. And actually I am using cookies, but just cross checking the URL with the value stored in the cookies. No, they shouldn't contain any double quotes. I pulled them from a databse where they have been put by a user form.

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 17 May 2006 - 12:41 AM

[!--quoteo(post=374483:date=May 16 2006, 06:37 PM:name=webdogjcn)--][div class=\'quotetop\']QUOTE(webdogjcn @ May 16 2006, 06:37 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
NEW PROBLEM:
I try to display a table row like this
echo "<tr><td>'$id'</td><td>'$adminuserid'</td><td>'$adminfname'</td><td>'$adminlname'</td><td>'$adminemail'</td><td>'$adminverified'</td></tr>";

and some how it returns an error unexpected '>' for that line of code.
[/quote]
there's nothing wrong with that piece of code. your problem is elsewhere. can you show some of the surrounding code?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users