TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-19-2009, 05:13 AM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2009
Posts: 19
Thanks: 9
shankar is on a distinguished road
Default Whats the error?

<?php

session_start();

$username=$_SESSION['username'];
$fname;
$lname;
$guardian;
$connect = mysql_connect("localhost","root","") or die ("Couldn't connect");
mysql_select_db("school_inspirations") or die("Couldn't find db");

$fname = mysql_query("SELECT fname FROM student_reg WHERE username='$username'");
mysql_query($fname);


$guardian = mysql_query("SELECT guardian FROM student_reg WHERE username='$username'");
mysql_query($guardian);


?>

<table border=1px;>

<tr>
<td>
Fullname
</td>
<td>
<?php echo "$fname"; ?>
</td>
</tr>

</table>




The ouput in the table is
Resource id #3
__________________
--
Regards
Shankar
shankar is offline  
Reply With Quote
Old 04-19-2009, 09:37 AM   #2 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default

wouw dude, hold on.

Please read once over your code:


Quote:
$fname = mysql_query("SELECT fname FROM student_reg WHERE username='$username'");
mysql_query($fname);
you are making a mysql_query -> and save the result int $fname.
then you trigger a mysql_query from the result you got from the sql query:

the code should look like that:

PHP Code:
//make a sql_query and save the result from that into $result
$resultmysql_query("SELECT `fname` FROM `student_reg` WHERE `username` = '$username'");

//next we need to fetch the data out of our result. Now it depends on what you want to do next with the data you received. Any of the below code could be right  -  depending on your what you wanna do with it

$array mysql_fetch_array($result); //would save result in a array
$objectmysql_fetch_object($result); //would save it into a object

$associativeArray mysql_fetch_assoc($result);

$field mysql_fetch_field($result); //get a single field

//next give out e.g.

echo $array['fname'];
echo 
$object->fname;

//...... 
Read that up on php.net or elsewhere ;) Then you understand best...

Your error means simply that you dont have an string available - so you cannot print/echo it
Sakakuchi is offline  
Reply With Quote
Old 04-19-2009, 11:24 AM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

@up- Better for the query part is to use it like this:
PHP Code:
$resultmysql_query("SELECT `fname` FROM `student_reg` WHERE `username` = '" $username "'"); 
@topicstarter- Please use php code tags [php] and also you don't have to post it on 3 places.
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error handling Ross TalkPHP Developer Team 0 01-17-2009 10:27 PM
Can't solve browser error Peuplarchie Absolute Beginners 1 06-09-2008 05:48 AM
Keep getting mySQL error No. 1064, but i can't seem to find the problem Durux MySQL & Databases 8 04-13-2008 07:51 PM
an error makes me crazy nuts !!!!!!! webtuto Absolute Beginners 1 02-27-2008 10:31 AM
HTTP 500 error... kunoSTAR Absolute Beginners 15 08-05-2005 08:13 PM


All times are GMT. The time now is 08:31 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design