Jump to content

[SOLVED] Need help with a form


popoval

Recommended Posts

Hi.

I have just started learing PHP and have run into trouble.

I am trying to create a form.

on the first page (testform.php) i have this code:

 

<html>

<head>

<title>PHP Test</title>

</head>

<body>

<?php echo '<p>Hello World</p>';

?>

<br>

<form action="/processForm.php" method="get">

Enter youre name

<input type="text" name="userName"><br>

<input type="submit" name="submit">

</form></body>

</html>

If I enter my Name "Alex" an click Submit it openes the next page: ProcessForm.php?user_name=alex&submit=Submit+Query

 

On that page I have this code:

<html>

<head>

<title>PHP Test</title>

</head>

<body>

<?php

print "hi $userName<br>";

?></body>

</html>

 

According to my book the page would now display:

Hi alex

 

But it does not work. What am I doing wrong?

 

Thanks

Alex

Link to comment
Share on other sites

try using an echo "$userName";

or print ("$userName");

 

o yea, the form action should probobally be post, or you could put session_start(); at the top of the page (in php tages)

 

I did try with both echo "$userName"; and print ("$userName");

but did not work.

 

I must say I did not understand wat you ment with session_start();

where to you want me to put it? as first line after <?php ?

What should be between () ?

Link to comment
Share on other sites

Simply try this

 

<?php
echo phpinfo();
?>

 

Or try ur form in this way.

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>';
?>
<form action="processForm.php" method="post">
Enter youre name
<input type="text" name="userName">

<input type="submit" name="submit">
</form>
</body>
</html> 

 

processForm.php code

 

 
<?php
If(isset($_POST['submit']))
{
$username=$_POST['userName'];
echo $username;
}
?>

Link to comment
Share on other sites

first page:

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>';
?> 


<form action="/processForm.php" method="post">
Enter youre name
<input type="text" name="userName">

<input type="submit" name="submit">
</form></body>
</html> 

 

second page:

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$userName = $_GET['userName'];
print "hi $userName";
?></body>
</html> 

or

firstpage:

<?php session_start(); ?>
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>';
?> 


<form action="/processForm.php" method="get">
Enter youre name
<input type="text" name="userName">

<input type="submit" name="submit">
</form></body>
</html>

 

second page:

<?php session_start(); ?>
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$userName = $_GET['userName'];
print "hi $userName";
?></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.