Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-16-2005, 01:49 PM Some Help please...
harry19's Avatar
Experienced Talker

Posts: 42
Location: India
Trades: 0
I'm trying to incorporate an invitation system in VBulletin. What I'm doing is;

1. Generating a invitation code using MD5 and emailing user. Invite.php generates md5 and puts it in database.
2. When user gets the link and clicks on it, he's taken to confirm.php where the hash is checked and he's forwarded to registration page. Also the hash is deleted from database so the invitation cannot be reused.

Here's the code

PHP Code:
<?php
//confirm.php
//Check and confirm hash and redirect to registration
mysql_connect("localhost","*****","***")
or die(
"Failure to connect to the database");
$hash=$_GET['hash'];
$email=$_GET['email]'];
$query="SELECT hash
        FROM invite
        WHERE hash='
$hash'";
$result=mysql_query($query);
if (
$result $hash ){
  echo 
'$result';
  
//Now it's confirmed. So let's forward the user to registration page
  //First deleting the hash
  
$delquery="DELETE hash
             FROM invite
             WHERE hash='
$hash'";
  
header("Location: http://fizz.fonzter.com/register.php");
  exit;
  }
else {
  echo 
"Error--Hash not found!";
  }
?>
PHP Code:
<?php
//Invite.php
//Create and insert invitation hash
mysql_connect("localhost","*******","******")
or die(
"Failure to connect to the database");
$supersecret_hash_padding='A string that will pad the super secrect hash making it really secret';
$name=$_POST['name'];
$email=$_POST['email'];
$encoded_email=urlencode($_POST['email']);
$hash=md5($email.$supersecret_hash_padding);
$query="INSERT INTO invite (ID,hash) VALUES(NULL,'$hash')";
$msg=<<< BODY
Hello $name,
Your friend 
$username has sent you an invitation to join FiZZ Club. Kindly click the link below to accept the invitation.
http://fizz.fonzter.com/confirm.php?hash=
$hash&email=$encoded_email
BODY;
//Let's send the email now
  
$encoded_email=urlencode($_POST['email']);
mail ($email'Invitation'$msg'invitation@fizz.in');
  
//Confirmation message
  
$feedback='You have successfully sent an invite';
  return 
$feedback;
   
?>
But this is just not working at all for me. Can someone guide me through please. I'm a newbie to PHP and MYSQL
__________________

Please login or register to view this content. Registration is FREE

Last edited by 0beron; 09-16-2005 at 02:04 PM.. Reason: Added [php] tags and scrubbed db passwords
harry19 is offline
Reply With Quote
View Public Profile Visit harry19's homepage!
 
 
Register now for full access!
Old 09-16-2005, 02:09 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
PHP Code:
if ($result $hash ){ 
^ This is part of your problem.
For a start, you must use == (equality test) instead of = (assignment) when comparing things, and also $result is not a string, it is a fragment of database table. (In this case the fragment probably only contains one string, but it is still a database result). In this situation, I would simply say:

PHP Code:
$count mysql_num_rows($result);
if(
$count 0) {
  echo 
"Hash matched";
}else {
  echo 
"No match.";

mysql_num_rows($result) counts the rows in that table fragment I was on about. If the hash was correct, there will e one row, if it didn't there will be 0 rows. There are other mysql functions such as mysql_result() and mysql_fetch_array that retrieve the database contents themselves so you can use them as strings or numbers, but you don't need them here.

Other problems include the fact that you put three queries into strings, but only actually execute one of them with mysql_query(). You must do this for all of them or else your SQL commands just sit there in the string doing nothing.

I can't see what you do with the variable $encoded_email if anything.

There's a return statement at the end - what is this meant to do? Where are you returning to/from? This is usually used when returning from functions, and you don't define any in your scripts.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)

Last edited by 0beron; 09-16-2005 at 02:14 PM..
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 09-16-2005, 02:26 PM hey thanks for this
harry19's Avatar
Experienced Talker

Posts: 42
Location: India
Trades: 0
thanks for this man! also whats wrong with delete?
__________________

Please login or register to view this content. Registration is FREE
harry19 is offline
Reply With Quote
View Public Profile Visit harry19's homepage!
 
Old 09-16-2005, 02:35 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Ah, you mean this:
Code:
DELETE hash
             FROM invite
             WHERE hash='$hash'
?

You can't delete one field from a row, you can only delete the whole row. (You can of course set the one field to be empty, but you can't delete bits like this otherwise your database wouldn't be rectangular any more!)

Change it to
Code:
DELETE FROM invite WHERE hash='$hash'
One other thing I thought of to avoid possible confusion - in PHP, assignment is = and equality test is ==. In mySQL = is used for both, but this is OK since mySQL knows by context what you mean. In a WHERE section it is equality test, but in an update query it can be an assignment. In PHP, there are situations where you can legally use either version, but get totally different effects - as a result you need to tell PHP which one you want by using the right one.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 09-16-2005, 02:51 PM
harry19's Avatar
Experienced Talker

Posts: 42
Location: India
Trades: 0
thanks a ton!
__________________

Please login or register to view this content. Registration is FREE
harry19 is offline
Reply With Quote
View Public Profile Visit harry19's homepage!
 
Old 09-18-2005, 07:17 AM
harry19's Avatar
Experienced Talker

Posts: 42
Location: India
Trades: 0
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
I get this error.
__________________

Please login or register to view this content. Registration is FREE
harry19 is offline
Reply With Quote
View Public Profile Visit harry19's homepage!
 
Old 09-20-2005, 03:52 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
that just means the supplied argument is not correct in the
$count = mysql_num_rows($result);
i would imagine that you have a string without apostrophes around it but try on the line before mysql_num_rows($result); do

echo $result;
exit;

if you cannot see the problem in the output then plz post the result of the echo and the mysql_num_rows line + a few lines before it
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Reply     « Reply to Some Help please...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44122 seconds with 12 queries