PHP Skipping validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sugo
    New Member
    • Mar 2007
    • 2

    #1

    PHP Skipping validation

    Hi, I have the following form:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?PHP
    		if (!isset($instructimg)) {  //changes the error message
    			$instructimg = 'instruct_1a.png';
    			}
    
    		if (!isset($username)) {  //remembers username
    		 $username="";
    		 }
    ?>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
    		<title>xxx</title>
    		<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
    		<link href="../css/reg.css" rel="stylesheet" type="text/css" media="all" />
    	</head>
    <body>
     <div id="container">
    		<div id="header"><a href="xxxxxx"><img src="../images/header_small.png" alt="xxx" /></a></div>
    		<div id="content_top"><img src="images/top_1.png" alt="Signup status." /></div>
    		<div id="content_main"><img id="instruct" src="images/<?php echo $instructimg; ?>" alt="Please enter your details" />
    		<div id="form">
    		<form action="step1_update.php" method="post" id="step1" name="step1" onsubmit="return VerifyData(this)">
    		<label for="Username"><img src="images/username.png" alt="Enter a username" /></label>
            <input name="Username" type="text" id="Username" size="30" value="<?php echo $username; ?>" tabindex="1" class="border" language="javascript" onclick="return Username_onclick()"><br/>
            <label for="Password"><img src="images/password.png" alt="Enter a password"></img></label><br/>
      		<input name="Password" type="password" id="Password" size="30" value="" tabindex="2" class="border"><br/>
            <label for="Confirm"><img src="images/confirm.png" alt="Confirm your password"></label><br/>
            <input name="Confirm" type="password" id="Confirm" size="30" value="" tabindex="3" class="border"><br />
    		<div id="nav"><input name="step2" type="image" src="images/next.png" alt="Next" class="next" tabindex="4" /></div>
    		</form>
    		</div>
    		</div>
    	<div id="footer">
    	<ul>
    		<li><a href="About.asp"><img src="../images/footer/footer1about.png" alt="About Us"></img></a></li>
    		<li><a href="help.asp"><img src="../images/footer/footer2faq.png" alt="Help"></img></a></li>
    		<li><a href="safety.asp"><img src="../images/footer/footer3safe.png" alt="Safety Online"></img></a></li>
    		<li><a href="privacy.asp"><img src="../images/footer/footer4privacy.png" alt="Privacy"></img></a></li>
    		<li><a href="tc.asp"><img src="../images/footer/footer6tc.png" alt="Terms and Conditions"></img></a></li>
    		<li><img src="../images/footer/footer5right_small.png" alt="xxxxxx"></img></li>
    	</ul>
    
    	</div>
    
    </div>
    </body>
    </html>
    And then this PHP to validate and post it into my table:

    Code:
    <?php //step1_insert.php
    
    include("my_config.php");
    
    // connect to the mysql server
    $link = mysql_connect($dbhost, $dbuser, $dbpass)
    or die ("MySQL is Broke! It said: ".mysql_error());
    
    // select the databases
    mysql_select_db($dbname)
    or die ("Can't find that database mate, MySQL said: ".mysql_error());
    
    //get the data and store it as vars
    $username=$_POST["Username"];
    $password=$_POST["Password"];
    $confirm=$_POST["Confirm"];
    
    //check whether username exists
    $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");
    $username_exist = mysql_num_rows($checkuser);
    if($username_exist > 0){
        $instructimg = 'instruct_1b.png';
        unset($username);
        unset($password);
        include 'step1.php';
    	exit();
    	}
    //make sure password match
    if ($password != $confirm) {
     $instructimg = 'instruct_1c.png';
        unset($password);
        include 'step1.php';
    	exit();
    }
    //make sure passwords are a minimum of 5 letters.
    if(strlen($password) < 5 ){
     $instructimg = 'instruct_1d.png';
        unset($password);
        include 'step1.php';
    	exit();
    }
    //Everything validated and all good, lets add this guy to the table!
    $date = date("Y-m-d G:i:s"); //Get the date
    $adduser= mysql_query("INSERT into MyUser
    (username, pwd, creationdate)VALUES('$username','$password','$date')")
    or die(mysql_error());
    
    
    printf ("it worked, you added your self! your id was", mysql_insert_id());
    
    ?>
    It all works pretty well (except the mysql_insert_id function, but thats not my main worry), except after inserting the new users deatils into the table, clicking back then submitting the form again bypasses the "check if existing user" bit.

    It will insert the same user again.

    Any idea please let me know. Thanks for your time = )

    John.
  • sugo
    New Member
    • Mar 2007
    • 2

    #2
    Please ignore the above! I was checking one table, then inserting into a different table.

    Right infront of my nose...

    Comment

    Working...