Jump to content

New to php


2words4uready

Recommended Posts

I just started php today and was wondering why this doesn't work?

index.php

<form action="next.php" method="post">
Enter your name: <input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" />
</form>

 

next.php

<?php
$file = fopen(test.txt, "a+");
fwrite($file,$_Post ["name"];
fwrite($file,$_Post ["age"];
fclose(test.txt);
?>

Link to comment
Share on other sites

The code for the form is fine but on next.php you forgot to close your function calls and you need to quote the filename as so.

<?php
$file = fopen("test.txt", "a+");
fwrite($file, $_POST["name"]);
fwrite($file, $_POST["age"]);
fclose("test.txt");
?>

I hope this helps.

Link to comment
Share on other sites

Also, the fclose() statement would need to be -

 

fclose($file);

 

From the php manual -

Description

bool fclose ( resource $handle )

 

When learning php, developing php code, or debugging php code, set error_reporting to E_ALL and display_errors to on in your php.ini (stop and start your web server to get any changes made to php.ini to take effect) to get php to help you.

 

Each of the problems pointed out would have generated an error message of some kind.

Link to comment
Share on other sites

How bout this code?

Index.php

<html>
<head>
<title><?PHP?></title>
</head>
<body>
<form action="index.php" method=POST>
Username: <input type=text name=user><br>
Password: <input type=password name=pass>
<input type=submit value="Login">
</form>
<?php
$user=$_POST["user"];
$pass=$_POST["pass"];
$user1="user"
$pass1="pass"
If (($user==$user1)&&($pass==$pass1)){
echo "Access Granted"
} else {
echo "Access Denied"
)
?>

</body>
</html>

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.