Current location: Hot Scripts Forums » Programming Languages » PHP » PHP adding disable and enable buttons


PHP adding disable and enable buttons

Reply
  #1 (permalink)  
Old 03-22-07, 03:00 PM
pablo1999 pablo1999 is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
PHP adding disable and enable buttons

I have a form that enters the following information to a MySql database table using PHP. The information gets properly added to the database with no problems.


First Name
Last Name
Company
Date
Quote

By default, every new entry will be enabled.


I have a second form that shows the information that got added, plus 3 more columns to delete, enable, or disable an specific entry.

Delete (radiobutton)
Enable (radiobutton)
Disable (radiobutton)
Id
First Name
Last Name
Company
Date
Quote

I have third form that displays all the information inside the table.

On my second form, how can I insert to the database if the record is enabled, disabled or deleted??

On my third form, how can I have the form only pull the records that are enabled??




The following is my code for the second form, the one that is used for deleting, enabling or disabling a record.


PHP Code:

<?php

$host
="localhost";
$username="user";
$password="user";
$db_name="user";
$tbl_name="mytable";


// Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

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

$count=mysql_num_rows($result);

?>

<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">Delete</td>
<td align="center" bgcolor="#FFFFFF">Enable</td>
<td align="center" bgcolor="#FFFFFF">Disable</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>First Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Last Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Company</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Date</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Quote</strong></td>
</tr>

<?php

while($rows mysql_fetch_array($result)){

?>

<tr>
<td align="center" bgcolor="#FFFFFF"><input name="radiobutton[]" type="radio" id="radiobutton[]" value="<? echo $rows['pers
onID'
]; ?>"></td>
<td align="center" bgcolor="#FFFFFF"><input name="radiobutton[]" type="radio" id="radiobutton[]" value="<? echo $rows['pers
onID'
]; ?>"></td>
<td align="center" bgcolor="#FFFFFF"><input name="radiobutton[]" type="radio" id="radiobutton[]" value="<? echo $rows['pers
onID'
]; ?>"></td>

<td bgcolor="#FFFFFF"><? echo $rows['personID']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['FirstName']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['LastName']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Company']; ?></td>

<td bgcolor="#FFFFFF"><? echo $rows['Date']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Quote']; ?></td>
</tr>
<?php
}
?>

<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?

//Check if delete button active, start this loop


if($delete){
for(
$i=0;$i<$count;$i++){
$del_id $checkbox[$i];
$sql "DELETE FROM $tbl_name WHERE personID='$del_id'";
$result mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result){
echo 
"<meta http-equiv=\"refresh\" content=\"0;URL=mytable.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>

Last edited by Nico; 03-22-07 at 03:02 PM. Reason: Please use [php] wrappers when posting PHP code.
Reply With Quote
  #2 (permalink)  
Old 03-22-07, 04:49 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
I have a form that enters the following information to a MySql database table using PHP. The information gets properly added to the database with no problems.

First Name
Last Name
Company
Date
Quote
Question 1: Are these the only fields in your database table?

First Name
Last Name
Company
Date
Quote

Quote:
By default, every new entry will be enabled.
Question 2: How are you planning to enable each entry?

Quote:
I have a second form that shows the information that got added, plus 3 more columns to delete, enable, or disable a specific entry.

Delete (radiobutton)
Enable (radiobutton)
Disable (radiobutton)
Id
First Name
Last Name
Company
Date
Quote
Question 3: The second form has nine fields. Two of which can be combined (Enable/Disable). Does your database table also have eight fields?

Quote:
I have third form that displays all the information inside the table.
Question 4: I am assuming here that this form (table) will contain these fields?

Id
First Name
Last Name
Company
Date
Quote

Quote:
On my second form, how can I insert to the database if the record is enabled, disabled or deleted??
Answer 1: First make sure your database table has eight fields.

Delete
Enable/Disable
Id
First Name
Last Name
Company
Date
Quote

Then you can toggle the Enable/Disable field in the database table. Either before you enter the data in to the database table or after. You can also toggle the Delete field to mark and unmark a record for deletion.

Quote:
On my third form, how can I have the form only pull the records that are enabled?
Answer 2: You use a select query to pull up only records with a value in their Enable/Disable field.

I don’t understand why you need a third form and not just a table. Maybe you want to have the ability to edit any record. But then you could design a form that would do a query from information you input into it and display it in a form (table).
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 03-23-07, 08:50 AM
pablo1999 pablo1999 is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Question 1: Are these the only fields in your database table?
The fields are the following

personID (auto increments)
First Name
Last Name
Company
Date
Quote

Quote:
Question 2: How are you planning to enable each entry?
I have a form that lets the user enter the information mentioned above, except the personID which is something MySql is using internally.

In that form there will be 2 radio buttons included, one named enable and the other named disable.

Most users will select enable since its a new entry. I also want the disable button in the form just in case they want to add an the information to the database but with the status disabled.


Quote:
The second form has nine fields. Two of which can be combined (Enable/Disable). Does your database table also have eight fields?
My database does not have 8 fields. I need to add the rest. Should I have just one column for the Enable/Disable radio buttons?

Quote:
Question 4: I am assuming here that this form (table) will contain these fields?
The thing is I have two different pages displaying the information. One page will be the admin panel that will give you access to all the information - FirstName, LastName, personID and the enable,diable and delete functionality etc, etc.. The other page will only be used to display information that is enabled from the admin panel.


I will follow your inputs and if you have anything else to add I will really appreciated.

Thanks.
Reply With Quote
  #4 (permalink)  
Old 03-23-07, 06:37 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Ok, lets start with these fields:

personID (auto increments)
First Name
Last Name
Company
Date
Quote

And we'll add one more field:

cont_rol

Now it's very simple to tag a record as Enabled (cont_rol = 1), Disabled (cont_rol = 0 and Delete (cont_rol = 2). Your using radio buttons, I would give them one id and three different values (0, 1 & 2). Then store that value in cont_rol when the record is created. And you can do a query later and change cont_rol value if you wish or any other value in the record.

The rest is just querying the database for the record you want and loading it into a form. You could even create dynamic forms and edit any record.
__________________
Jerry Broughton

Last edited by job0107; 03-23-07 at 06:45 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 05:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.