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
https://forums.phpfreaks.com/topic/203254-random-loop-problem/
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
https://forums.phpfreaks.com/topic/203254-random-loop-problem/#findComment-1064930
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.