0

I have a form in a php page into which I would like to automatically add a URL paramenter into a field. The address would look something like:

http://www.websiteaddress/admin/add_data.php?file_name=image.jpg

The page add_data.php contains the following form (I've removed some colums for brevity). All I want to achieve is that the parameter file_name is the data entered into the cell containing:

<input type="text" name="image" id="image" value="<?php echo $row_getShip['image']; ?>" maxlength="150" />

So that when clicking 'insert' the name of the image file is already filled in in the correct box

Please help!

  <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <p>&nbsp;</p>
  <table width="1312" border="0">
    <tr>
      <td><input type="text" name="image" id="image" value="<?php echo $row_getShip['image']; ?>" maxlength="150" /></td>
      <td><div align="right">
        <input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_getShip['ship_id']; ?>" />
        <input type="hidden" name="MM_update" value="form1" />
        <input type="submit" name="insert" id="insert" value="Update" />
      </div></td>
    </tr>
  </table>
</form>

3 Answers 3

1

You can try

 <input type="text" name="image" id="image" value="<?php echo $_GET['file_name']; ?>" maxlength="150" />

All values in url can be retrieved using php $_GET global variable

eg in your case $_GET['file_name'] returns image name.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for that - can I ask a stupid question..... There are about 10 fields on the full table, and the code for each one is similar to this.... <input name="class" type="text" id="class" value="<?php echo $row_getShip['class']; ?>" maxlength="150" /> Would I just replace this whole line with the one you suggested or integrate in some way? Thank you
You can save whole tag in a variable and echo that variable ,
Like <?php $image= "<input type='text' name='image' id='image' value="$_GET['file_name']" maxlength='150' />"; //wants to use this line here echo $image; ?>
0

To get that value from the url use:

$_GET['file_name'];

Comments

0

You would grab the value using $_GET. You could put this at the top of your script.

$row_getShip['image'] = $_GET['filename'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.