FreePgs.com Forum
October 18, 2017, 04:13:11 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Click Here for Toll-Free Service for your business starting at $2.00 per month and 4.5 cents per minute
 
   Home   Help Search Login Register  
Pages: [1] 2 3   Go Down
  Print  
Author Topic: ANybody good at SQL? I keep messing up  (Read 18414 times)
sixthcrusifix
Sage
Verified Account
Sr. Member
*

Karma: +0/-3
Offline Offline

Posts: 445


http://sixthcrusifix.com/home/

Blog entries (0)

View Profile WWW
« on: November 29, 2005, 08:13:56 PM »

$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

Code:
<?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";
?>


« Last Edit: November 29, 2005, 08:17:46 PM by sixthcrusifix » Logged

Visite me website at http://www.sixthcrusifix.com
webzone (archived)
Official Technical Support
Verified Account
Hero Member
*

Karma: +0/-0
Offline Offline

Posts: 508

Archived Account

Blog entries (0)

View Profile
« Reply #1 on: November 29, 2005, 08:26:15 PM »

Try this instead :

$SQL1 = 'UPDATE userbase SET password = \''.$NEW_PW.'\' WHERE username = \''.$lostpw.'\'';
Logged
FreePgs.com Forum
« Reply #1 on: November 29, 2005, 08:26:15 PM »

 Logged
sixthcrusifix
Sage
Verified Account
Sr. Member
*

Karma: +0/-3
Offline Offline

Posts: 445


http://sixthcrusifix.com/home/

Blog entries (0)

View Profile WWW
« Reply #2 on: November 29, 2005, 08:29:15 PM »

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???
Logged

Visite me website at http://www.sixthcrusifix.com
ghost
Toasty Warrior
Non-Verified Account
Full Member
***

Karma: +0/-0
Offline Offline

Posts: 148


I'm thirsty.

Blog entries (0)

View Profile WWW
« Reply #3 on: November 29, 2005, 08:31:01 PM »

$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());
Logged

- Ghost -
FreePgs.com Forum
« Reply #3 on: November 29, 2005, 08:31:01 PM »

 Logged
sixthcrusifix
Sage
Verified Account
Sr. Member
*

Karma: +0/-3
Offline Offline

Posts: 445


http://sixthcrusifix.com/home/

Blog entries (0)

View Profile WWW
« Reply #4 on: November 29, 2005, 08:37:46 PM »

$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.
Logged

Visite me website at http://www.sixthcrusifix.com
ghost
Toasty Warrior
Non-Verified Account
Full Member
***

Karma: +0/-0
Offline Offline

Posts: 148


I'm thirsty.

Blog entries (0)

View Profile WWW
« Reply #5 on: November 29, 2005, 08:42:57 PM »

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.
Logged

- Ghost -
sixthcrusifix
Sage
Verified Account
Sr. Member
*

Karma: +0/-3
Offline Offline

Posts: 445


http://sixthcrusifix.com/home/

Blog entries (0)

View Profile WWW
« Reply #6 on: November 29, 2005, 08:47:13 PM »

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
Logged

Visite me website at http://www.sixthcrusifix.com
ghost
Toasty Warrior
Non-Verified Account
Full Member
***

Karma: +0/-0
Offline Offline

Posts: 148


I'm thirsty.

Blog entries (0)

View Profile WWW
« Reply #7 on: November 29, 2005, 08:55:41 PM »

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?)
Logged

- Ghost -
sixthcrusifix
Sage
Verified Account
Sr. Member
*

Karma: +0/-3
Offline Offline

Posts: 445


http://sixthcrusifix.com/home/

Blog entries (0)

View Profile WWW
« Reply #8 on: November 29, 2005, 08:57:42 PM »

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.
Logged

Visite me website at http://www.sixthcrusifix.com
ghost
Toasty Warrior
Non-Verified Account
Full Member
***

Karma: +0/-0
Offline Offline

Posts: 148


I'm thirsty.

Blog entries (0)

View Profile WWW
« Reply #9 on: November 29, 2005, 08:58:52 PM »

Javascript popup box?
Logged

- Ghost -
sixthcrusifix
Sage
Verified Account
Sr. Member
*

Karma: +0/-3
Offline Offline

Posts: 445


http://sixthcrusifix.com/home/

Blog entries (0)

View Profile WWW
« Reply #10 on: November 29, 2005, 08:59:58 PM »

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. . .
Logged

Visite me website at http://www.sixthcrusifix.com
webzone (archived)
Official Technical Support
Verified Account
Hero Member
*

Karma: +0/-0
Offline Offline

Posts: 508

Archived Account

Blog entries (0)

View Profile
« Reply #11 on: November 29, 2005, 09:01:18 PM »

$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).
Logged
sixthcrusifix
Sage
Verified Account
Sr. Member
*

Karma: +0/-3
Offline Offline

Posts: 445


http://sixthcrusifix.com/home/

Blog entries (0)

View Profile WWW
« Reply #12 on: November 29, 2005, 09:02:07 PM »


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
Logged

Visite me website at http://www.sixthcrusifix.com
webzone (archived)
Official Technical Support
Verified Account
Hero Member
*

Karma: +0/-0
Offline Offline

Posts: 508

Archived Account

Blog entries (0)

View Profile
« Reply #13 on: November 29, 2005, 09:04:46 PM »

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);
Logged
sixthcrusifix
Sage
Verified Account
Sr. Member
*

Karma: +0/-3
Offline Offline

Posts: 445


http://sixthcrusifix.com/home/

Blog entries (0)

View Profile WWW
« Reply #14 on: November 29, 2005, 09:08:17 PM »

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 ./ . .
Logged

Visite me website at http://www.sixthcrusifix.com
Pages: [1] 2 3   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!