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!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I get the following error:
Warning: mysql_data_seek(): Offset 0 is invalid for MySQL result index 2 (or the query data is unbuffered)
mysql_data_seek is used in a function (made not by me, found on php.net) which i know 500% that it works for other queries:
"select * from accounts where email = '" . mysql_real_escape_string($_POST['email']) . "' and pass = '" . mysql_real_escape_string($_POST['pass']) . "'"
So the outcome would be (if username is a@a.com and password 1):
select * from accounts where email = 'a@a.com' and pass = '1'
What the query obviously does is it looks whether there is a data row in the db with that email and pass (if he is registered AND if the pass corresponds to the email)
Any suggestions?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by UrButtFullOfArr0ws on Thu Feb 22, 2007 1:43 pm, edited 1 time in total.
When i executed from mysql console, with the exact cases, letters, spaces, complete copy except mysql_real_escape_string() the query came out ok and it gave result of course.
Also PHP didn't return any MySQL warnings/errors about the query.
<?php
function mysql_fetch_all($result) { //the function
$return = array();
mysql_data_seek($result, 0);
while ($row = mysql_fetch_assoc($result)) {
$return[] = $row;
}
return $return;
}
// Set some vars
$email = mysql_real_escape_string($_POST['email']);
$pass = mysql_real_escape_string($_POST['pass']);
//the actual query
$sql = "SELECT *
FROM `accounts`
WHERE `email` = '$email'
AND `pass` = '$pass'";
//execute the query
$res = mysql_query($sql, $con) or die('Error in the query: ' . mysql_error());
//call the function
$bigarray = mysql_fetch_all($res);
?>
Thx but unfortunately didn't work
On first glance i didn't believe it was going to do much anyway couse i got the same way of writing the query in some other files too. All of the others seem to work fine.
At some point however the fact it might have something to do with the database and not with the query itself crossed my mind.
Any other suggestions?
You are not getting results because your query is empty. That is why you were getting an undefined offset. You were telling PHP to move the result pointer to a position that didn't exist. I would seriously consider doing a var_dump() after reading the result into an array with mysql_fetch_array().
$res = mysql_query($sql, $con) or die('Error in the query: ' . mysql_error());
echo '<p># result for "', $sql, '": ', mysql_num_rows($res), "</p>\n";
$bigarray = mysql_fetch_all($res);