0

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

<?php
 session_start();session_destroy();
 session_start();
if($_POST["regfname"] && $_POST["reglname"] && $_POST["regcname"] && $_POST["regemail"] && $_POST["regphone"] && $_POST["regwebsite"])
{
    if($_POST["regpass"]==$_POST["regcpass"])
	{
	$servername="localhost";
    $username="akshay";
    $conn=  mysql_connect($servername,$username)or die(mysql_error());
    mysql_select_db("akshay",$conn);
    $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";

?>
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by hakeemtunde
0

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 =)

<?php

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

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)

Edited by brugernavn: n/a

0

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.

e.g

<?php
 if(isset($_POST["regfname"]) && isset($_POST["reglname"]) && 
isset($_POST["regcname"]) && isset($_POST["regemail"]) && 
isset($_POST["regphone"]) && isset($_POST["regwebsite"]) )
{
 .................
}
?>

hope this helps

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.