PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
If your second example isn't working, you're passing a variable which is not a valid mysql result resource (what's returned by mysql_query). Check if you're not getting an error (var would be FALSE).
Check the query (print it). $_POST['username'] should be in quotes ( ' ) and escaped. If you still get error, check if mysql_query doesn't return FALSE. If so, check what does MySQL say about the error.
<?php
//notice error checking
$rowCheck = mysql_query("select username from user_details where username = '".$_POST['username']."'") or die(mysql_error());
//check to see if valid resource
echo $rowCheck;
//should return something like Rescource #1 if valid
?>
<?php
ob_start();
require_once('includes/link.php');
include("includes/funclib.inc");
if(isset($_GET['action'])) //variable set by URL on index.php
{
if($_GET['action'] == 'page_1')
{
$redirect = "redirect_page_1.php";
}
if($_GET['action'] == 'page_2')
{
$redirect = "redirect_page_2.php";
}
if($_GET['action'] == 'page_3')
{
$redirect = "redirect_page_3.php";
}
if($_GET['action'] == 'page_4')
{
$redirect = "redirect_page_4.php";
}
}
if(isset($_POST['formsubmit'])) //run when form submitted
{
$error_header = "The following errors occurred, please correct them<br>";
if(!$_POST['email'])
{
$error_msg = "Please Fill in the email field<br>";
}
if(!$_POST['password'])
{
$error_msg .= "Please fill in the password field<br>";
}
if(strlen($password) >
{
$error_msg .= "Your password must be less than 8 characters<br>";
}
if (!preg_match('/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/',$login))
{
$error_msg .= "Please enter a valid email address<br>" ;
}
$rowCheck = mysql_query("select username from user_details where username = '".$_POST['username']."'") or die(mysql_error()); // check for duplicate rows
if (mysql_num_rows($rowCheck) > 0)
{
$error_msg .= "This email address has already been used, If you would like to make another application, please contact us by telephone";
}
if(!$error_msg) // run this if no errors
{
cleanMemberSession($id, $login, $password); //set session variables
mysql_select_db($database_pdb_conn, $link);
$result=mysql_query("insert into user_details (username, password)
values('$login', '$pass')") or die(mysql_error());
header("Location: ".$redirect);
}
}
?>