Jump to content

Creating action page for php registration


chand.sethi77

Recommended Posts

This is the updated code.

<?php	$connect = mysql_connect ("localhost", "root", ""); 	if (!$connect) {		die ("Could not connect to mysql : " . mysql_error() );	} 		$db_select = mysql_select_db ("users", $connect) ;		if (!$db_select) {			die ("Could not select database : " .mysql_error() ); 		}	$select = mysql_query ("SELECT * FROM users ", $connect); 		if (!$select) {			die ("Table selection failed " .mysql_error() ); 		}?><?php$insert =	 "INSERT INTO users (firstname, lastname, password, age)			VALUES (" . $_POST['firstname'] . ", " . $_POST['lastname'] . ", " . md5($_POST['password']) . ", " . $_POST['age'] . ")";echo $insert;if (!$insert) {	die ("Server error: Access denied : " . mysql_error() ); 	}?>

Link to comment
Share on other sites

It is even worse now. It says that firstname, lastname, age etc are undefined and echoed that complete line "INSERT INTO (first....) values (...)
If they are undefined that means you haven't set them. Undefined means they don't exist; the index of firstname, lastname, etc contain nothing. Are you sure your script is getting data as it is supposed to?Could you post the code of your form?Does it work now?
Link to comment
Share on other sites

<?php$insert =	 "INSERT INTO users (firstname, lastname, password, age)			VALUES (\" . $_POST['firstname'] . \", \" . $_POST['lastname'] . \", \" . md5($_POST['password']) . \", \" . $_POST['age'] . \")";echo $insert;if (!$insert) {	die ("Server error: Access denied : " . mysql_error() ); 	}?>

Finally this is the code and the error is unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on Line : VALUES (\" . $_POST['firstname'] . \", \" . $_POST['lastname'] . \", \" . md5($_POST['password']) . \", \" . $_POST['age'] . \")";

Link to comment
Share on other sites

I'm curious, do you have a table named "users" in your database "users"?I rewrote your code..

<?php//SQL variables -->$host = "localhost";$username = "root";$password = "";$database = "users";//Connect to the database -->$connect = mysqli_connect($host, $username, $password, $database) or die(mysqli_error($connect));//Check for data-->if($_POST){	//Post variables-->	$fname = $_POST['firstname'];	$lname = $_POST['lastname'];	$pass = md5($_POST['password']);	$age = $_POST['age'];	//If there is data insert it into the database -->	$SQL =	"INSERT INTO users (firstname, lastname, password, age) " .			"VALUES ('$fname', '$lname', '$pass', '$age')";	mysqli_query($connect, $SQL) or die(mysqli_error($connect));	echo "Data succesfully inserted!";}else{	//If not, then there's a problem!	echo "You have a problem! There is no data to insert!";}?>

Tested and works!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...