Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Anyone good with PHP ? Need some help!!!

Thread Tools
 
Search this Thread
 
Old 11 March 2004, 12:08 PM
  #1  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default Anyone good with PHP ? Need some help!!!

I cannot get it to detect whether a checkbox on my form was ticked or not.

The problem i think is that there are a number of checkboxes, which are numbered according to the id of that row of data in the database - i.e. chk1, chk2 etc. The row number on the processing page is held in the $tmpid variable.

Currently I have:
Code:
if ( $debug == '1' ) { echo("<i>$tmpid - ". $_POST['chk$tmpid' ] ."</i>\n"); }
Which obviously doesn;t work, but how do i get it to work?

Andy

Last edited by SiDHEaD; 11 March 2004 at 12:09 PM.
Old 11 March 2004, 12:21 PM
  #2  
judgejules
Scooby Regular
 
judgejules's Avatar
 
Join Date: Nov 2000
Posts: 1,227
Likes: 0
Received 0 Likes on 0 Posts
Default

Not knowing PHP yet (my books are at home), it would seem you're trying to get the values out of the variable chk$tmpid rather than chk1 chk2 etc.

Try

['chk'.$tmpid]

So you're appending tmpid to the string chk. Not sure if thats the right syntax.

J
Old 11 March 2004, 12:30 PM
  #3  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

I tried that, but i changed it a bit for this page so that it was easier to see what vars i was working with.
I had
Code:
$tmpid - ". $_POST['chk' .$tmpid ] ."</i>
Doesnt work!

Now, i will want to be using the checkbox as an if using isset() , but i need to know it is reading the checkbox first!

Edit: tmpid definately contains a var, as it prints the number out before the hyphen!

Last edited by SiDHEaD; 11 March 2004 at 12:33 PM.
Old 11 March 2004, 12:34 PM
  #4  
chump
Scooby Regular
 
chump's Avatar
 
Join Date: Feb 2004
Posts: 266
Likes: 0
Received 0 Likes on 0 Posts
Default

You need to create a new variable to concatenate (spelling) the two variables:

$newvariable = "chk"."$tmpid";


If say the value of $tmpid is 1 then when you echo $newvariable you should see chk1

Not sure if this is want you mean but......

Chump
Old 11 March 2004, 12:36 PM
  #5  
judgejules
Scooby Regular
 
judgejules's Avatar
 
Join Date: Nov 2000
Posts: 1,227
Likes: 0
Received 0 Likes on 0 Posts
Default

Check boxes are only passed if they are checked.

Dunno if that helps?

J
Old 11 March 2004, 12:41 PM
  #6  
SiDHEaD
Scooby Regular
Thread Starter
 
SiDHEaD's Avatar
 
Join Date: Apr 2002
Location: Birmingham
Posts: 9,196
Likes: 0
Received 0 Likes on 0 Posts
Default

Ooo i've done it. Stuck the string of the checkbox value's variable name 'chk1' etc into a variable called $tmpchk and gave it directly to the post bit. A bit bodge but it works. Its only for our intranet so i don't care overly!

Andy
Old 11 March 2004, 12:54 PM
  #7  
judgejules
Scooby Regular
 
judgejules's Avatar
 
Join Date: Nov 2000
Posts: 1,227
Likes: 0
Received 0 Likes on 0 Posts
Default

Hmm interesting, mine worked:

index.htm
Code:
<html>
<head>
</head>
<body>
<form action="a.php" method="post" name="wib">
<input name="chk1" value="ace">
<input name="submit" value="submit" type="submit">
</form>
</body>
</html>
a.php
Code:
<?
$tmpid = 1;
echo("<i>$tmpid - ". $_POST['chk'.$tmpid ] ."</i>\n"); 
?>

Last edited by judgejules; 11 March 2004 at 12:54 PM.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
blackandz
General Technical
0
12 September 2015 07:01 PM



Quick Reply: Anyone good with PHP ? Need some help!!!



All times are GMT +1. The time now is 01:49 PM.