Metoriium Posted October 25, 2014 Share Posted October 25, 2014 (edited) Not sure what is wrong with line 17 <?php $hostname="localhost"; //local server name default localhost $username="root"; //mysql username default is root. $password=""; //blank if no password is set for mysql. $database="login"; //database name which you created $con=mysql_connect($hostname,$username,$password); if(! $con) { die('Connection Failed'.mysql_error()); } mysql_select_db($database,$con); //include connect.php page for database connection Include('connect.php') //if submit is not blanked i.e. it is clicked. If(isset($_REQUEST['submit'])!='') { If($_REQUEST['name']=='' || $_REQUEST['email']=='' || $_REQUEST['password']==''|| $_REQUEST['repassword']=='') { Echo "please fill the empty field."; } Else { $sql="insert into student(name,email,password,repassword) values('".$_REQUEST['name']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."', '".$_REQUEST['repassword']."')"; $res=mysql_query($sql); If($res) { Echo "Record successfully inserted"; } Else { Echo "There is some problem in inserting record"; } } } ?> Edited October 25, 2014 by Metoriium Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/ Share on other sites More sharing options...
sKunKbad Posted October 25, 2014 Share Posted October 25, 2014 Should probably be: If( isset( $_REQUEST['submit'] ) && $_REQUEST['submit'] != '' ) Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494749 Share on other sites More sharing options...
Metoriium Posted October 25, 2014 Author Share Posted October 25, 2014 Just tried that but still says error message Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494751 Share on other sites More sharing options...
Solution chrisrulez001 Posted October 25, 2014 Solution Share Posted October 25, 2014 (edited) Not sure what is wrong with line 17 <?php $hostname="localhost"; //local server name default localhost $username="root"; //mysql username default is root. $password=""; //blank if no password is set for mysql. $database="login"; //database name which you created $con=mysql_connect($hostname,$username,$password); if(! $con) { die('Connection Failed'.mysql_error()); } mysql_select_db($database,$con); //include connect.php page for database connection Include('connect.php') //if submit is not blanked i.e. it is clicked. If(isset($_REQUEST['submit'])!='') { If($_REQUEST['name']=='' || $_REQUEST['email']=='' || $_REQUEST['password']==''|| $_REQUEST['repassword']=='') { Echo "please fill the empty field."; } Else { $sql="insert into student(name,email,password,repassword) values('".$_REQUEST['name']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."', '".$_REQUEST['repassword']."')"; $res=mysql_query($sql); If($res) { Echo "Record successfully inserted"; } Else { Echo "There is some problem in inserting record"; } } } ?> Hi there, After testing this code, and also taking into account of what sKunKbad has said, I think I might have found your problems. You have a capital letter, it should probably be lower-case letter on a few lines and you are missing the semi colon at the end of line 15. Line 15 should probably be include not Include. Line 15 is missing ; at the end of the line. Line 17, 19 and 27 If should probably be if. Line 21, 29 and 33 should probably be echo not Echo. Line 23 and 31 should probably be else not Else. These changes should be made in conjunction of the suggestion that sKunKbad has made. Hope this helps. Edited October 25, 2014 by chrisrulez001 Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494752 Share on other sites More sharing options...
Metoriium Posted October 25, 2014 Author Share Posted October 25, 2014 Thank you very much chrisrulez001This works now although i am now getting this message Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /home/a5347792/public_html/register.php on line 6 Connection FailedAccess denied for user 'root'@'localhost' (using password: NO) Sorry i am new to this stuff Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494754 Share on other sites More sharing options...
chrisrulez001 Posted October 25, 2014 Share Posted October 25, 2014 Your welcome. The error message is saying that you are trying to login to your mysql server without a password and is giving you an access denied message. I see at the top of the code are these variables: $username="root"; //mysql username default is root. $password=""; //blank if no password is set for mysql. Is root the username and is the password blank for logging into your mysql server? Also what are you using for a mysql server? I should also point out that the mysql_* functions are now depreciated, you should be using mysqli or PDO. Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494756 Share on other sites More sharing options...
Metoriium Posted October 25, 2014 Author Share Posted October 25, 2014 I am using 000webhost at the moment (this is temporary) and i dont think it supports mysqli Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494757 Share on other sites More sharing options...
chrisrulez001 Posted October 25, 2014 Share Posted October 25, 2014 (edited) I'm not familiar with 000webhost but I think they use phpMyAdmin to manage the databases? When you login to phpMyAdmin you use a specific username and password, you need to put the username in the username variable and password in the password variable. mysqli is actual PHP code that is used to connect to (for example: phpMyAdmin). Take a look at this tutorial: http://codular.com/php-mysqli Edit: Take a look at this on the 000webhost's FAQ: http://www.000webhost.com/faq.php?ID=25 Edited October 25, 2014 by chrisrulez001 Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494758 Share on other sites More sharing options...
Metoriium Posted October 25, 2014 Author Share Posted October 25, 2014 (edited) I have fixed it, Thank you very much Edited October 25, 2014 by Metoriium Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494761 Share on other sites More sharing options...
chrisrulez001 Posted October 25, 2014 Share Posted October 25, 2014 (edited) Can you login to phpMyAdmin using the same username and password? If you can login, then I think maybe you need to double check the hostname. Edited October 25, 2014 by chrisrulez001 Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494762 Share on other sites More sharing options...
Metoriium Posted October 25, 2014 Author Share Posted October 25, 2014 one more question aha. What normally goes into connect.php //include connect.php page for database connection include('connect.php'); Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494764 Share on other sites More sharing options...
chrisrulez001 Posted October 25, 2014 Share Posted October 25, 2014 (edited) You usually start the connection in connect.php and then include it on the pages that you are connecting to the database. From line 2 to line 12 would be classed as the database connection. However the connection process is different if you are using mysqli. Did you manage to connect to phpMyAdmin from the members area using the username and password you added to the code? Edit: Sorry hadn't noticed you'd managed to fix the problem Edited October 25, 2014 by chrisrulez001 Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494766 Share on other sites More sharing options...
Metoriium Posted October 25, 2014 Author Share Posted October 25, 2014 Yes this is fixed, i am going to link you to the webpage that i am working on via message. Thank you so much chrisrulez001 Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494767 Share on other sites More sharing options...
chrisrulez001 Posted October 26, 2014 Share Posted October 26, 2014 Your welcome. Please mark this as fixed. Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494768 Share on other sites More sharing options...
jcbones Posted October 26, 2014 Share Posted October 26, 2014 Things you should be doing differently. 1. You should be using mysqli or PDO as stated, they support prepared statements that eliminate the need to structure your query inputs, as well as making sure they are the right type. 2. You should be sanitizing and validating your inputs, you should never trust the client to send the correct data. You must verify the data is correct. 3. You should be using $_POST or $_GET arrays, as you expect them. Never use $_REQUEST. I could make this form submit by sending an URL 'email' query.4. Your line If(isset($_REQUEST['submit'])!='') will always be true. isset() returns a boolean value, so it is never an empty string. Should probably be: if(isset($_POST['submit'])) { //or better yet: if($_SERVER['REQUEST_METHOD'] == 'POST') Quote Link to comment https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/#findComment-1494789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.