Jump to content

Recommended Posts

Hi

I'm a beginner at writing website and everything. I have the following problem.

 

I want to write a very simple page which the users will input their I.P. address using html form. And i can do that with the code below.

 

<form action="update.php" method="post" >
IP: <input type="text" name="IP" >
<input type="submit" value="submit">
</form>

 

Now i want it to have different default value. I know i can set a default value for the input box by :

 

IP: <input type="text" name="IP" value="128.243.0.0">

 

But i don't know how to make the default IP as a variable. For example if i want the default value to be the user's IP. (I know i can get the user's IP with $_SERVER['REMOTE_ADDR']).

Is there any way that i can define a string in php then call it in the input tag?

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/120742-html-form-with-different-pre-set-value/
Share on other sites

Try this....

 

<form action="update.php" method="post" >
IP: <input type="text" name="IP" value="<?php echo $ip=$_SERVER['REMOTE_ADDR']; ?>">
<input type="submit" value="submit">
</form>

 

test example

 

http://www.mesquitechristmas.com/development/form.php

 

Keep in mind your file will need to be .php and not .html

 

 

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.