Jump to content

Whats wrong with line 17?


Go to solution Solved by chrisrulez001,

Recommended Posts

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 by Metoriium
Link to comment
https://forums.phpfreaks.com/topic/292061-whats-wrong-with-line-17/
Share on other sites

  • Solution

 

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 by chrisrulez001

Thank you very much 

chrisrulez001

This 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

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 mysqlor PDO.

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 by chrisrulez001

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 by chrisrulez001

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')
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.