0

I'm trying to create a page that handles something like existing username. This is what I've got so far .

<?php 
// Parse the form data and add inventory item to the system

if (isset($_POST['username'])) {

    $username = ($_POST['username']);
    $password = ($_POST['password']);

    $level = ($_POST['level']);
    // See if that product name is an identical match to another product in the system
    $sql = mysql_query("SELECT id FROM users WHERE username='$username' LIMIT 1");
     include "storescripts/connect_to_mysql.php"; 
    $productMatch = mysql_num_rows($sql); // count the output amount
    if ($productMatch > 0) {
           header("location: message.php?msg=activation_failure");
        exit();
    }
    // Add this product into the database now
    $username = preg_replace('#[^a-z0-9]#i', '', $_POST['username']);
    $email = mysql_real_escape_string($_POST['email']);
    $p_hash = md5($password);
    $sql = mysql_query("INSERT INTO users (username, password, email, level, date_added) 
        VALUES('$username','$p_hash','$email','$level',now())") or die (mysql_error());
    header("location: order_complete.php"); 
    exit();
}
?>

The if statement queries mysql to determine if there is a match between form entry and database. Then I'd like to go to message.php with a message like ...this username already exists. Any tips on how to do this or how to approach it is greatly appreciated.

Further clarification..form starts :

<form action="user-info.php" enctype="multipart/form-data" name="signupform" id="signupform" method="post">

and message.php

<?php
$message = "";
$msg = preg_replace('#[^a-z 0-9.:_()]#i', '', $_GET['msg']);
if($msg == "sorryuser"){
$message = 'No good';
} else if($msg == "activation_success"){
$message = 'test';
} else {
$message = $msg;
}
?>

<?php include_once("./includes/site-opener.php");?>
<title></title>
</head>
<body id="home">

            <?php include 'includes/header.php'; ?>
<?php include 'includes/content-opener.php'; ?>
            <div class="containOthers">
    <div style="width:300px;margin-left:auto;margin-right:auto;margin-bottom:40px;min-height:500px;">
<div><?php echo $message; ?><?php echo $emailError; ?></div>
</div>

            </div>
            <?php include 'includes/footer.php'; ?>



</body>
</html>

This is the error on user-info.php after form submission.

Warning: mysql_query(): Access denied for user 'onlinfaa'@'localhost' (using password: NO) in /home3/onlinfaa/public_html/user-info.php on line 18 Warning: mysql_query(): A link to the server could not be established in /home3/onlinfaa/public_html/user-info.php on line 18 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home3/onlinfaa/public_html/user-info.php on line 20 Duplicate entry 'test-email@aol.com' for key 'username'

Chris
  • 67
  • 1
  • 7

1 Answers1

0

is the user "onlinfaa" in your mysql? and it has all privileges on this database, maybe you should execute "grant all privileges on YOURDB.* to onlinfaa@localhost" and flush privileges

xu01
  • 21
  • 1
  • This user does have all privileges. @xu01 I use this for other areas. I believe the issue is with the query to determine num rows, but Ican't figure out how to resolve it . The "$productmatch" – Chris Jul 23 '13 at 02:51