i8a6ari i8a6ari - 6 months ago 8
PHP Question

How can i use a button with php?

How can I use a button or form with PHP?

<button formmethod="GET" neme="1" type="button">click</button>
<?php
if ($_GET["1"]) {
require_once "0000.php";
$query = mysql_query("SELECT * FROM op");
while ($rwo = mysql_fetch_object($query)) {
$rwo-> id;
}
}
?>


An error is always shown. What I am trying to do is if someone clicks on the button, results will show up.

Answer
  • typo neme="1" should be name="1"
  • I think you still need a <form> tag wrapped around your button
  • you'll probably want to echo $rwo->id; to see the results
  • use isset to avoid undefined index notices
  • use the input type="submit" instead of type="button"

<form>
    <button formmethod="GET" name="1" type="submit">click</button>
</form>
<?php 
    if (isset($_GET["1"])) {
        require_once "0000.php";
        $query = mysql_query("SELECT * FROM op");
        while ($rwo = mysql_fetch_object($query)) {
            echo $rwo->id;
        }
    }
?>
Comments