Jump to content

name display problem


opicoder

Recommended Posts

Code:

 

Nimesi: 

<?php

echo $_POST['fname'];

 

?>

 

 

 

Display when im not set the name: Notice: Undefined index: fname in C:\xampp\htdocs\index.php on line 24

Display when im set the name: Name: name

how i can set the first name to "Quest"?

Link to comment
Share on other sites

Good afternoon,

 

You first want to check that the form has been submitted and that the $_POST superglobal actually contains a value. You should do this:

<?php
 
if(isset($_POST['fname']))
{
       //the $_POST superglobal holds value(s)!
 
 
}
else
{
      //we got nothing.
}
 
 
?>

That will eliminate your Undefined Index problem.
 
Now, what are you typing in the fname field in the form?
 
It should display the value that you entered.
 
Kind regards,
 
L2c.
 

Edited by Love2c0de
Link to comment
Share on other sites

You should be getting the name from a form with an input field. You can default the value to Quest

<form method="POST" action="myscript.php">
<input name="fname" type="text" value="Quest">
<input type="submit>
</form>

If you don't want the user to be able to change the value easily use type="hidden" instead of text. If you don't want the user to control the value then don't put it in the $_POST array.

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.