Jump to content

displays resource ID #


webdogjcn

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
Link to comment
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'];
Link to comment
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.
Link to comment
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
Link to comment
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.
Link to comment
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?
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.