Jump to content

need help with Resource id #5???


Pyro4816

Recommended Posts

[code]<?php
session_start();
$user = $_POST['user'];
$pass = $_POST['pass'];
include('includes/dbconnector.php');
$connector = new DbConnector();
$query = $connector->query("SELECT user,pass FROM members WHERE user=' $user '");
$row = $connector->fetchArray($query);
{
echo $query;
}[/code]
OK, I have that code, i use a login to send the post  vars to the script, but instead of echoing the username and pass in the DB, it echos and i quote "Resource id #5" and i am not sure why. Now, i am new to php, so please explain it in non "industry" language.

Thank you.
Link to comment
https://forums.phpfreaks.com/topic/28437-need-help-with-resource-id-5/
Share on other sites

To check the result, you may use 'while' loop.


[code]
<?php
session_start();
$user = $_POST['user'];
$pass = $_POST['pass'];
include('includes/dbconnector.php');
$connector = new DbConnector();
$query = $connector->query("SELECT user,pass FROM members WHERE user=' $user '");
while($row = $connector->fetchArray($query))
{
print_r($row);
}
[/code]

You have to show class in "dbconnector.php" for more info.
ok, this is kinda hard not seeing the full code from the class
but You normally get Resorce 5 by echoing the query

Which I can see your doing there

You want a while loop for the $row

while($row = $connector-:fetchArray($query){
$fieldname = $row["DBFIeldName"];
}
onlyican, i tryed it like this:
[code]<?php
session_start();
$user = $_POST['user'];
$pass = $_POST['pass'];
include('includes/dbconnector.php');
$connector = new DbConnector();
$query = $connector->query("SELECT user,pass FROM members WHERE user=' $user '");
while($row = $connector->fetchArray($query)){
$fieldname = $row["user"];
}[/code] but still no change, it still comes up blank, and i am 100% sure that the user in the post var is in the database, i checked it myself.
[code]function DbConnector(){
$settings = SystemComponent::getSettings();
$host = $settings['dbhost'];
$db = $settings['dbname'];
$user = $settings['dbusername'];
$pass = $settings['dbpassword'];
$this->link = mysql_connect($host, $user, $pass);
mysql_select_db($db);
register_shutdown_function(array(&$this, 'close'));
}[/code]
this is what you mean, right?
Try this hombre

[code]
<?php
$query = $connector->query("SELECT user,pass FROM members WHERE user = '".$user."'");
if(mysql_num_rows($query) != 0){

while($row = $connector->fetchArray($query)){

echo $row["user"]."<br />\n";
}
}else{
echo "There are no results in the DB";
}
?>
[/code]

Archived

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

×
×
  • 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.