Jump to content

random & loop problem


robert_gsfame

Recommended Posts

I have 3 tables (table1,table2,table3)

 

and i want to insert $username which is firstname.md5(uniqid(rand())

 

but the problem is that i want to check it first whether this $username exists in among those 3 tables.

 

if not exists then goes to INSERT query else do the looping

 

can anyone help?

thx in advance

Link to comment
Share on other sites

Exactly what he said, I have a long script, you might be able to shorten it, but it works. This is what I use for my site I just started on today.. Isn't the best, but It works how I want it to for now.

 

<?php
if(isset($_GET['v']))
{
echo "This site is using version: ". $version;
}
else
{
if(!isset($_SESSION['user']))
{
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
  if($_POST['username'] == "" || $_POST['password1'] == "" || $_POST['password2'] == "")
  {
    echo "<p>You have left 1 or more boxes empty!</p>";
  }
  else
  {
    $rrr = mysql_query('SELECT * FROM main WHERE username=\'' . realEscape($_POST['username']) . '\'') ;
    if(mysql_num_rows($rrr) > 0)
    {
    echo "<p>This username already exists</p>";
    }
    else
    {
      if($_POST['password1'] == $_POST['password2'])
      {
        if(preg_match('/[A-Za-z0-9\_]{3,50}/i', $_POST['username'], $matches) && strlen($matches[0]) === strlen($_POST['username']))
        {
          if(preg_match('/[a-z0-9]{3,25}/i', $_POST['password1'], $matches) && strlen($matches[0]) === strlen($_POST['password1']))
          {
              mysql_query("INSERT INTO main (date, username, rights, ip, password, banned) VALUES ('" . date("Y-m-d") . "', '". realEscape($_POST['username']) ."', 0, '". $_SERVER['REMOTE_ADDR'] ."', '". md5($_POST['password1']) ."', 0)");
              echo "<p>Your account has been successfully created<br>You can now login on the <a href='login.php'>Login Page</a>.<br />
              Username: ". htmlspecialchars($_POST['username']) ."</p>"; 
          }
          else
          {
            echo '<p>Invalid password. Your password can only contain Numbers and Letters, and be 3-12 characters in length.</p>';
          }
        }
        else
        {
          echo '<p>Invalid username. Your username can only contain Numbers, Letters, Underscores, and be 3-12 characters in length.</p>';
        }
      }
      else
      {
        echo "<p>Passwords do not match</p>";
      }
    }
  }
}
else
{
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.