Jump to content

Recommended Posts

OK, i'm gonna try to make this as simple as possible. I am trying to make the 'edit' function work for my checkbox on my project management tool. I've gotten it to work, but I'm getting a weird error, and i don't understand why im getting it because everything is working.

 

To start....

 

In my database, I have a table row for each product, there are 14.

 

acro_8_prof, acro_9_prof, acro_conn, etc....

 

When you 'add' a project, the checkboxes use a value of "1" to write to the database. So, if a product falls under a project, it writes a "1" into the table row, and if its not checked, it leaves it blank...

 

On the 'edit' page, I defined the variables like this....

 

$acro_8_prof = $row['acro_8_prof'];

$acro_9_prof = $row['acro_9_prof'];

$acro_conn = $row['acro_conn'];

 

And then wrote an if statment for each one to see if there is a "1" or not....

 

if ($acro_8_prof == "1") {

$p1 = "Checked";

}

 

if ($acro_9_prof == "1") {

$p2="Checked";

}

 

if ($acro_conn == "1") {

$p3="Checked";

}

 

etc......

 

Then, the generate the 'edit' checkbox, I used this.....

 

if ($p1 == "Checked") {

echo "<label><strong>Product</strong></label><br/>

<input type='checkbox' checked='checked' name='edit_acro_8_prof' value='1' />  <label><strong>Acrobat 8 Professional</strong></label><br/>";

}ELSE{

echo "<label><strong>Product</strong></label><br/>

<input type='checkbox' name='edit_acro_8_prof' value='1' />  <label><strong>Acrobat 8 Professional</strong></label><br/>";

}

 

if ($p2 == "Checked") {

echo "<input type='checkbox' checked='checked' name='edit_acro_9_prof' value='1' />  <label><strong>Acrobat 9 Professional</strong></label><br/>";

}ELSE{

echo "<input type='checkbox' name='edit_acro_9_prof' value='1' />  <label><strong>Acrobat 9 Professional</strong></label><br/>";

}

 

if ($p3 == "Checked") {

echo "<input type='checkbox' checked='checked' name='edit_acro_conn' value='1' />  <label><strong>Acrobat Connect</strong></label><br/>";

}ELSE{

echo "<input type='checkbox' name='edit_acro_conn' value='1' />  <label><strong>Acrobat Connect</strong></label><br/>";

}

 

So now....when I click the 'edit' button on the project list page to get to the edit page.....it populates the right checkboxes and seems to be FUNCTIONING correctly, but the checkboxes are being spaced out due to an unusual error, and there is an error underneath each individual checkbox... the error is as follows for all checkboxes..

 

 

 

Notice: Undefined variable: p1 in D:\WebRoot\Domains\adoberegistrations.com\wwwroot\ResourceCenters\OYilmaz\admin\edit_project.php on line 168

 

that is for the first one, Acrobat 9 Professional, and here is the line that it is referring too....

 

if ($p1 == "Checked") {

 

The reason im confused, is because if the varialbes WEREN'T being defined, than the checkboxes wouldn't be populating, but they are, can anyone help me out? Is there something I'm missing?!?

 

THANKS IN ADVANCE

 

Bossman

This is a really round about way of doing this. Why not just have 1 column for the project name and enter like acro_9_prof and whatever else as values in each row? Do projects have multiple of those values checked at a time, or is it usually just 1 project checked?

 

You are getting undefined variable errors because you only define the variable if a certain condition is met. if its not, then the variable won't be set. change your if statements to have an else clause like

 

if ($acro_8_prof == "1") {
$p1 = true; 
}
else {
$p1=false;
}

 

and then when you check it

if ($p1) {

 

Hope that helps

haha yes i know i did it the hard way, but thats what makes php fun. But YES what you just gave me worked, heres what i did ....

 

if ($acro_8_prof == "1") {

$p1 = "Checked";

}ELSE{

$p1 = "";

}

 

if ($acro_9_prof == "1") {

$p2="Checked";

}ELSE{

$p2 = "";

}

 

if ($acro_conn == "1") {

$p3="Checked";

}ELSE{

$p3 = "";

}

 

since i dont need it to do anything if its not checked, i just left that blank, all my errors are gone. I GREATLY appreciate the help sir!!

 

Bossman

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.