I am basically creating a registration page.
Tell me where I am wrong in this code.

if($_POST["regfname"] && $_POST["reglname"] && $_POST["regcname"] && $_POST["regemail"] && $_POST["regphone"] && $_POST["regwebsite"])
    $conn=  mysql_connect($servername,$username)or die(mysql_error());
    $sql="INSERT INTO acts(fname,lname,cname,email,phone,website,password)values('$_POST[regfname]','$_POST[reglname]','$_POST[regcname]','$_POST[regemail]','$_POST[regphone]','$_POST[regwebsite]','$_POST[regpass]');
    $result=mysql_query($sql,$conn) or die(mysql_error());		
    print "<h1>you have registered sucessfully</h1>";
    print "<a href='index.php'>go to login page</a>";
	else print "passwords doesnt match";
else print"invaild input data";


Recommended Answers

All 2 Replies

You have startet the session two times. (you dont need to start a session in this case)
You hasn't defined a mysql password
and i dont know what acts does.. in your sql query

i have rewirted your code =)


if(! $_POST["regfname"] || ! $_POST["reglname"] || ! $_POST["regcname"] || ! $_POST["regemail"] || ! $_POST["regphone"] || ! $_POST["regwebsite"] && $ _POST["regpass"] != $_POST["regcpass"]){
echo "something is wrong";

mysql_connect("localhost", "USERNAME", "PASSWORD");

mysql_query("INSERT INTO database.table (`fname`, `lname`, `cname`, `email`, `phone` ,`website`, `password`) VALUES ('$_POST[regfname]', '$_POST[reglname]', '$_POST[regcname]' ,'$_POST[regemail]', '$_POST[regphone]', '$_POST[regwebsite]', '$_POST[regpass]')");

echo "finish, <a href=\"index.php\">go to login page</a>";


Ps. replace the: database.table wtih your database and table (do not remove the dot)

session should not be twice since is just a registration page. But if you need validation whereby if there is any error you don't want the user to start re-entering his data again
then is fine using session to store the values and display them when their is error during his/her registration.

using the global $_POST[] is better you use if isset() method to verify whether or not something was posted.


 if(isset($_POST["regfname"]) && isset($_POST["reglname"]) && 
isset($_POST["regcname"]) && isset($_POST["regemail"]) && 
isset($_POST["regphone"]) && isset($_POST["regwebsite"]) )

hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.