zero-perfoliate
zero-perfoliate

Author Topic: PHP and mysql help  (Read 302 times)

Offline pcw

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
PHP and mysql help
« on: February 25, 2009, 07:21:09 AM »
Hi, I am writing a registration script. So far I have got a registration page. Once the user has registered, it sends a registration email and generates a 5 letter PIN code. The users details along with the PIN, are saved to a mysql database. The next step is for a user to enter the PIN that was emailed to them, before the script allows them to proceed. If they enter the wrong PIN, then a error message should be displayed instead.

This is what I have got. Currently it just shows a blank page once submitted. If I add an } else { print "PIN incorrect"; it just says the PIN is correct all the time. I have been stuck on this for the past day, any help is much appreciated.

Code: [Select]
if (isset($_POST['submit'])) {

   $db = "moveitho_sitebuilder";

  mysql_connect('localhost', 'moveitho_paul', 'test') or die(mysql_error());
  mysql_select_db( $db) or die(mysql_error());
 
   $username = mysql_real_escape_string($_POST['username']);
  $gen_id = mysql_real_escape_string($_POST['gen_id']);

  if ($result = mysql_query("SELECT username, gen_id FROM users WHERE username='$username' AND gen_id='$gen_id'")) {
    if (mysql_num_rows($result)) {
      echo "PIN matched";
    }
  }

}

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: PHP and mysql help
« Reply #1 on: February 25, 2009, 03:18:06 PM »
try this instead:

Code: [Select]
<?php
if (isset($_POST['submit'])) {

   
$db "moveitho_sitebuilder";

  
mysql_connect('localhost''moveitho_paul''test') or die(mysql_error());
  
mysql_select_db$db) or die(mysql_error());
  
   
$username mysql_real_escape_string($_POST['username']);
  
$gen_id mysql_real_escape_string($_POST['gen_id']);

  if (
$result mysql_query("SELECT username, gen_id FROM users WHERE username='$username' AND gen_id='$gen_id'")) {
    if (
mysql_num_rows($result) == 1) {
      echo 
"PIN matched";
    }
  }

}
?>


 

zero-perfoliate