Jump to content


Photo

Form posting help please, checkbox inputs ******SOLVED******


  • Please log in to reply
8 replies to this topic

#1 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 26 September 2006 - 05:45 AM

Ok I have a mysql query with a loop so it will pull all necasary data out, i need to display a checkboc next to it with a submit button on the bottom of the table to where the selected data will be deleted, kinda like a hotmail mailbox, and the checkbox's value is the id that will submit to a page to parse the data.

this is what i have:
$delete=$_GET[delete];
//FIRST CHECK IF DELETING SO IT DOES NOT SHOW BELOW
if($delete=='invite'){
$sql = "delete from event_invites where event_id=$_POST[eventid] && user_id='$id'";
mysql_query($sql);
echo"<font color=red><center>Events Deleted";

}




if($mail=='invites')) {
echo"<form name=delete action='?delete=invite&mail=invites&sid=$sid' method='post'>";
$sql1 = mysql_query("SELECT * FROM `event_invites` WHERE user_id ='$id' LIMIT $from, $max_results"); 
while($row1 = mysql_fetch_array($sql1)){ 
$eventid=$row1[event_id];

echo"<tr><td><center><input type='checkbox' name='eventid' value='$eventid'>";
}
echo"<input type=submit name='deleteinvite' value='Delete Selected'>";
}


All help appreciated

#2 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 26 September 2006 - 06:37 AM

anything, this has been bothering the heck outa me for hours, can't even sleep because of it...

#3 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 26 September 2006 - 07:25 AM

Just had a quick look and for a start you have a $_POST directly in your query. You should really set this value first as a normal variable then enter it along with ' ' or convert first to an int as you will normally find that mysql might think the value is a var.

I would have a better look but alot of the html go in the way. If you can do a more simple code with just the php and basic html it would be easyier to look at as i don't know long.

I take it that it is a list of check box each with an number value that if the user checks and posts this value will be deleted.

Just looking at your code I would also add after the mysql_query($sql) or die(mysql_error());

I think you have an error in your sql because of the post and no quotes around that value. This should let you know as it will echo it to the screen.

#4 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 26 September 2006 - 07:37 AM

Ok here is a revised version of my code

$delete=$_GET[delete];

//FIRST CHECK IF DELETING SO IT DOES NOT SHOW BELOW

if($delete=='invite'){
$eventid=$_POST[eventid]
$sql = "delete from event_invites where event_id='$eventid' && user_id='$id'";
mysql_query($sql);


//DISPLAY THAT THE EVENT HAS BEEN DELETED

}




if($mail=='invites')) {


//START THE FORM


$sql1 = mysql_query("SELECT * FROM `event_invites` WHERE user_id ='$id' LIMIT $from, $max_results"); 
while($row1 = mysql_fetch_array($sql1)){ 
$eventid=$row1[event_id];

//CHECKBOX WILL DISPLAY HERE


}

//WITH SUBMIT BUTTON TO FOLLOW

}

Hope that's a little better

#5 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 26 September 2006 - 07:40 AM

and i added the or die(mysql_error()); and it returns nothing.

#6 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 26 September 2006 - 07:58 AM

Basicly what i need is to have a check box with the same name, like a radio button would but has different values, reason being i am not using a radio button is because only one can be selected, checkbox's can have multiple but the conflict is that they all have the same name

#7 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 26 September 2006 - 08:23 AM

Anything???

#8 warewolfe

warewolfe
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts
  • LocationOtago, NZ

Posted 26 September 2006 - 08:30 AM

hej
  Perhaps if you want multiple values to go to the same name then that name should be an array. Eg checkboxName[]

WW




#9 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 26 September 2006 - 08:49 AM

Thanks, i have it working now, here is the code i used:



if($delete=='invite'){
//remove junk requests
$posted=$_POST[eventid];
foreach ($posted as $posted) {
$sql = "delete from event_invites where event_id='$posted' && user_id='$id'";
mysql_query($sql) or die(mysql_error());
}
echo"<font color=red><center>Events Deleted</font>";

}




echo"<tr><td><center><input type='checkbox' name='eventid[]' value='$eventid'>";

I appreciate the help guys




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users