[Help] with PHP Code

12/30/2011 01:54 kyle191#1
Hi there, how do I link these two PHP codes together?

Code:
<?php
$conn = mysql_connect("localhost", "root", "jhdyjkkaj");
$db = mysql_select_db("cq");

if(isset($_POST['submit']))
{
     if(isset($_POST['pass']) && $_POST['pass'] != "")
     {
          if($_POST['pass'] == $_POST['pass2'])
          {
               if(strlen($_POST['pass']) > 3 && strlen($_POST['pass']) < 32)
               {
                    $sql = "INSERT INTO `accounts` (Username, Password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
                    $sql = mysql_query($sql);
                    echo "Registered Successfully, use your browser to go back.";
               } else {
                    die("Your password must be between 3 and 32 characters.");
               }
          } else {
               die("Your passwords do not match.");
          }
     } else {
          die("Please enter in a password.");
     }
}
?>

and


Code:
$username = $_POST["user"];

$query = mysql_query("SELECT * FROM accounts WHERE Username='$username'");

if(mysql_num_rows($query) != 0)
{
echo "Username already exists";
}
else
{

}
12/30/2011 02:03 I don't have a username#2
Not really a private server question. Google it :)
12/30/2011 13:57 Mr_PoP#3
PHP Code:
<?php
$conn 
mysql_connect("localhost""root""jhdyjkkaj");
$db mysql_select_db("cq");
$username $_POST["user"];


if(isset(
$_POST['submit']))
{
    if(isset(
$_POST['user'])){
        
$query mysql_query("SELECT * FROM accounts WHERE Username='$username'");

        if(
mysql_num_rows($query) != 0){
            echo 
"Username already exists";
        }
        else{
            if(isset(
$_POST['pass']) && $_POST['pass'] != "")
             {
                  if(
$_POST['pass'] == $_POST['pass2'])
                  {
                       if(
strlen($_POST['pass']) > && strlen($_POST['pass']) < 32)
                       {
                            
$sql "INSERT INTO `accounts` (Username, Password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
                            
$sql mysql_query($sql);
                            echo 
"Registered Successfully, use your browser to go back.";
                       } else {
                            die(
"Your password must be between 3 and 32 characters.");
                       }
                  } else {
                       die(
"Your passwords do not match.");
                  }
             } else {
                  die(
"Please enter in a password.");
             }
        }
    }
    else{
        die(
"Please enter ther user name.");
    }
}
?>
12/30/2011 17:11 kyle191#4
Quote:
Originally Posted by Mr_PoP View Post
PHP Code:
<?php
$conn 
mysql_connect("localhost""root""jhdyjkkaj");
$db mysql_select_db("cq");
$username $_POST["user"];


if(isset(
$_POST['submit']))
{
    if(isset(
$_POST['user'])){
        
$query mysql_query("SELECT * FROM accounts WHERE Username='$username'");

        if(
mysql_num_rows($query) != 0){
            echo 
"Username already exists";
        }
        else{
            if(isset(
$_POST['pass']) && $_POST['pass'] != "")
             {
                  if(
$_POST['pass'] == $_POST['pass2'])
                  {
                       if(
strlen($_POST['pass']) > && strlen($_POST['pass']) < 32)
                       {
                            
$sql "INSERT INTO `accounts` (Username, Password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
                            
$sql mysql_query($sql);
                            echo 
"Registered Successfully, use your browser to go back.";
                       } else {
                            die(
"Your password must be between 3 and 32 characters.");
                       }
                  } else {
                       die(
"Your passwords do not match.");
                  }
             } else {
                  die(
"Please enter in a password.");
             }
        }
    }
    else{
        die(
"Please enter ther user name.");
    }
}
?>

I get an error on line 4 with this code.
12/30/2011 21:13 _tao4229_#5
Change $username = $_POST["user"] to $username = $_POST["username"]
12/30/2011 22:04 kyle191#6
Code:
<?php
$conn = mysql_connect("localhost", "root", "djhbsnu73h");
$db = mysql_select_db("cq");
$username = $_POST["username"];


if(isset($_POST['submit']))
{
    if(isset($_POST['user'])){
        $query = mysql_query("SELECT * FROM accounts WHERE Username='$username'");

        if(mysql_num_rows($query) != 0){
            echo "Username already exists";
        }
        else{
            if(isset($_POST['pass']) && $_POST['pass'] != "")
             {
                  if($_POST['pass'] == $_POST['pass2'])
                  {
                       if(strlen($_POST['pass']) > 3 && strlen($_POST['pass']) < 32)
                       {
                            $sql = "INSERT INTO `accounts` (Username, Password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
                            $sql = mysql_query($sql);
                            echo "Registered Successfully, use your browser to go back.";
                       } else {
                            die("Your password must be between 3 and 32 characters.");
                       }
                  } else {
                       die("Your passwords do not match.");
                  }
             } else {
                  die("Please enter in a password.");
             }
        }
    }
    else{
        die("Please enter ther user name.");
    }
}
?>
I get no errors which display now, but it says "Please enter ther user name." I inputted a username that already exists in the database and also one that doesn't exist. I get the same message and no MYSQL insert.

PS, my Database config is correct.
12/30/2011 22:24 I don't have a username#7
Learn to code PHP.
12/30/2011 22:36 kyle191#8
Why?? When I have all this help lol.
12/30/2011 22:47 I don't have a username#9
Quote:
Originally Posted by kyle191 View Post
Why?? When I have all this help lol.
Because then you learn to do something and won't have to ask for help all the time. You ain't asking your mom to do your stuff all the time for you either, are you?
12/30/2011 23:56 kyle191#10
I bet you don't even know how to fix the code do ya? lol
12/31/2011 00:06 Lateralus#11
Quote:
Originally Posted by kyle191 View Post
I bet you don't even know how to fix the code do ya? lol
I bet you don't.
12/31/2011 00:14 kyle191#12
Quote:
Originally Posted by Lateralus View Post
I bet you don't.
I don't, clearly from what I've been asking for the last few hours.
I really can't see what's wrong with it tbh. My guess it's XAMPP.
12/31/2011 02:52 I don't have a username#13
Quote:
Originally Posted by kyle191 View Post
I bet you don't even know how to fix the code do ya? lol
I'm not coding PHP, but I can easy fix it. With your attitude give me 3 reason why I should fix it.
12/31/2011 08:17 BioHazarxPaul#14
There is a better way to code register pages..
12/31/2011 09:12 agathom#15
bunch of examples out there,