Page 1 of 1

[SOLVED] JUST A FEW SECONDS

Posted: Tue Jul 13, 2004 10:21 pm
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>

Posted: Tue Jul 13, 2004 11:05 pm
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

Posted: Tue Jul 13, 2004 11:17 pm
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

Posted: Tue Jul 13, 2004 11:23 pm
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']; 

?>

Posted: Tue Jul 13, 2004 11:29 pm
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

Posted: Tue Jul 13, 2004 11:31 pm
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.

Posted: Tue Jul 13, 2004 11:43 pm
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

Posted: Tue Jul 13, 2004 11:46 pm
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.

Posted: Tue Jul 13, 2004 11:50 pm
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

Posted: Tue Jul 13, 2004 11:52 pm
by g3ckO
ok.. now its executed perfectly :)
Tq very much James

Posted: Tue Jul 13, 2004 11:55 pm
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.

Posted: Tue Jul 13, 2004 11:57 pm
by g3ckO
OK. TQ again.