Jump to content

Need a little help.


Pain

Recommended Posts

Hello everyone.

 

I am learning how to use PHP and i would like to get some help.

For example i wrote this crappy code:

<html>
<head>
<title>
Login
</title>
<body>
<?php
$username = "username";
$password = "password";
$wel = "You have successfully logged in $username";
$get = "Incorrect username or password";
$vardas = $_POST['vardas'];
$slaptazodis = $_POST['slaptazodis'];
<form method="POST" action="'. $_SERVER['PHP_SELF'] . '">
<input type="text" name="vardas">
<input type="text" name="slaptazodis">
<input type="submit" />
</form>
if ($username != $vardas)
{
print $get;
{
elseif ($password != $slaptazodis)
print $get;
}
}
else
{
print $wel;
}
?>
</body>
</html>

Can't figure out what is wrong with it.

I get this:

Parse error: syntax error, unexpected '<' in /home/a2789128/public_html/a/Login.php on line 14

 

Thank you for your help:)

Link to comment
Share on other sites

PHP is not HTML, so it can't be used in the same tags. You need to separate them, Let me show you an example of your working code:

<html>
  <head>
    <title>
     Login
    </title>
  <body>
<?php
$username = "username";
$password = "password";
$wel = "You have successfully logged in $username";
$get = "Incorrect username or password";
$vardas = $_POST['vardas'];
$slaptazodis = $_POST['slaptazodis'];
?>
<form method="POST" action="<?php print $_SERVER['SCRIPT_NAME']; ?>">
  <input type="text" name="vardas">
  <input type="text" name="slaptazodis">
  <input type="submit" />
</form>
<?php
if ($username != $vardas) {
   print $get;
} elseif  ($password != $slaptazodis) {
   print $get;
} else {
  print $wel;
}
?>
  </body>
</html>

 

Although it still looks like there are many problems with your structures, You should learn how to use IF statements properly, as I needed to correct quite a few. Try not to list the curly braces ({ }) on new lines, as it seems you're confusing them in the end.

 

For security reasons, also use SCRIPT_NAME in place of PHP_SELF, which will work the same in the end.

 

This code will not work, as you need to look into ISSET for your $_POST elements as well. If you need help on that just ask. :P

Link to comment
Share on other sites

Ok i modified it a bit, but it still doesnt look good. Anny suggestions how to improve it:(?

<html>
<head>
<title>
Login
</title>
<body>
<?php

$user = "asesu1";
$pass = "asesu2";
$username = $_POST['username'];
$password = $_POST['password'];


if ($username != $user)
{

if ($password != $pass)
{

print'
<form method="POST" action="'. $_SERVER['PHP_SELF'] . '">
Login:<br/>
<input type="text" name="username" size="14"><br/>
Password:<br/>
<input type="password" name="password" size="14"><br/>
<input type="submit" value="Jungti" name="B1">
<input type="reset" value="Valyti" name="B2">
</form>';

}
}

else

{

?>
<p align="center">
<br/>
<br/>
<br/>
<br/>
<b>Welcome!</b>
<br/>
<br/>
Vla bla bla</p>
<?
}
?>
</body>
</html>

Link to comment
Share on other sites

When I was learning the basics of PHP I found this book very useful.

 

Sams teach your self php, mysql database and appachy in 24 hours.

It showed me some every day use of php and gived me a better understanding.

 

The book will not teach everything, just the basics to help you understand and learn basic scripting.

And as you start to get better you can start to desgin your own guest book and interactive pages.

 

This site and a forum is a great place for information and help if you get stuck.

And www.php.net has loads of information on diffrent codes and funcanlitys.

Link to comment
Share on other sites

this

if ($username != $user)
{

if ($password != $pass)
{

print'
<form method="POST" action="'. $_SERVER['PHP_SELF'] . '">
Login:<br/>
<input type="text" name="username" size="14"><br/>
Password:<br/>
<input type="password" name="password" size="14"><br/>
<input type="submit" value="Jungti" name="B1">
<input type="reset" value="Valyti" name="B2">
</form>';

}
}

 

can be simplified to

if ($password != $pass && $username != $user)
{

print'
<form method="POST" action="'. $_SERVER['PHP_SELF'] . '">
Login:<br/>
<input type="text" name="username" size="14"><br/>
Password:<br/>
<input type="password" name="password" size="14"><br/>
<input type="submit" value="Jungti" name="B1">
<input type="reset" value="Valyti" name="B2">
</form>';

}

Link to comment
Share on other sites

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.