Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

I can't for the life of me see whats wrong with this

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

I can't for the life of me see whats wrong with this

Postby Mh_0 » Mon Jan 20, 2003 7:07 am

heres the code

if ($saveuser) {

$sql = "UPDATE Passwords SET `username`='$username'";
$result = mysql_query($sql);

$result = mysql_query("SELECT * FROM Passwords ORDER by username ASC" ,$db);
while ($myrow = mysql_fetch_array($result)) {
if ($myrow[username] == $username) {
if ($password <> '$myrow[password]') {
$salt = substr($password, 0, 2);
$encrypted_pswd = crypt($password, $salt);
$sql = "UPDATE Passwords SET `password`='$encrypted_pswd'";
$result = mysql_query($sql);

The error is:

Warning: Supplied argument is not a valid MySQL result resource in /local/data/www/htdocs/OED/CruisePlan/users.php on line 82

line 82 is:

while ($myrow = mysql_fetch_array($result)) {

(just a note I can't turn off warnings in php.ini)

anybody got any ideas?

Thanks in advance!
New php-forum User
New php-forum User
Posts: 11
Joined: Thu Nov 14, 2002 7:13 am
Location: UK

Postby Redcircle » Wed Jan 22, 2003 12:05 am

sounds dumb but make sure your fields in your database are spelled correct and that you are trying to access the correct database. Usually if the query has an error in it you will receive that error.
User avatar
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby Nehle » Wed Jan 22, 2003 7:08 am

Shouldn't it be

Code: Select all

while ($myrow == mysql_fetch_array($result)) {

otherwise it wouldn't be a boolean statement, right?[/code]
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Jan 21, 2003 3:13 pm

Postby Hurkle » Wed Jan 22, 2003 8:32 am

I think your fetch array call is fine, and now, it shouldn't be ==, it's right as it is.

This might be the problem.. the line you have is..

$sql = "UPDATE Passwords SET `password`='$encrypted_pswd'";

I would instead try..

$sql = "UPDATE passwords SET password = '" . $encrypted_pswd . "'";

a couple of things here.. your field password had single quotes around it in the sql string, I've never seen that before. Also, when building sql strings, I've had the best luck with concatenating , i.e. string = "something" . $variable . "something else", rather than having the variable inside a double quoted string expression.

Last but not least, you might want to consider some different naming conventions to avoid confusion, and eliminate case as a possible error source.. for example, if you have a table object dealing with passwords, you might use tbl_passwords as a name. The field storing the password might be fld_password. all lowercase, with underscores instead of spaces, and a naming convention for objects and variables can simplify the process.

Ok, I rambled, please give the sql string a shot and let us know if it makes a difference.. best of luck.
New php-forum User
New php-forum User
Posts: 36
Joined: Tue Jan 07, 2003 8:45 am
Location: Minnesota, USA

Postby ppera » Wed Jan 22, 2003 8:34 am

User avatar
New php-forum User
New php-forum User
Posts: 11
Joined: Thu Jan 09, 2003 2:11 pm

Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.