-2

This is test.html

<!DOCTYPE html>
<html>
<body>
<form method="POST" action="test.php">
<table>

<tr>
 <th>content_id</th>
 <th>title</th>
 <th>image</th>
</tr>

<tr>
 <td><input type="text" name="content_id" size="26"></td>
 <td><input type="text" name="title" size="26"></td>
 <td><input type="text" name="image" size="26"></td>
</tr>

</table>
<input type="button" id="cancel" name="cancel" value="Cancel"> <a href="index.php"/></a>
<button type="submit" id="submit" value="Submit">Submit</button>
</form>
</body>
</html>

This is test.php

<?php 
error_reporting(E_ALL);ini_set('display_errors','1');

echo $_POST["content_id"];
echo $_POST["title"];
echo $_POST["image"];
?>

I want to pass the form's value to the PHP and display it but it shows this instead.

enter image description here

EDIT: I apologize for the vague and confusing question, thanks for the assistance everyone!

Ryan
  • 13
  • 2
  • 11
  • You have to host it, e.g. on a LAMP server. Delete Welcome before echo. Method=post on the form and change $_GET to $_POST – vicatcu Nov 07 '17 at 01:34
  • @vicatcu not the problem. – Derek Brown Nov 07 '17 at 01:34
  • You are mixing text/html and php. Change your code to be like this: `Welcome Welcome Welcome ` – Cave Johnson Nov 07 '17 at 01:36
  • @vicatcu I am hosting on a MAMP server. Tried applying what you mentioned and received the same error. – Ryan Nov 07 '17 at 01:38
  • @KodosJohnson I have omitted this conn string if (!$this->conn) { $this->conn = @mysqli_connect($ip, $user, $password); }, if I remove the overall php header, does the conn still works? – Ryan Nov 07 '17 at 01:40
  • You have to wrap anything that is **PHP code** with ``. The only part of your question that is not php code is the "Welcome" text. So just wrap everything before that which is **PHP code** with ``. – Cave Johnson Nov 07 '17 at 01:42
  • The error you are seeing is vague because you don't have error reporting turned on. It can become impossible to tell exactly what is wrong. Put `` at the top of your php script to show the exact errors. – Cave Johnson Nov 07 '17 at 01:44
  • Noted w thanks. I have updated accordingly and displayed my error in the original qns. – Ryan Nov 07 '17 at 01:51
  • Your html is invalid. Table cannot be a child of form tag – Rotimi Nov 07 '17 at 02:10
  • I just saw your error messages. Can you make sure that you have a closing `` tag at the end of your html? I don't see it in your snippet. That could be causing your problems. – Cave Johnson Nov 07 '17 at 02:19
  • Your error messages are basically saying that the variables do not contain the values you are expecting. That means there is something wrong with how your html form is sending the input values. Please make sure the variables you use to get your inputs match your form method (i.e. if you use `method="POST"`, use `$_POST`, if you use `method="GET"`, use `$_GET`) – Cave Johnson Nov 07 '17 at 02:22
  • @Akintunde Is that the main issue for not displaying form values? – Ryan Nov 07 '17 at 03:18
  • @KodosJohnson Sorry, updated codes FULLY. Pls have a look again, thanks. – Ryan Nov 07 '17 at 03:18
  • @Ryan The screenshot you added is blank. Are you actually putting anything in your textboxes? Your php code doesn't do anything except output the value of your textboxes. – Cave Johnson Nov 07 '17 at 03:21
  • @Akintunde That is not correct. You can put a table inside a form. – Cave Johnson Nov 07 '17 at 03:23
  • @KodosJohnson Yes, I added certain values and submit and got brought to that blank test.php page. My objective here is to ascertain that the form value is passed to the php hence I wanna display whether is it showing the correct values. – Ryan Nov 07 '17 at 03:40
  • I'm sorry it's too hard to troubleshoot your problem. But based on the code you have, it should work. I even copied your exact code and it works for me but with one change: you didn't put a semicolon after `ini_set('display_errors','1')`. Try that and see if it works. But it should have given you an error for not having it and you said you got a blank page. – Cave Johnson Nov 07 '17 at 04:08
  • @KodosJohnson Sorry for the vague and confusing question but it's resolved, thanks for your help! – Ryan Nov 07 '17 at 05:18

3 Answers3

1
  1. An error (500) occurs because your syntax is invalid. You can't mix text and commands.

  2. There are two methods of sending data to PHP; GET and POST. GET sends information in URL parameters, and POST sends data in headers. You must use the appropriate PHP method to get data in each format. Given you set the method in the HTML form as POST, you should use _POST in PHP:

<?php
  echo "Welcome ".$_POST["content_id"];
  echo "Welcome ".$_POST["title"];
  echo "Welcome ".$_POST["image"];
?>
  1. In the future, you should look at the error_log, or enable error reporting so that you can see the actual results from the PHP runtime. Details on this can be found here.
Derek Brown
  • 4,232
  • 4
  • 27
  • 44
  • 1
    Noted w thanks. I have updated accordingly and displayed my error in the original qns. – Ryan Nov 07 '17 at 01:52
  • Yes, I understand that. I have tried using both GET and POST (Form & PHP) but to no avail. – Ryan Nov 07 '17 at 02:11
0

The 500 error is because Welcome is not executable PHP code. Put it outside the <?php ?> tags

vicatcu
  • 5,407
  • 7
  • 41
  • 65
-2

Your form method is using GET, your test.php should be:

<?php
 echo $_POST["content_id"];
 echo $_POST["title"];
 echo $_POST["image"];
?>

And your form misses its end tag and a submit button:

<form method="POST" action="test.php">
    <table>
    <tr>
     <th>content_id</th>
     <th>title</th>
     <th>image</th>
    </tr>

    <tr>
     <td><input type="text" name="content_id" size="26"></td>
     <td><input type="text" name="title" size="26"></td>
     <td><input type="text" name="image" size="26"></td>
    </tr>
    </table>
    <button type="submit">Submit</button>
</form>

Here's the form screenshot: https://i.stack.imgur.com/cmMr7.jpg And here's the php script result: https://i.stack.imgur.com/I8vgr.jpg

sianipard
  • 164
  • 2
  • 17
  • Hi, sorry for the confusion! I have updated accordingly and displayed my error in the original qns. – Ryan Nov 07 '17 at 01:53
  • If you're using POST, your URL won't show your form's content, it would be only: http://localhost/test.php only. – sianipard Nov 07 '17 at 02:12
  • Hi, I have updated my codes FULLY. Pls take a look again, thanks. – Ryan Nov 07 '17 at 03:19