Jump to content

Creating action page for php registration


chand.sethi77

Recommended Posts

I created a simple html form for registration and action was "asdf.php" method was ="post"I create database and table regarding registration using phpmyadminin asdf.php i wrote the following code

	<?php		$connect = mysql_connect ("localhost", "root", "PASSWORD_HERE");			if(!$connect) {			die ("Could not connect to mysql" . mysql_error() );			}	?>	<?php		$db_select = mysql_select_db ("php_login", $connect);			if(!$db_select) {				die ("Database selection failed : " . mysql_error() );				}	?>	<?php		$query = mysql_fetch_array("SELECT * FROM users". $connect);	?>	<?php		$insert = 'INSERT INTO users (										fname,										lname,										password,										email,										phone										)								values (								"' . $_POST['fname'] . '", 								"' . $_POST['lname'] . '",								"' . md5($_POST['password']) . '"								"' . $_POST['email'] . '",								"' . $_POST['phone'] . '",										)';		 if (!$insert) {			die ("server error. Access denied : ". mysql_error() );		}	?>

I STRONGLY GUESS THAT IT IS PROBLEM IN VALUES SECTION IN $INSERT and the error is mysql_fetch_array() expects parameter 1 to be resource in line ' $query = mysql_fetch_array("SELECT * FROM users". $connect);" Please tell me what to do. help will be appreciated. Thanks. If possible please create the complete php section of page for meTHANKS

Link to comment
Share on other sites

you neeed to use mysql_query() isstead of mysql_fetch_array() to execute a query.http://php.net/function.mysql_fetch_array used to fecth data from a mysql reslutsetdid you check the w3school tutorials . there is some good example. you may want to check

Link to comment
Share on other sites

you neeed to use http://php.net/function.mysql_query() isstead of mysql_fetch_array() to execute a query.http://php.net/function.mysql_fetch_array used to fecth data from a mysql reslutsetdid you check the w3school tutorials . there is some good example. you may want to check
May be but i guess that section i.e. <?php $query = mysql_fetch_array("SELECT * FROM users". $connect); ?> <?phpis not a major section and the link you gave didn't worked. But thanks anyways :)
Link to comment
Share on other sites

$query = mysql_fetch_array("SELECT * FROM users". $connect);

should be

$query = mysql_query("SELECT * FROM users". $connect);

at first you need to execute the query. same in

$insert = 'INSERT INTO users (										fname,										lname,										password,										email,										phone										)								values (								"' . $_POST['fname'] . '", 								"' . $_POST['lname'] . '",								"' . md5($_POST['password']) . '"								"' . $_POST['email'] . '",								"' . $_POST['phone'] . '",										)';mysql_query($insert,$connect);

same in thi8s case you need to execute this also by using mysql_query() and after that you have to check its return value in conditional structure to determine succefull insert. i fixed the link you will find more details there.

Link to comment
Share on other sites

Okay thanks a lot all the errors are removed. But another problem. I guess it should now store the details (like fname, lname) etc in database but i checked, it is not there. The table shows "Record : 0"i am rechecking for any error. Please a bit help more

Link to comment
Share on other sites

did you created the table already? you need to create the table firstcheck for the return value of mysql_query.something like

if(!$res=mysql_query($insert,$connect))echo mysql_error();elseecho 'inserted';

http://php.net/function.mysql_error will show the error if there is any error in sql

Link to comment
Share on other sites

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 14And line 14 is empty.That is error after inserting the code you gave in previous reply.

Link to comment
Share on other sites

	<?php		$connect = mysql_connect ("localhost", "root", "");			if(!$connect) {			die ("Could not connect to mysql" . mysql_error() );			}	?>	<?php		$db_select = mysql_select_db ("php_login", $connect);			if(!$db_select) {				die ("Database selection failed : " . mysql_error() );				}	?>	<?php		$query = mysql_query("SELECT * FROM users", $connect);	?>	<?php		$insert = 'INSERT INTO users (										fname,										lname,										password,										email,										phone										)								values (								"' . $_POST['fname'] . '", 								"' . $_POST['lname'] . '",								"' . md5($_POST['password']) . '"								"' . $_POST['email'] . '",								"' . $_POST['phone'] . '",										)';		 if (!$insert) {			die ("server error. Access denied : ". mysql_error() );		}		if(!$res=mysql_query($insert, $connect))echo mysql_error();elseecho 'inserted';	?>

Link to comment
Share on other sites

$insert = 'INSERT INTO users ( fname, lname, password, email, phone ) values ( "' . $_POST['fname'] . '", "' . $_POST['lname'] . '", "' . md5($_POST['password']) . '" "' . $_POST['email'] . '", "' . $_POST['phone'] . '", <------you put coomma here. you should remove it. )';line number 14 does not reffer to your php document's line number 14. it points the line number of the sql query which has passed to mysql server.

Link to comment
Share on other sites

its means that data type of your column in db does not match the data which you passed to be inserted. data type must match to insert/update anything.what data type you used for your columns? and can you show the echo of the $insert

echo $insert;

Link to comment
Share on other sites

md5() will return 32 character long hashed string which is not matching in password data type. change it to char(32)/varchar(32).char(32) will be more apropiate.

Link to comment
Share on other sites

echo the $input what you are trying and getting error.

Link to comment
Share on other sites

<?php $insert = 'INSERT INTO users ( fname, lname, password, email, phone ) values ( "' . $_POST['fname'] . '", "' . $_POST['lname'] . '", "' . md5($_POST['password']) . '" "' . $_POST['email'] . '", "' . $_POST['phone'] . '", )'; echo $insert; // <---------put it here if (!$insert) { die ("server error. Access denied : ". mysql_error() ); } if(!$res=mysql_query($insert, $connect))echo mysql_error();elseecho 'inserted'; ?>and remove the quotes from the phone number $_POST['phone']. inetger type should not be quoted.

Link to comment
Share on other sites

<?php include ("connect.php") ?><?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() ); 	}if (!$res = mysql_query($insert, $connect) )echo mysql_error();elseecho 'Successfully registered';?>?>

Okay this is my new code. The ERROR now is syntax error, unexpected T_STRING in C:\wamp\www\users\registered.php on line 11 ........ Line 11 is "" . $_POST['firstname'] . "" ,

Link to comment
Share on other sites

This code:

$insert = 'INSERT INTO users (						firstname,						lastname,						password,						age						)				VALUES (				"" . $_POST['firstname'] . "" ,				"" . $_POST['lastname'] . "" ,				"" .md5( $_POST['password']) . "" ,				"" . $_POST[age] . "" ,				) ';

Is really confusing.Delete that and try this instead:

$insert = 	"INSERT INTO users (firstname, lastname, password, age)			VALUES (" . $_POST['firstname'] . ", " . $_POST['lastname'] . ", " . md5($_POST['password']) . ", " . $_POST['age'] . ")";

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...