0

I wrote this using various helper guides online:

<?php // update
if(isset($_POST['update']))
{
$id = $_POST['id'];
$emp_salary = $_POST['emp_salary'];

$sql = "UPDATE pins ".
   "SET is_private = $emp_salary ".
   "WHERE id = $pinDetails->id" ;

mysql_select_db('test_db');
$retval = mysql_query( $sql );
if(! $retval )
{
  die('Could not change: ' . mysql_error());
}
echo "Post is now private<br><br>";
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>Private
<input name="emp_salary" type="text" id="emp_salary" value="1">
<input name="id" type="hidden" id="id">
<input name="update" type="submit" id="update" value="Change">
</td>
</tr>
</table>
</form>
<?php
 }
?><!-- update -->

I'm trying to create an online form which I can return to to change posts from public to private simply by entering 1 for private or 0 for public as a moderation tool.

However, when I submit the form, (which works) every time I revisit the page it just says the echo statement 'post is now private'. I want to be able to see the form everytime, so I can re-use again and again when necessary.

What do I need to change in order to achieve this?

4

2 回答 2

0

Remove else in last condition.

if(isset($_POST['update']))
{
$id = $_POST['id'];
$emp_salary = $_POST['emp_salary'];

$sql = "UPDATE pins ".
   "SET is_private = $emp_salary ".
   "WHERE id = $pinDetails->id" ;

mysql_select_db('test_db');
$retval = mysql_query( $sql );
if(! $retval )
{
  die('Could not change: ' . mysql_error());
}
echo "Post is now private<br><br>";
}
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>Private
<input name="emp_salary" type="text" id="emp_salary" value="1">
<input name="id" type="hidden" id="id">
<input name="update" type="submit" id="update" value="Change">
</td>
</tr>
</table>
</form>
于 2013-11-06T19:50:39.187 回答
0

after:

 echo "Post is now private<br><br>";

add this:

 echo '<a href="' . $_PHP_SELF . '">see form</a>';

Your problem is that the form post variables are still being sent to the server so your if statement

if(isset($_POST['update']))

evaluates to true and the form doesnt' display.

于 2013-11-06T19:52:50.960 回答