Jump to content

[SOLVED] mysql posts "Array" instead of post form value


lilwing

Recommended Posts

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?  ???

Link to comment
Share on other sites

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());
*/
?>

Link to comment
Share on other sites

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.

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.