lilwing Posted July 24, 2008 Share Posted July 24, 2008 I've got something like: <?php $query = mysql_query('SELECT username FROM users WHERE ID > 4 ORDER BY username, permissions ASC'); while($row = mysql_fetch_array($query)) { $list = $row['username']; echo("<li>"); echo('<input type="radio" name="username[]" value="'.$list.'" />' . $list); echo("</li>"); } ?> That works perfectly fine. The value in the html source is correct. However, this is part of a form, and that form tries to post to a table. Everything else posts fine, but this particular field posts "Array" instead of the values I want it to. The query looks like this: <?php $contenttype = $_POST['contenttype']; $contentid = $_POST['contentid']; $contentname = $_POST['contentname']; $contentowner = $_POST['username']; $insert = 'INSERT INTO content (ContentOwner, ContentID, ContentType, ContentName) VALUES ("'.$contentowner.'", "'.$contentid.'", "'.$contenttype.'", "'.$contentname.'")'; mysql_query($insert) or die(mysql_error()); ?> What have I done wrong? ??? Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/ Share on other sites More sharing options...
MFHJoe Posted July 24, 2008 Share Posted July 24, 2008 I'm guessing $contentowner is the one that's not working properly. Run the code below with your form and post the output (I commented out the mySQL bit as we don't need that at the minute). I added a print_r statement that prints an array out in a readable way. You can use it to determine which part of the username array you want to use. <?php $contenttype = $_POST['contenttype']; $contentid = $_POST['contentid']; $contentname = $_POST['contentname']; $contentowner = $_POST['username']; // I added this. print_r($contentowner); /* $insert = 'INSERT INTO content (ContentOwner, ContentID, ContentType, ContentName) VALUES ("'.$contentowner.'", "'.$contentid.'", "'.$contenttype.'", "'.$contentname.'")'; mysql_query($insert) or die(mysql_error()); */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/#findComment-598782 Share on other sites More sharing options...
ranjuvs Posted July 24, 2008 Share Posted July 24, 2008 Try using subscript $_POST['username'][0] Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/#findComment-598785 Share on other sites More sharing options...
MFHJoe Posted July 24, 2008 Share Posted July 24, 2008 Try it using like this.. $_REQUEST['username'][0] Or $_REQUEST['username'][1]. The reason for posting my message above was to figure out which one, but I suppose guessing would be quicker. Just increment the number until you get the value you're looking for. Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/#findComment-598788 Share on other sites More sharing options...
lilwing Posted July 24, 2008 Author Share Posted July 24, 2008 Thanks for the quick responses, guys. That outputs this: Array ( [0] => user1 ) I guess that means use I should use 0, huh? Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/#findComment-598789 Share on other sites More sharing options...
lilwing Posted July 24, 2008 Author Share Posted July 24, 2008 Hmm, well, it doesn't post array, but it doesn't post anything. I tried both of these: $contentowner = $_POST['username'][0]; $contentowner = $_POST['username'][1]; Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/#findComment-598792 Share on other sites More sharing options...
ranjuvs Posted July 24, 2008 Share Posted July 24, 2008 Can you please paste your code here so that I could get a better understanding of your problem Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/#findComment-598798 Share on other sites More sharing options...
lilwing Posted July 24, 2008 Author Share Posted July 24, 2008 Well, I figured it out. //Don't do $_POST['username'][0] //Instead do $contentowner[0] $contentowner = $_POST['username']; echo $contentowner[0]; Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/#findComment-598799 Share on other sites More sharing options...
.josh Posted July 24, 2008 Share Posted July 24, 2008 since username is a radio button, you're only going to have one checked in your form, so there's no reason to make name = 'username[]' an array. just make it name = 'username' and it will post to $_POST['username'] like all your other vars. Quote Link to comment https://forums.phpfreaks.com/topic/116444-solved-mysql-posts-quotarrayquot-instead-of-post-form-value/#findComment-598801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.