[SOLVED] JUST A FEW SECONDS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

[SOLVED] JUST A FEW SECONDS

Post by g3ckO »

Look at this: :)

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\userprofile.php on line 17

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\userprofile.php on line 18

Code: Select all

<?php
<?

session_start(); 
include("database.php");
include("login.php");
verify();//function to check session

$query="SELECT * FROM employee WHERE username = $_SESSION[username]";
$result=mysql_query($query);


include ("head.html");
echo "<left><b>$_SESSION[username]</b> Profile Management:</b> You can edit some of your personal info here.";



   $ID=mysql_result($result,"username");// HERE!! What should I put here
   $Pass=mysql_result($result,"password");
   
?>
   <hr>
   <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
   <center><b>*****************************************</b></font></center>
   <hr>
   <div align="center"><center>
   <table border="1" cellpadding="2" cellspacing="1" width="100%">
    	<tr>
        <td align="left" valign="bottom" width="30%"
            bgcolor="#FFFFFF" valign="TOP" marginwidth="12" marginheight="12">

            <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
            <b>Username</b></font>
        </td>
   <td align="left" valign="top" width="70%"
            bgcolor="#FFFFFF" marginwidth="12" marginheight="12">
	    
	    <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
            <b><?echo "$ID";?></b></font>
        </td>
    	</tr>
   </table>

   <div align="center"><center>
   <table border="1" cellpadding="2" cellspacing="1" width="100%">
    	<tr>
        <td align="left" valign="bottom" width="30%"
            bgcolor="#FFFFFF" valign="TOP" marginwidth="12" marginheight="12">

            <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
            <b>Password</b></font>
        </td>
   <td align="left" valign="top" width="70%"
            bgcolor="#FFFFFF" marginwidth="12" marginheight="12">
	    
	    <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
            <b><?echo "$Pass";?></b></font>
        </td>
    	</tr>
   </table>
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

Post by James M. »

I think theres an error in your query. If mysql_query turns up false, then you would have supplied an invalid arguement to mysql_result.

If the user has a apostrahpe in thier name, it will make an error.
i would recommend:

Code: Select all

<?php
$user=addslashes($_SESSION[username]);
$query="SELECT * FROM table WHERE user='user'";

?>
But the thing with that is you will have to wrap it in a function so that of the user refreshed the page it wouldn't add a slash where its not needed (recently found this out in my own script). Theres probably a better way to do hat but thats how i do it and it works fine.

And where user name and password are you have to put an INT value, not string.

go here: http://www.php.net/manual/en/function.mysql-result.php
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

you mean like this:

Code: Select all

<?php
<?

session_start(); 
include("database.php");
include("login.php");
verify();

$user=addslashes($_SESSION[username]); 
$query="SELECT * FROM employee WHERE username='user'"; 

include ("head.html");
echo "<left><b>$_SESSION[username]</b> Profile Management:</b> You can edit some of your personal info here.";



   $ID=mysql_result($result,"username");
   $Pass=mysql_result($result,"password");
   
?>
?>
I still get the error:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\userprofile.php on line 19

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\userprofile.php on line 20
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

Post by James M. »

well i think you should try this

Code: Select all

<?php
$result_rows=mysql_fetch_array($result);
$ID=$row_array['username]';
$Pass=$row_array['password'];
?>
but because everytime the page is refreshed the addslashes adds another slash, i would do somthing like this:

Code: Select all

<?php
function extract_user()
{
$user=addslashes($_SESSION[username]); 
$query="SELECT * FROM employee WHERE username='$user'"; 
$result=mysql_query($query, $link);
$row_array=mysql_fetch_array($result);
return $row_array;
}

include ("head.html"); 
echo "<left><b>$_SESSION[username]</b> Profile Management:</b> You can edit some of your personal info here."; 


$row_array=extract_user();
   $ID=$row_array['username']; 
   $Pass=$row_array['password']; 

?>
Last edited by James M. on Tue Jul 13, 2004 11:41 pm, edited 1 time in total.
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

I do like that:

Code: Select all

<?php
<?

session_start(); 
include("database.php");
include("login.php");
verify();

$user=addslashes($_SESSION[username]); 
$query="SELECT * FROM employee WHERE username='user'"; 

include ("head.html");
echo "<left><b>$_SESSION[username]</b> Profile Management:</b> You can edit some of your personal info here.";



   $result_rows=mysql_fetch_array($result); 
   $ID=$row_array['username']; 
   $Pass=$row_array['password']; 
   
?>
?>
And get this error message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\userprofile.php on line 16
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

Post by James M. »

did you start a mysql connection and do a mysql_query? Because in the code you show, you dont. And look at my post before this one again, i had to edit it.
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

getting more confuse rite now :)

this is my database.php

Code: Select all

<?php
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db('db1', $conn) or die(mysql_error());

?>
and this what I write on userprofile.php folowing what you suggested

Code: Select all

<?php
session_start(); 
include("database.php");
include("login.php");
verify();

 
function extract_user() 
{ 
$user=addslashes($_SESSION[username]); 
$query="SELECT * FROM employee WHERE username='user'"; 
$result=mysql_query($query, $link); 
$row_array=mysql_fetch_array($result); 
return $row_array; 
} 

include ("head.html"); 
echo "<left><b>$_SESSION[username]</b> Profile Management:</b> You can edit some of your personal info here."; 


$row_array=extract_user(); 
   $ID=$row_array['username']; 
   $Pass=$row_array['password']; 

 

   
?>
   <hr>
   <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
   <center><b>*****************************************</b></font></center>
   <hr>
   <div align="center"><center>
   <table border="1" cellpadding="2" cellspacing="1" width="100%">
    	<tr>
        <td align="left" valign="bottom" width="30%"
            bgcolor="#FFFFFF" valign="TOP" marginwidth="12" marginheight="12">

            <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
            <b>Username</b></font>
        </td>
   <td align="left" valign="top" width="70%"
            bgcolor="#FFFFFF" marginwidth="12" marginheight="12">
	    
	    <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
            <b><?echo "$ID";?></b></font>
        </td>
    	</tr>
   </table>

   <div align="center"><center>
   <table border="1" cellpadding="2" cellspacing="1" width="100%">
    	<tr>
        <td align="left" valign="bottom" width="30%"
            bgcolor="#FFFFFF" valign="TOP" marginwidth="12" marginheight="12">

            <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
            <b>Password</b></font>
        </td>
   <td align="left" valign="top" width="70%"
            bgcolor="#FFFFFF" marginwidth="12" marginheight="12">
	    
	    <font color="#671247" size="3" face="Verdana, Arial, Helvetica, sans-serif">
            <b><?echo "$Pass";?></b></font>
        </td>
    	</tr>
   </table>

 <form action="home.php" method="post">
   <input type="submit" value="Back" name="Back"><br></form>

?>
and this the error message again:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\apache\htdocs\userprofile.php on line 13

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\userprofile.php on line 14
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

Post by James M. »

I forgot, add the $ to the user in the query so it looks like this:

Code: Select all

$query="SELECT * FROM employee WHERE username='$user'";
sorry. And dont put the $link in mysql_query(), its habit for me.
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

still got eror msg:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\apache\htdocs\userprofile.php on line 13

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\userprofile.php on line 14
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

ok.. now its executed perfectly :)
Tq very much James
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

Post by James M. »

No prob. Sorry I wasnt clearer, too many mistakes on my part to. But try putting that function in an include file, maybe the database.inc file, you never know when you'll use it later on.
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

OK. TQ again.
Post Reply