0

just a simple question. How can I show 1 specific error from this?

$search_query = mysql_query("SELECT * FROM users WHERE username = '$username' OR email = '$email'");
$num_row = mysql_num_rows($search_query);
if($num_row >= 1){
    $errors['username'] = "username is unavailable.";
    $errors['email'] = "Email address is unavailable.";
}else
{//insert.....

They both show the error, but not working with $username.

Just can't figure it out.

And if it's not asking too much, can you please add if the username/email is available?

Thanks in advance.

I'll put the $errors after the input tag:

                    <p>username:</p>
                    <input type="text" name="username" id="username" value="<?php if(isset($_POST['username'])){echo $_POST['username'];} ?>">
                    <?php if(isset($errors['username'])){echo "<h5>" .$errors['username']. "</h5>"; } ?></td>
            </tr>
                <td><p>email:</p>
                    <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])){echo $_POST['email'];} ?>">
                    <?php if(isset($errors['email'])){echo "<h5>" .$errors['email']. "</h5>"; } ?></td>
            </tr>
6
  • umm... echo $errors....? Commented Jan 22, 2017 at 18:54
  • oops sorry @Fred-ii- ill edit it where i print my errors :) Commented Jan 22, 2017 at 18:55
  • any errors from error reporting? and look at your html source and check for errors on the query Commented Jan 22, 2017 at 18:58
  • Do you mean you want to know which column matched? e.g. what is unavailable. Commented Jan 22, 2017 at 19:47
  • 1
    Select your 2 columns and do a check in PHP, or you do do a case in mysql. Commented Jan 23, 2017 at 4:21

1 Answer 1

3
 mysql_query() or die(mysql_error());

like

$search_query = mysql_query("SELECT * FROM users WHERE username = '$username' OR email = '$email'") or die(mysql_error());

And

  $num_row = mysql_num_rows($search_query)or die(mysql_error());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.