php代码中的按钮的isset函数
How can I make the form not to run the php code directly when the database.php is executed. I can set an if clause that if isset then run..
but there is nothing in the form except the show
button. Is there any way to test if the show button is set? what is the isset
for buttons?
below is the code
database.php
<?php
require 'core.inc.php';
require 'conn.inc.php';
if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id']))
{
$query= "SELECT * FROM Properties";
$query_run=mysql_query($query);
if ($num=mysql_num_rows($query_run))
{
echo $num, " results found <br>";
while ($query_row= mysql_fetch_assoc($query_run))
{
echo "Found";
}
}
}
?>
<html>
<div >
<form action='<?php echo $current_file;?>' method='POST'>
<input type="submit" value="Show">
</form>
</div>
</html>
如何在执行database.php时使表单不直接运行php代码。 我可以设置一个if子句 下面是代码 p>
if isset然后运行.. code>但是除了
show code>按钮之外,表格中没有任何内容。 有没有办法测试是否设置了显示按钮? 按钮的
isset code>是什么? p>
database.php
&lt;?php
require'core.inc.php';
require'conn.inc.php';
if(isset($ _ SESSION ['user_id'])&amp;&amp;!empty($ _ SESSION ['user_id']))
{
$ query =“SELECT * FROM Properties”;
$ query_run = mysql_query($ query);
if($ num = mysql_num_rows($ query_run))
{
echo $ num,“results found&lt; br&gt;“;
while($ query_row = mysql_fetch_assoc($ query_run))
{
echo”Found“;
}
}
}
?
?&gt;
&lt; html&gt;
&lt; div&gt;
&lt; form action ='&lt;?php echo $ current_file;?&gt;' method ='POST'&gt;
&lt; input type =“submit”value =“Show”&gt;
&lt; / form&gt;
&lt; / div&gt;
&lt; / html&gt;
code> pre>
div>
try this..
<?php
require 'core.inc.php';
require 'conn.inc.php';
if (isset($_POST['submit'])) {
if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id']))
{
$query= "SELECT * FROM Properties";
$query_run=mysql_query($query);
if ($num=mysql_num_rows($query_run))
{
echo $num, " results found <br>";
while ($query_row= mysql_fetch_assoc($query_run))
echo "Found";
}
}
}
?>
<html>
<div>
<form action='<?=$_SERVER['PHP_SELF'] ?>' method='POST'>
<input type="submit" name="submit" value="Show">
</form>
</div>
</html>
Give a name to your submit button. e.g btnsubmit than check condition if(isset($_POST['btnsubmit'])). It must work, except this everything is pretty good with your code.
Add a hidden input to your HTML inside the <form>
like this:
<input type="hidden" name="action" value="asdf" />
Then in your PHP you can check:
if (isset($_POST['action']) && $_POST['action'] === 'asdf') {
// Something
} else {
// Something else
}
Use this to branch your code logic, though if it gets really long I'd recommend using multiple files.