Jump to content

Post value not evaluating true?


flambo

Recommended Posts

Hi,

 

Apologies if this is rather easy but wondered how you would get around the following problem.

 

I have a post being sent on a checked form that has the name set to a value used in my DB, for example:

 

<input type="checkbox" name="<?PHP echo $rows ["catID"] ?>">

 

Where name would equal something like 11. I'm trying to right some code that inserts data from the rows that have been checked, bit like the below:

 

while($rows = $database->fetch_array($result)){
    $strSQL='INSERT INTO affiliate_join_cat (ajcCatID, ajcAffID) VALUES ('.$rows["catID"].', '.$_POST["affID"].')';
	if ($_POST($rows["catID"])=="on"){
		$database->query($strSQL);

 

so my post will look something like 11 = on, dependent on the row checked. But there is something wrong with this part of the code:

 

$_POST($rows["catID"])=="on"

 

my thoughts are that until catID actually equals 11 this does not evaluate to anything? So have tried using empty and isset to handle it without any success.

 

Not sure what to do next?

 

Thanks in advance

Link to comment
Share on other sites

AK's code is correct.

 

You had parens instead of brackets, which would cause PHP to attempt to execute a function named after the $_POST array, but that would throw a fatal error. 

 

You're going about this wrong btw.  Name all your checkboxes "catID[]".  All of them, named JUST like that.  Each of their VALUES needs to be the actual catID.

 

Then, in your code, $_POST['catID'] will be an array of all the checked catIDs.

Link to comment
Share on other sites

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.