Jump to content


Array to string conversion error

  • Please log in to reply
1 reply to this topic

#1 JamesKoash

  • Members
  • PipPip
  • Member
  • 23 posts

Posted 29 August 2013 - 10:57 PM

I'm getting the following error:

Array to string conversion in C:\wamp\www\survey\page_3.php on line 164

Here is my code, which is a slightly tweaked version of something given to me by a user of this forum.

  $marketingvalueArray = array('1' => '1',
                          '2' => '2',
                          '3' => '3',
                          '4' => '4',
                          '5' => '5');
$marketingvalueOutput = "";
foreach($marketingvalueArray AS $key => $value) {
    //### Checks to see if 'outsource' is posted AND whether its an array AND it the value exists i n the posted array
    $checked = (isset($_POST['marketingvalue']) && is_array($_POST['marketingvalue']) && in_array($key, $_POST['marketingvalue'])) ? 'checked' : '' ;
    $marketingvalueOutput .= '<input type="radio" class="radio" name="marketingvalue[' . $key .']" value="'. $key .'" '. $checked .'>'. $value .' ';


		if (isset($_POST['marketingvalue'])) {

			$test = ($_POST['marketingvalue']);

Line 164 is where I have referenced $test. I was testing to see what data was coming back through $_POST['marketingvalue'].


All I want to do is get a string from radio buttons/checkboxes, rather than an array, so that I can easily export the information into SQL. However, I don't want to totally get rid of the for loop as it has saved me a lot of time, rather than having to input the code for individual radio buttons.

I've posted a few other threads about related issues (I've been struggling with this code for the past few days) but no one has been able to help. If someone could point me in the right direction I'd appreciate it greatly.



#2 AbraCadaver

  • Gurus
  • Creepy Ass Cracka Memba
  • 1,893 posts
  • LocationThe Republic of Texas

Posted 29 August 2013 - 11:38 PM

Nothing about:

$test = ($_POST['marketingvalue']);

Would cause:

Array to string conversion in C:\wamp\www\survey\page_3.php on line 164

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users