chand.sethi77 Posted March 21, 2011 Share Posted March 21, 2011 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 More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 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 More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 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 checkMay 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 More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 $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 More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 more details herehttp://w3schools.com/phphttp://w3schools.com/php/php_mysql_intro.asphttp://w3schools.com/php/php_mysql_insert.asphttp://w3schools.com/php/php_mysql_select.asp Link to comment Share on other sites More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 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 More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 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 More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 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 More sharing options...
chokk Posted March 21, 2011 Share Posted March 21, 2011 $query = mysql_query("SELECT * FROM users", $connect); You seperate the SQL string and link identifier with a comma, not a period. Link to comment Share on other sites More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 still same problem Link to comment Share on other sites More sharing options...
chokk Posted March 21, 2011 Share Posted March 21, 2011 Can you post the updated code as it looks now? Link to comment Share on other sites More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 <?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 More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 $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 More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 I appreciate that you are continuously helping. Removing comma helped in countering the error. But now i am getting "Column count doesn't match value count at row 1" this thing written. What does that mean ? how do i counter it? Link to comment Share on other sites More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 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 More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 fname, lname, password and email are VARCHAR(30) whereas phone and id(p.k and a.i) are INT(11) Link to comment Share on other sites More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 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 More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 Still not working. I tried removing .md5 stilll same problem Link to comment Share on other sites More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 echo the $input what you are trying and getting error. Link to comment Share on other sites More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 $input variable is not specified Link to comment Share on other sites More sharing options...
birbal Posted March 21, 2011 Share Posted March 21, 2011 <?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 More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 Okay, I am deleting everything done so far and start again. This time i will use w3school's tutorials. Link to comment Share on other sites More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 <?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 More sharing options...
chokk Posted March 21, 2011 Share Posted March 21, 2011 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 More sharing options...
chand.sethi77 Posted March 21, 2011 Author Share Posted March 21, 2011 Still getting same error but now on different line. Line number 8 :die ("Server error: Access denied : . " mysql_error() ); Error is Parse error: syntax error, unexpected T_STRING Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.