<?php //filename signup.php
ob_start();
include('dat.php');
if (!empty($_POST)){
if ($pass!="d41d8cd98f00b204e9800998ecf8427e" OR $user!="") { // 1
$result=mysql_query($sql);
if(mysql_error()) {
die('Sorry, this username already exists'); // 2
}
} else {
echo "Please enter the Password";
}
}
ob_end_flush();
?>
<html>
<body>
<form name="form1" method="post" action="signup.php"> <!--3-->
Username<input name="myusername" type="text" id="myusername" />
Password<input name="mypassword" type="text" id="mypassword" />
e-mail<input name="email" type="text" id="email" />
<input type="submit" name="Submit" value="Login" />
</form>
</body>
</html>
This is a sign up page (All the mysql details are missing here, they are included in dat.php) . If there is ny error , it is displayed in the same page.
problem 1 : [ //1 ] what is the operator for OR , in this case I have used the condition for if the pass or user is blank,but the OR is not working neither || , used in javascript.
problem 2 : [ //2 ] if die is used , then the statement is printed in the new window , but I want it to appear in the same window…I also used echo, it worked but I feel like i am missing the main function of ‘die’ by using ‘echo’.
problem 3 : [ <!--3--> ] how can I replace signup.php as action to something like SERVER_PAGE or whatever…
ORis the same as||except thatORhas a lower precedence than||. This can cause logical errors when it’s used with other operators with a higher precedence thanORbut a lower precedence than||like the assignment operators:So I recommend you to rather use
||thanOR.diedoes print the passed string and quits the execution of the current script. Personally, I wouldn’t use usediebut implement a more decent error handling like storing the error message in a variable and print it in the document like this:If you use an empty URL for the
actionattribute, it refers to the very same URL:Some further tips:
$_SERVER['REQUEST_METHOD'] === 'POST'to test the request method instead of testing!empty($_POST).$_POST['pass']instead of$passif you want to refer to the parameter pass passed by POST.