Billy T
07-22-2003, 09:11 PM
Hey all
can anyone tell me which part of this code will only work in php 4.3?
<?php
//Set showform flag to true
$showLogin = true;
$showform = false;
//Create empty array for errors
$errors = array();
//Check for submission of form
if($_POST['submit']) {
if($_SESSION['loggedIn']!="yep"){
//echo "not logged in code";
//check that username does not already exist
$checkUserName=$_POST['username'];
$checkPass=$_POST['pass'];
$crypt=md5($checkPass);
if($checkUserName != ""){
$dbHost = "sql";
$dbUser = "not";
$dbPass = "telling";
$dbName = "aDB";
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
@mysql_select_db($dbName);
$query = "SELECT * FROM subscribers WHERE username='$checkUserName' AND password='$crypt'";
// Execute Query
$result = mysql_query($query);
// If query was successful and there was a match
if ($result && @mysql_num_rows($result) > 0) {
//match found
while($row=mysql_fetch_array($result)){
//echo $row['paid'];
if($row['paid']=="true"){
$_SESSION['loggedIn']="yep";
$showLogin = false;
$showform=true;
}else{
$errors[] = "You need to be a paid subscriber.";
}//close else
}//close while
}else{
$errors[] = "There was an error with your login - please try again.";
}//end check num row
mysql_close($link);
}else{//end if username = ""
$errors[] = "Please enter a username";
}
if(count($errors) < 1) {
//Stick it in the database
$showLogin = false;
}
//if not logged in
}else{
//logged in and checking main form
$showLogin = false;
//echo "checked";
if($_POST['em1'] == "") $errors[] = "Please enter something for em1";
if($_POST['em2'] == "") $errors[] = "Please enter something for em2";
if(count($errors) > 0) {
//Stick it in the database
$showform = true;
}
}
}//if post
if ($showLogin == true) {
?>
<h2>Login to the EM form</h2>
<?php
//Check to see if the errors array is populated
if(count($errors)) {
print "<ul>";
foreach($errors as $key => $val) {
print "<li class='content'><p class='error'>$val</p></li>";
}
print "</ul>";
}//end of print errors
?>
<p class="content"> Please enter your <b>australian anthill</b> username and password.
</p>
<form class="subscribe" action="main.php?page=em_form" method="post">
<table cellpadding="10" cellspacing="10">
<tr><td align="right">
<div class="form"><b>Username:</b></div>
</td><td align="left">
<input name="username" type="text" class="box" title="Title" size="30" maxlength="30"></td></tr>
<tr><td align="right">
<div class="form"><b>Password:</b></div>
</td><td align="left">
<input name="pass" type="password" class="box" title="given name" size="30" maxlength="30">
</td></tr>
<tr><td align="left" valign="top">
</td><td align="right" valign="top">
<input type="submit" name="submit" value="Submit">
</td></tr>
</table>
</form>
<?php
//end of show login
} else {
//logged in
if($showform){
?>
<h2>EM form</h2>
<?
if(count($errors)) {
print "<ul>";
foreach($errors as $key => $val) {
print "<li class='content'><p class='error'>$val</p></li>";
}
print "</ul>";
} //end of print errors
?>
<form class="subscribe" action="main.php?page=em_form" method="post">
<table cellpadding="10" cellspacing="10">
<tr><td align="right">
<div class="form"><b>EM1:</b></div>
</td><td align="left">
<input name="em1" type="text" class="box" title="Title" size="30" maxlength="30"></td></tr>
<tr><td align="right">
<div class="form"><b>EM2:</b></div>
</td><td align="left">
<input name="em2" type="text" class="box" title="given name" size="30" maxlength="30">
</td></tr>
<tr><td align="left" valign="top">
</td><td align="right" valign="top">
<input type="submit" name="submit" value="Submit">
</td></tr>
</table>
</form>
<?
//end if showform
}else{
echo "all cool";
}
//end else
}
?>
cause it works in 4.3 but not in 4.2
Thanks
can anyone tell me which part of this code will only work in php 4.3?
<?php
//Set showform flag to true
$showLogin = true;
$showform = false;
//Create empty array for errors
$errors = array();
//Check for submission of form
if($_POST['submit']) {
if($_SESSION['loggedIn']!="yep"){
//echo "not logged in code";
//check that username does not already exist
$checkUserName=$_POST['username'];
$checkPass=$_POST['pass'];
$crypt=md5($checkPass);
if($checkUserName != ""){
$dbHost = "sql";
$dbUser = "not";
$dbPass = "telling";
$dbName = "aDB";
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
@mysql_select_db($dbName);
$query = "SELECT * FROM subscribers WHERE username='$checkUserName' AND password='$crypt'";
// Execute Query
$result = mysql_query($query);
// If query was successful and there was a match
if ($result && @mysql_num_rows($result) > 0) {
//match found
while($row=mysql_fetch_array($result)){
//echo $row['paid'];
if($row['paid']=="true"){
$_SESSION['loggedIn']="yep";
$showLogin = false;
$showform=true;
}else{
$errors[] = "You need to be a paid subscriber.";
}//close else
}//close while
}else{
$errors[] = "There was an error with your login - please try again.";
}//end check num row
mysql_close($link);
}else{//end if username = ""
$errors[] = "Please enter a username";
}
if(count($errors) < 1) {
//Stick it in the database
$showLogin = false;
}
//if not logged in
}else{
//logged in and checking main form
$showLogin = false;
//echo "checked";
if($_POST['em1'] == "") $errors[] = "Please enter something for em1";
if($_POST['em2'] == "") $errors[] = "Please enter something for em2";
if(count($errors) > 0) {
//Stick it in the database
$showform = true;
}
}
}//if post
if ($showLogin == true) {
?>
<h2>Login to the EM form</h2>
<?php
//Check to see if the errors array is populated
if(count($errors)) {
print "<ul>";
foreach($errors as $key => $val) {
print "<li class='content'><p class='error'>$val</p></li>";
}
print "</ul>";
}//end of print errors
?>
<p class="content"> Please enter your <b>australian anthill</b> username and password.
</p>
<form class="subscribe" action="main.php?page=em_form" method="post">
<table cellpadding="10" cellspacing="10">
<tr><td align="right">
<div class="form"><b>Username:</b></div>
</td><td align="left">
<input name="username" type="text" class="box" title="Title" size="30" maxlength="30"></td></tr>
<tr><td align="right">
<div class="form"><b>Password:</b></div>
</td><td align="left">
<input name="pass" type="password" class="box" title="given name" size="30" maxlength="30">
</td></tr>
<tr><td align="left" valign="top">
</td><td align="right" valign="top">
<input type="submit" name="submit" value="Submit">
</td></tr>
</table>
</form>
<?php
//end of show login
} else {
//logged in
if($showform){
?>
<h2>EM form</h2>
<?
if(count($errors)) {
print "<ul>";
foreach($errors as $key => $val) {
print "<li class='content'><p class='error'>$val</p></li>";
}
print "</ul>";
} //end of print errors
?>
<form class="subscribe" action="main.php?page=em_form" method="post">
<table cellpadding="10" cellspacing="10">
<tr><td align="right">
<div class="form"><b>EM1:</b></div>
</td><td align="left">
<input name="em1" type="text" class="box" title="Title" size="30" maxlength="30"></td></tr>
<tr><td align="right">
<div class="form"><b>EM2:</b></div>
</td><td align="left">
<input name="em2" type="text" class="box" title="given name" size="30" maxlength="30">
</td></tr>
<tr><td align="left" valign="top">
</td><td align="right" valign="top">
<input type="submit" name="submit" value="Submit">
</td></tr>
</table>
</form>
<?
//end if showform
}else{
echo "all cool";
}
//end else
}
?>
cause it works in 4.3 but not in 4.2
Thanks