Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-13-2007, 08:19 PM Problem with POST
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
There is probably a simple solution to this problem but I've been going over my code for an hour and I can't seem to figure out what is wrong. Here's my code:

PHP Code:
$sql 'SELECT * FROM `groups` WHERE 1 LIMIT 0 , 30';
$result mysql_query($sql);
while(
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
    
$groupName $row['name'];
    
$currGroup $_POST[$groupName]; //This line is giving me trouble
    
if($currGroup != '' or $currGroup != NULL)
    {
        
$hasGroup 1;
        
$sql 'INSERT INTO `'.$dbname.'`.`contacts` (`name`, `address`, `group`, `count`) VALUES (\''.$newName.'\', \''.$newAddress.'\', \''.$groupName.'\', NULL);';
        
mysql_query($sql);
    }

Is it acceptable to use a variable as the argument for $_POST[]? I know for a fact that $groupName is equal to the id of the form that i'm trying to retrieve data from
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
 
Register now for full access!
Old 08-13-2007, 08:24 PM Re: Problem with POST
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
$_POST is not derived from the id, but the name of the input field.

<input type="text" name="This is the POST index name" />


BTW: Its uneccessary to use WHERE 1 in your sql query, you can drop it off if there are no conditions to be used.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-13-2007, 08:27 PM Re: Problem with POST
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I meant name not id, sorry. $groupName is equal to Name but it does not seem to be working still.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-13-2007, 08:41 PM Re: Problem with POST
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Print to the screen the value of $groupName to be sure of its value. Then check if $_POST[$groupName] exists.

echo '$groupName = "' . $groupName . '" and $_POST[$groupName] ' . (isset($_POST[$groupName]) ? 'exists with the value of "' . $_POST[$groupName] . '"' : 'does NOT exists');
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-13-2007, 09:03 PM Re: Problem with POST
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Here is the html for the form I'm trying to get input from:

PHP Code:
<input type="checkbox" id="test group" value="test group" name="test group">test group<br>
<
input type="checkbox" id="testgroup 2" value="testgroup 2" name="testgroup 2">testgroup 2<br>
<
input type="checkbox" id="test group2" value="test group2" name="test group2">test group2<br>
<
input type="checkbox" id="NEW GROUP" value="NEW GROUP" name="NEW GROUP">NEW GROUP<br>
<
input type="checkbox" id="ANOTHER GROUP" value="ANOTHER GROUP" name="ANOTHER GROUP">ANOTHER GROUP<br
and here is the code that generates the code above:

PHP Code:
$sql 'SELECT * FROM `groups` WHERE 1 LIMIT 0 , 30';
                            
$result mysql_query($sql);
                            while(
$row mysql_fetch_array($resultMYSQL_ASSOC))
                            {
                                print 
'<input type="checkbox" id="' $row['name'] . '" value="1" name="'$row['name'] . '">' $row['name'] . '<br>';
                            } 
when I check to see if $_POST['test group'] exists it doesn't... even though it should.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-13-2007, 09:26 PM Re: Problem with POST
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
This may be a silly question, but are you using method="post" in your form tag?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-13-2007, 09:32 PM Re: Problem with POST
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Yeah I am
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-13-2007, 09:39 PM Re: Problem with POST
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The only other thing I would think that might (not quite sure tho) break it is using spaces in the names. Maybe some browsers are encoding them as url encoded names. Try this method:

PHP Code:
$sql 'SELECT * FROM `groups` WHERE 1 LIMIT 0 , 30'
                            
$result mysql_query($sql); 
                            while(
$row mysql_fetch_array($resultMYSQL_ASSOC)) 
                            { 
                                print 
'<input type="checkbox" id="' $row['name'] . '" value="1" name="'str_replace(' ''_'$row['name']) . '">' $row['name'] . '<br>'
                            } 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-13-2007, 09:47 PM Re: Problem with POST
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
That didn't fix it either, but I figured it out... For some reason it doesn't like the space in the name field of the checkbox. So 'test' works, but 'test group' does not.


Thanks for the help, I can get it working from here.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 08-13-2007 at 09:54 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Problem with POST
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.54084 seconds with 12 queries