Jump to content

publish/unpublish a record using php


mrjameer

Recommended Posts

hi,

i have a mysql table which contains some hosting plans info.there are 5 records inside the table.what i want to do is i want to put button like publish/unpublish for every record.so that whenever i dont want to publish a particular record i will simply click unpublish.is it posible to do this with php.any of your help will be greatly appreciated.


thanks
mrjameer
Link to comment
https://forums.phpfreaks.com/topic/32854-publishunpublish-a-record-using-php/
Share on other sites

hi,

i tried some code.the following code is used to display records from mysql table and dynamically creates a checkbox for every record.

when i click checkbox and press submit button,that particular record will be hided(unpublished),here the field 'published' value will be set to '0' means unpublished and '1' for published.upto this ok.

but what i want to do is when i want publish the same record again,how to code.if i create another button,how to make it in action.i want to code like this.

if published value='0' then if i click checkbox and press submit button,the published value='1'.if published value='1' then if i click checkbox and press submit button,the published value='0'.any of your help will be surely appreciated.

thanks
mrjameer

<?php


mysql_connect("localhost", "", "")or die("cannot connect");
mysql_select_db("mrj")or die("cannot select DB");

$sql="SELECT * FROM ahost";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

?>
<center><table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><font color="navy"><form name="form1" method="post" action=""><br><center><b>

<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>

<td bgcolor="lightgreen" align="center"><font color="navy">#</font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>Id</strong></font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>details</strong></font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>bandwidth</strong></font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>email_accounts</strong></font></td>
<td bgcolor="lightgreen" align="center"><font color="navy"><strong>published</strong></font></td>

</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<font color="navy">
<tr class="odd" onmouseover="over(this);" onmouseout="out(this);">
<td align="center"><font color="navy"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></font></td>

<td><font color="navy"><? echo $rows['id']; ?></font></td>
<td><font color="navy"><? echo $rows['details']; ?></font></td>
<td><font color="navy"><? echo $rows['bandwidth']; ?></font></td>
<td><font color="navy"><? echo $rows['email_accounts']; ?></font></td>
<td><font color="navy"><? echo $rows['published']; ?></font></td>
</tr></font>
<?php
}
?>
<tr>
<td colspan="5" align="center" ><input name="delete" type="submit" id="delete" value="unpublish">
</font></td>
</tr></table></center>
<?php

if($delete)
{
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];

$sql = "UPDATE ahost SET published='0' WHERE id='$del_id'";
$result = mysql_query($sql);

}


if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=viewfiles1.php\">";
}


}



mysql_close();


?>
</table>
</form>
</font></td>
</tr>
</table></center>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.