But i was wondering if this code is correct that i thought of making
| Code: |
<html>
<head></head>
<body>
Password
<input type="text" name="psw" size="5" maxlength="9">
<input type="submit" name="sumbmit" value="log in">
</body>
</html>
|
filename.php
| Code: |
<html>
<head></head>
<body>
<?php
//password varible
$password= whateverpasswordis
//check to see if password is right
if ($_POST['psw'] == $password){
echo 'You craked the code';}
else {
echo 'errr wrong code try agin';}
?>
</body>
</html>
|
Is this code correct and usable?
and i also need to know if there is a code to send the user to a certain page if a varible is equal to another varible.

Ok 21 veiws and no anser coud i please get an anser here
well i see maybe 1 or 2 things.. i would set it like this just cuz im a neat freak in my code sometimes.
| Code: |
<html>
<head></head>
<body>
<?php
$password = 'whateverpasswordis';
$submitted = $_POST['psw'];
if ($submitted == $password){
echo 'You craked the code';
}else{
echo 'errr wrong code try agin';
}
?>
</body>
</html>
|
That was just a rouph code that i wrote ou and yes i dont like my codes bunched together but does the code work?
the bit i just did should work. i cant test it cuz im rather busy with php scripting of my own atm.
ahh i just had to resumbit my account thx that means my first php code worked 
| TheMasterCheaif wrote: |
| Code: |
<html>
<head></head>
<body>
Password
<input type="text" name="psw" size="5" maxlength="9">
<input type="submit" name="sumbmit" value="log in">
</body>
</html> |
|
Invalid HTML. You are missing a title inside the <head>; the input tags must be inside a form.
| TheMasterCheaif wrote: |
filename.php
| Code: |
<html>
<head></head>
<body>
<?php
//password varible
$password= whateverpasswordis
//check to see if password is right
if ($_POST['psw'] == $password){
echo 'You craked the code';}
else {
echo 'errr wrong code try agin';}
?>
</body>
</html>
|
|
You are missing a semicolon between "whateverpasswordis" and "if".
Also I would delimit whateverpasswordis with quotes or single quotes ("or '), unless, of course, it really is a constant defined elsewehere in your code.
| TheMasterCheaif wrote: |
and i also need to know if there is a code to send the user to a certain page if a varible is equal to another varible.  |
Look up header() in the fine PHP manual.
Also, if the two codes are on different pages don't you need to add the form function:
| Code: |
| <form name="anyname" method="post" action="filename.php"> |
Thats only if the two codes are on seperate pages, cause how is the form suspossed to tell you where to go.
I thought of the form code, but I wasent really sure what it was. Thanks for clearing that up.
And yes I knew I needed something in the head. but this is a rouph code.
so it shoud be
| Code: |
$password= 'whateverpasswordis'
|
| TheMasterCheaif wrote: |
so it shoud be
| Code: |
$password= 'whateverpasswordis'
|
|
Don't forget the semicolon!
Usually people place it right after the statement, but you can put it anywhere between this statement and the next | Code: |
$password= 'whateverpasswordis';
$password= 'whateverpasswordis'
; if (true) { /* void */ }
$password= 'whateverpasswordis'
// comment
;
if (true) { /* void */ } |
SO it be
| Code: |
$password= 'whateverpasswordis' ;
|
and is there a way to put php and html in one file?
| TheMasterCheaif wrote: |
| is there a way to put php and html in one file? |
Yes. Make sure your files have a ".php" extension. | Code: |
<html>
<head>
<title>THIS IS HTML</title>
</head>
<body>
<?php
echo '<p>AND THIS IS PHP.</p>';
echo '<p>current server time is ', date('Y-m-d H:i:s'), '</p>';
?>
</body>
</html> |
Thank you so much hexkid, you shoud be an admin, or atleast a mod your one of the most helpful users on frihost.
your forms code should be
<html>
<head></head>
<body>
<form action = "yourscript.php" method = "POST">
Password
<input type="text" name="psw" size="5" maxlength="9">
<input type="submit" name="sumbmit" value="log in">
</form>
</body>
</html>
and now it will work
and the php code should be
<html>
<head></head>
<body>
<?php
//password varible
$password= "whateverpasswordis";
//check to see if password is right
if ($_POST['psw'] == $password){
echo ("You craked the code");}
else {
echo ("errr wrong code try agin");}
?>
</body>
</html>