News:

LVCS.NET offers low cost domain registration services.

Main Menu

ANybody good at SQL? I keep messing up

Started by sixthcrusifix, November 30, 2005, 01:13:56 AM

Previous topic - Next topic

sixthcrusifix

$SQL1="UPDATE 'userbase' SET password = \"$NEW_PW\" WHERE username =\"$lostpw\"";


what's wrong with that? I keep getting the die message!

here's the whole script. I KNOW that just setting somone's password to a random number is a bit cheap but they can change it and I'm lazy:
(userbase is the table, DATA is the Database)\

EDIT: Turns out onone of it works anymore since I re-uploaded it!?!??!?! I get this stuff:  Resource id #4Resource id #4 Resource id #3


<?php
if(isset($lostpw))
{
srand(microtime() * 1000000);
$NEW_PW rand(100000,999999);

$conn=@mysql_connect("localhost","sixthcrusifix","*******")or die("Sorry, Could Not Connect");
$DTB=@mysql_select_db(DATA,$conn) or die("Could Not Select Database");

$SQL1="UPDATE 'userbase' SET password = \"$NEW_PW\" WHERE username =\"$lostpw\"";

$result1=mysql_query($SQL1,$conn) or die("SORRY, password could not be reset");

$SQL="SELECT email
FROM `userbase`
WHERE username = \"
$lostpw\"";
$result=mysql_query($SQL,$conn) or die("SORRY, We can't find your new password");
$EMAIL=$result;
$SQL2="SELECT password
FROM `userbase`
WHERE username = \"
$lostpw\"";
$result2=mysql_query($SQL2,$conn)or die("SECOND QUERY FAILED");
$LPW=$result2;
$msg="$lostpw, your new password is $LPW. You may change your password in the User Control Panel";
mail($EMAIL,"Lost Password",$msg);
$ALERT1="<script> alert(\"Your Email Has Been Sent to $EMAIL\")</script>";
}
else{ 
$ALERT1="You Did NOt Define  A Username!"; }
#############################################################################################################
//The Below is the HEAD!

echo($ALERT1);

#############################################################################################################
//The below is the body
#############################################################################################################

include "defaultcss.php";
echo (
"
$BG_black

$table_1
$center
$main_category
$category

$tr
$content
$TS4
$ALERT1
$br 
$LPW$LPW
$EMAIL
$TS_end1
$bottom
$br
$tr_end
$main_bottom

$div_end
$table_end
"
)
?>

<?
######################################################################################################

//Below is the MAIN MENU (The default menu for ALL pages)
######################################################################################################
include "default_menu.php";
?>


Visite me website at http://www.sixthcrusifix.com

webzone (archived)

Try this instead :

$SQL1 = 'UPDATE userbase SET password = \''.$NEW_PW.'\' WHERE username = \''.$lostpw.'\'';

sixthcrusifix

Quote from: webzone on November 30, 2005, 01:26:15 AM
Try this instead :

$SQL1 = 'UPDATE userbase SET password = \''.$NEW_PW.'\' WHERE username = \''.$lostpw.'\'';

1. COOL! That worked.

BUT My otherstuff is wrong now. . . instead of the text from the fields it says "Resource ID#3" But it used to work. . what's resource ID???
Visite me website at http://www.sixthcrusifix.com

ghost

$SQL1 ="UPDATE userbase SET password ='$NEW_PW' WHERE username = '$lostpw' '';

You dont need double quotes on the variables.. just the outside, which makes it easier.

And if you want to actually see the error use this:

$result1=mysql_query($SQL1,$conn) or die(mysql_error());
- Ghost -

sixthcrusifix

Quote from: ghost on November 30, 2005, 01:31:01 AM
$SQL1 ="UPDATE userbase SET password ='$NEW_PW' WHERE username = '$lostpw' '';

You dont need double quotes on the variables.. just the outside, which makes it easier.

And if you want to actually see the error use this:

$result1=mysql_query($SQL1,$conn) or die(mysql_error());
Oh cool thanks.

I still don't knwo about the other stuff not working anymor ethough.
Visite me website at http://www.sixthcrusifix.com

ghost

Looks like it was just the way the line was written with those quotes.

mysql_error() will most likely be helpful in the future though.
- Ghost -

sixthcrusifix

Quote from: ghost on November 30, 2005, 01:42:57 AM
Looks like it was just the way the line was written with those quotes.

mysql_error() will most likely be helpful in the future though.


Now I'm getting a PHP error (WARNING blah blah, function mail expects perameter 1 to ba a string


Instead of getting the password and username it's returning resource id#3 for the password and resource id#4
Visite me website at http://www.sixthcrusifix.com

ghost

It would help if you copied and pasted the error as it shows up on the page. (Same page as before I'm guessing too?)
- Ghost -

sixthcrusifix

Quote from: ghost on November 30, 2005, 01:55:41 AM
It would help if you copied and pasted the error as it shows up on the page. (Same page as before I'm guessing too?)

yeah the source code is in the first post. I tried to copy it but I have to get rid of that javascript pop-up box.
Visite me website at http://www.sixthcrusifix.com

ghost

- Ghost -

sixthcrusifix

Quote from: ghost on November 30, 2005, 01:58:52 AM
Javascript popup box?

I made an alert and I forgot to take it down so I could copy the error. I figured out the prioblem.

Instead of getting the EMAIL from the EMAIL part of the table, it just gets "resource id#" everything else works. . .
Visite me website at http://www.sixthcrusifix.com

webzone (archived)

Quote from: ghost on November 30, 2005, 01:31:01 AM
$SQL1 ="UPDATE userbase SET password ='$NEW_PW' WHERE username = '$lostpw' '';

You dont need double quotes on the variables.. just the outside, which makes it easier.

My solution didn't use double quotes, but single quotes, this is why they had to be escaped. I agree that your solution is simpler, but mine is faster to process (single quotes are always faster).

sixthcrusifix


Resource id #3Resource id #3 Lost Password sixthcrusifix, your new password is 326671. You may change your password in the User Control Panel
^That's an echo of the variables^


Warning: mail() expects parameter 1 to be string, resource given in /fpgs/fpgshttpd/sixthcrusifix/lostpw.php on line 30
alert("Your Email Has Been Sent to Resource id #3")

Instead of RESOURCE ID#3 it should say an email adress
Visite me website at http://www.sixthcrusifix.com

webzone (archived)

I think I found your problem.

You are doing a query and using the value mysql_query returned directly. mysql_query only returns a resource identifier that is designed to be fetched afterwards.

Try this :
$query2=mysql_query($SQL2,$conn)or die("SECOND QUERY FAILED");
$result2=mysql_fetch_object($query2);
$LPW=$result2->password;

To free memory you could also add :
mysql_free_result($query2);

sixthcrusifix

Quote from: webzone on November 30, 2005, 02:04:46 AM
I think I found your problem.

You are doing a query and using the value mysql_query returned directly. mysql_query only returns a resource identifier that is designed to be fetched afterwards.

Try this :
$query2=mysql_query($SQL2,$conn)or die("SECOND QUERY FAILED");
$result2=mysql_fetch_object($query2);
$LPW=$result2->password;

To free memory you could also add :
mysql_free_result($query2);

okay lemmie try that ./ . .
Visite me website at http://www.sixthcrusifix.com