Reputation: 23
I am a newbie I am having a little problem on how can i call the button inside my if statement. I am trying to work on a userlog where when you click a button it will output on the user log.
but how can i call the >>
THE VIEW button inside my if statement so that it will fwrite
inside the userlog.txt.
inside this if($_POST['submit'] = ")
same goes in the search button and the add edit delete button. did u get my point?
<body background="images.jpg">
<?php
session_start();
if($_SESSION['username'])
{
echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a><br>";
echo '<FORM METHOD="LINK" ACTION="mydata4.php">
<INPUT TYPE="submit" VALUE="Edit/Delete/add">
</FORM>';
echo '<FORM METHOD="LINK" ACTION="mydata2.php">
<INPUT TYPE="submit" VALUE="View" id="viewbutton">
</FORM>';
echo '<FORM METHOD="LINK" ACTION="display_data.php">
<INPUT TYPE="submit" VALUE="Search">
</FORM>';
}
else
{
die("You must be logged in!");
}
if($_POST['submit'] = ")
{
$date=date("Y-m-d H:i:s");
$updatefile = "userlogs.txt";
$fh = fopen($updatefile, 'a') or die("can't open file");
$stringData = "User: $username click view button";
fwrite($fh, "$stringData".PHP_EOL);
fclose($fh);
}
?>
Upvotes: 0
Views: 4638
Reputation: 2119
you can set the same name to your submit buttons ...
<input type="submit" name="submit" value="View" />
<input type="submit" name="submit" value="Search" />
and in your PHP, you can simply use as you mentioned
if( $_POST["submit"] == "View" )
...
if( $_POST["submit"] == "Search" )
...
one more things is that, you have to use method="post"
in your <form>
tag if you want to use $_POST
in php
<form method="post" action="....php">
Upvotes: 0
Reputation: 1675
try this... you are doing mistake in your if condition.
<body background="images.jpg">
<?php
session_start();
if($_SESSION['username'])
{
echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a><br>";
echo '<FORM METHOD="LINK" ACTION="mydata4.php">
<INPUT TYPE="submit" VALUE="Edit/Delete/add">
</FORM>';
echo '<FORM METHOD="LINK" ACTION="mydata2.php">
<INPUT TYPE="submit" VALUE="View" id="viewbutton">
</FORM>';
echo '<FORM METHOD="LINK" ACTION="display_data.php">
<INPUT TYPE="submit" VALUE="Search" name="submit" id="submit">
</FORM>';
}
else
{
die("You must be logged in!");
}
if($_POST['submit'] == "submit")
{
$date=date("Y-m-d H:i:s");
$updatefile = "userlogs.txt";
$fh = fopen($updatefile, 'a') or die("can't open file");
$stringData = "User: $username click view button";
fwrite($fh, "$stringData".PHP_EOL);
fclose($fh);
}
?>
Upvotes: 0