2

I am having an issue on designing a web page. I want to display a POST variable inside of an HTML table.

Here is the form code from the first page:

<form action="buy.php" method="post">
<input type="text" name="uid" />
<input type="submit" value="Buy Now" />
</form>

This code works fine if I am displaying the POST variable on a normal blank PHP file.

But when I go to use it in an html table it just won't display.

Here is the table code:

<td id="bal"><?php echo $_POST['uid']; ?></td>
<td id="amt">test1</td>
<td id="type">test2</td>

The first tabledata just appears blank.

Can anyone help me fix this?

Here is the entire code in the buy.php file: http://pastebin.com/ffWAP92C

(was having trouble posting it in here )

This is what the problem looks like:

12
  • I assume that you have the table and tr tags in place. If you cant single step through it then I would suggest do a var_dump($_POST['uid']) before the table tag Commented Apr 18, 2015 at 7:05
  • Starkeen could you please elaborate? You don't mean an if statement do you? There's no need for one here. Commented Apr 18, 2015 at 7:06
  • Rohit yes I do have the table and tr tags. How will dumping the variable before the table help display it inside of the table? Commented Apr 18, 2015 at 7:08
  • the above code works fine for me. did you use any css or jquery in your code Commented Apr 18, 2015 at 7:10
  • 3
    It means your table is malformed. If you like answer it is better to show us whole code Commented Apr 18, 2015 at 7:15

3 Answers 3

1

Change this <td id="bal"> <?php echo "$_POST['uid'];" ?> </td> to <td id="bal"> <?php echo $_POST['uid']; ?> </td>

Try this one,

<html>
<head>
    <title></title>
    <style type="text/css">
    </style>
</head>

<body>
    <center><h1>Purchase Account ID</h1></center>
    <table border="1" style="width:100%;">
        <tr>
           <td><b>Account ID</b></td>
           <td><b>Account Type</b></td>               
           <td><b>Account Price</b></td>
        </tr>
        <tr>
           <td id="bal">
               <?php
                   if(isset($_POST['uid']))
                      echo $_POST['uid'];
                   else
                      echo "Nothing";
               ?> 
           </td>
           <td id="amt">test1</td>
           <td id="type">test2</td>
        </tr>
    </table>
</body>
</html>

Hope this works.

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

5 Comments

@Chawbee :- can you please post your whole code. So that i can analyze.
@jithin_varghese No it didn't :\ This is actually what I had before. I just inserted the quotes to see if it would work. It shows up like this: prntscr.com/6v4yo6
@jithin_varghese There still isn't anything displayed in the box. Didn't even print out the "nothing" .
@Chawbee :- are you running the code in localhost (using wamp server, xampp server etc...) or just opening with browser.
@jithin_varghese I feel like such an idiot right now -__- . Thanks, that was it. How do I rep you/give you best answer? Fairly new to the site still
0

Remove " signs inside php tag. i.e. replace

<td id="bal"> <?php echo "$_POST['uid'];" ?> </td>

with

<td id="bal"> <?php echo $_POST['uid']; ?> </td>

OR insert semicolon after " sign. i.e.

 <td id="bal"> <?php echo "$_POST['uid']"; ?> </td>

1 Comment

can you post the source code of first page, not buy.php
0

you can copy past below code in a test.php file. i have updated code. It is working in my localhost.

        <html>

        <head>
        <title></title>
        <style type="text/css">


        </style>
        </head>
        <center><h1>Purchase Account ID</h1></center>




        <body>
        <table border="1" style="width:100%;">
          <tr>

            <td><b>Account ID</b></td>
            <td><b>Account Type</b></td>               
            <td><b>Account Price</b></td>


          </tr>

          <tr>

                <td id="bal"> <?php if(isset($_POST['uid'])) echo $_POST['uid']; ?> </td>
                <td id="amt">test1</td>
                <td id="type">test2</td>


          </tr>

        </table>

        </body>


        <form action="test.php" method="post">
        <input type="text" name="uid" />
        <input type="submit" value="Buy Now" />
        </form>

        </html>

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.