Page 1 of 1

PHP newbie problem - Code

Posted: Wed Sep 22, 2010 12:23 pm
by MattH_PHP
pickle | Please use [ syntax=php ], [ syntax=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi all,

I'm banging my head against a brick wall again with some code. The code is basically for a login page whereby the PHP code check with my DB if the membership card and email address exist. If so, users can get access. All i've done is update another php file that is working fine.

The first part of the code ensures users fill in all the correct details. When i click submit, i constantly get the error:

You did not enter one or more of the required fields. Please go back and try again

Is my PHP wrong or could it be the HTML code on the actual logon page? The PHP is below:

Code: Select all

<?php
include("global.inc.php");
pt_register('POST','Emailaddress');
pt_register('POST','TWnumberfoundonmembershipcard');
if($emailaddress=="" || $TWnumberfoundonmembershipcard==""){
die('You did not enter one or more of the required fields. Please go back and try again');
}
if ($_POST['TWnumberfoundonmembershipcard'] < "TW60006000" || $_POST['TWnumberfoundonmembershipcard'] > "TW60011000") {
die('The TW number you have entered is not valid. Please click the back button and ensure you have entered your Think White membership card number correctly and that TW is in upper case.');
}
$link = mysql_connect("localhost","dbuser","dbpassword");
mysql_select_db("thinkwh_frgn1",$link);
$login_query = "SELECT * FROM users WHERE email_address = '$emailaddress' AND TW_number_found_on_membership_card = '$TWnumber'";
$res = mysql_query($login_query);
if (mysql_num_rows($res) < 1) 
die('The details you have entered do not match a registered email address/TW number combination. Please click the back button and re-enter your details');
if (mysql_num_rows($res) == 1) 
die('congrats, you are in!');
?>

This is the HTML code for the login page:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style2 {
	color: #FFF;
	font-family: Verdana, Geneva, sans-serif;
	font-size: 18px;
}
.style2 font {
	font-size: 14px;
}
-->
</style>
<form action='../Login/twlogin.php' method='GET' enctype='multipart/form-data'>
  <table width="835" height="277" border="1" align="center" bordercolor="#000000">
    <tr bgcolor="#000000">
      <td width="230" height="271"><img src="../activate/WHITE 230X140.jpg" width="230" height="140" align="absmiddle" /></td>
      <td width="589"><table width="100%" border="1" align="left" cellpadding="5" cellspacing="1" bordercolor="#000000"                       bgcolor="#000000" style="border-collapse: collapse; font-family: Verdana, Geneva, sans-serif;">
        <tr bordercolor="#000000" bgcolor="#000000">
          <td height="17" colspan="3" bordercolor="#000000"                       background="../Library/Caches/TemporaryItems/Transmit/.tmp_ocggmu/tile_back.gif" bgcolor="#000000"><p align="left"><b><font face=" class="                size="2" color="#FFFFFF"><font face='Verdana' size=2>
            
            
          </font>Think White Membership Login </p></td>
        </tr>
        <tr bgcolor="#000000">
          <td height="16" colspan="3" bordercolor="#000000"                      ><span class="style1"><font size="1" face="Verdana">Please fill in all fields marked with *</font></span></td>
        </tr>
        <tr>
          <td width="320" height="30" bordercolor="#000000" bgcolor="#000000"                      ><span class="style1">Email address</span></td>
          <td height="30" bordercolor="#000000" bgcolor="#000000"                      ><font face="Verdana">
            <input type=text name='Emailaddress' />
            <span class="style1"> *</span></font></td>
        </tr>
        <tr>
          <td width="320" height="30" nowrap="nowrap" bordercolor="#000000"                       bgcolor="#000000"><span class="style1">TW number on membership card</span></td>
          <td height="30" bordercolor="#000000" bgcolor="#000000"                      ><font face="Verdana">
            <input type=text name='TWnumberfoundonmembershipcard' />
            <span class="style1"> *</span></font></td>
        </tr>
        <tr                       bgcolor="#000000">
          <td height="25" colspan="3" bordercolor="#000000"><p align="center"><font face="Verdana" size="2">
            <input name="submit" type=submit value='Submit' />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="reset" type=reset value='Reset Form' />
          </font></p></td>
        </tr>
      </table></td>
    </tr>
  </table>
</form> <br><br><a href='http://phpformgen.sourceforge.net'></a>
Any pointers would be greatly appreciated and thanks in advance!

Matt



pickle | Please use [ syntax=php ], [ syntax=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: PHP newbie problem - Code

Posted: Thu Sep 23, 2010 1:30 am
by cpetercarter
Hint - 'emailaddress' and 'Emailaddress' are not the same.

What is this 'pt_register()' function? This, I guess. As you will see from the comments in the link, it is unnecessary (and, in some contexts, dangerous). Why not:

Code: Select all

if (empty($_POST['Emailaddress']) || empty($_POST['TWnumberfoundonmembershipcard']))
{
    die('You did not enter one or more of the required fields. Please go back and try again');
}

Re: PHP newbie problem - Code

Posted: Thu Sep 23, 2010 10:07 am
by MattH_PHP
pickle | Please use [ syntax=php ], [ syntax=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Right, it's still not working and i'm not sure why. This is the new simplified html code:

Code: Select all

<form action="checklogin.php" method="post">
Email Address <input type="text" name="emailaddress" />
TW Membership Number: <input type="text" name="twnumber" />
<input type="submit" />
</form>
This is the PHP code:

Code: Select all

<?php
if(empty($_POST["emailaddress"]) || empty($_POST["twnumber"])){
die('You did not enter one or more of the required fields. Please go back and try again.');
}
if ($_POST["twnumber"] < "TW60006000" || $_POST["twnumber"] > "TW60011000") {
die('The TW number you have entered is not valid. Please click the back button and ensure you have entered your Think White membership card number correctly and that TW is in upper case.');
}
$link = mysql_connect("localhost", "dbuser", "dbpassword");
mysql_select_db("thinkwh_frgn1",$link);
$query = "SELECT * FROM users WHERE Email_address = '$emailaddress' and TW_number_found_on_membership_card = '$twnumber'";
$res = mysql_query($query);
if (mysql_num_rows($res) >= 1)
die('testloginsuccess');
?> 
<html>
<body>
Number not found
</body>
</html>
Even though my html fields are filled in, i still get a message saying you did not enter one or more of the required fields. Please go back and try again.

Can somebody help me?


pickle | Please use [ syntax=php ], [ syntax=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.