Jump to content

Archived

This topic is now archived and is closed to further replies.

webdogjcn

displays resource ID #

Recommended Posts

Okay so I have the following code:
[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>";[/code]

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

Share this post


Link to post
Share on other sites
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'];

Share this post


Link to post
Share on other sites
NEW PROBLEM:
I try to display a table row like this
[code]echo "<tr><td>'$id'</td><td>'$adminuserid'</td><td>'$adminfname'</td><td>'$adminlname'</td><td>'$adminemail'</td><td>'$adminverified'</td></tr>";[/code]

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

Share this post


Link to post
Share on other sites
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
[code]<?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>';
?>[/code]

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 [url=http://www.php. net/htmlentities]htmlentities()[/url] on each variable in the echo.

Ken

Share this post


Link to post
Share on other sites
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.

Share this post


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

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?

Share this post


Link to post
Share on other sites

×

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.