The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Form Post Method, $_Get in Form Post Action
Freshman
post Dec 19 2018, 08:54 AM
Post #1


Newbie
*

Group: Members
Posts: 12
Joined: 19-December 18
Member No.: 26,776



Hi all,

I'm very new to HTML and PhP but learning as I go.
In code below I would like to 'insert' the id (from the URL) to the Action in the Form Post method.
As you will see I tried to pass the $id value into the Action but it is not working.
If I hardcode the correct value then all my following code work 100%

URL would be something like: www.mydomain.com/add.html?id=123

CODE

<?php
//getting id from URL
$id = $_GET['id'];
?>

<html>
<head>
    <title>Add Data</title>
</head>

<body>
    <br/><br/>

    <form method="post" name="form1" action="addrec.php?id="&<?php echo $id;?>>
        <table width="25%" border="0">
            <tr>
                <td>Day <?php echo $id;?> N </td>
                <td><input type="text" name="HDay"></td>
            </tr>
            <tr>
                <td>Month</td>
                <td><input type="text" name="HMonth"></td>
            </tr>
            <tr>
                <td>Relation</td>
                <td><input type="text" name="Relation"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" name="Submit" value="Add"></td>
            </tr>
        </table>
    </form>
</body>
</html>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Freshman
post Dec 20 2018, 02:01 AM
Post #2


Newbie
*

Group: Members
Posts: 12
Joined: 19-December 18
Member No.: 26,776



Final update:
@ChristianJ - Thanks this worked smile.gif
(Not sure how to give a 'thumbs up' on your post or to mark as 'solved')

CODE

action="addrec.php?id=<?php echo $id;?>">


This post has been edited by Freshman: Dec 20 2018, 02:02 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Dec 20 2018, 04:15 AM
Post #3


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Ah, simple as that.

Normally .html files aren't parsed for PHP. You can see that by doing a View Source. If PHP isn't parsed you see the raw PHP in the page source. If it is you don't. If it's important to you, you can make the server parse HTML files too though.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th April 2024 - 08:50 PM