Page 1 of 1

PHP Array not saving entire string

Posted: Wed Jun 06, 2007 8:27 pm
by True Story
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


First, thanks in advance for any help that I can get with this.

I'm having a problem with assigning string values to an array. The project I'm working on sends an email from Flash using PHP. The email sends just fine, however the values that appear in the email don't appear correct.

The following is the code that assigns the values. For some reason when I set the email to just send $bentonArray[0] the only thing that appears in the email is an "E" instead of "Easel Chartpad". However I tell the email to display $bentonArray[0] and $bentonArray[1] it displays "Ea".

I've been through tons of websites and FAQs about arrays in PHP and don't see what I'm doing wrong.

Code: Select all

<?php

$bentonArray = array();

$i = 0;
	
	if($eq001_benton.selected == true)
	{
		$bentonArray[$i] = "Easel Chartpad";
		$i++;
	}
	
	if ($eq002_benton.selected == true)
	{
		$bentonArray[$i] = "Laser Pointer";
		$i++;
	}
	
	if ($eq003_benton.selected == true)
	{
		$bentonArray[$i] = "Wireless PC Remote";
		$i++;
	}
	
	if ($eq004_benton.selected == true)
	{
		$bentonArray[$i] = "Wireless High Speed Internet";
		$i++;
	}
	
	if ($eq005_benton.selected == true)
	{
		$bentonArray[$i] = "Laptop";
		$i++;
	}
	
	if ($eq006_benton.selected == true)
	{
		$bentonArray[$i] = "VHS Camcorder w/Tripod";
		$i++;
	}
	
	if ($eq007_benton.selected == true)
	{
		$bentonArray[$i] = "3'x5' Whiteboard & Markers";
		$i++;
	}
	
	if ($eq008_benton.selected == true)
	{
		$bentonArray[$i] = "Network Switches";
		$i++;
	}
	
	if ($ost001_benton.selected == true)
	{
		$bentonArray[$i] = "Onsite Technician (Mon-Fri)";
		$i++;
	}
	
	if ($ost002_benton.selected == true)
	{
		$bentonArray[$i] = "Onsite Technician (Sat & Sun)";
		$i++;
	}
	
	if ($proj001_benton.selected == true)
	{
		$bentonArray[$i] = "61-inch Plasma Digital TV";
		$i++;
	}
	
	if ($proj002_benton.selected == true)
	{
		$bentonArray[$i] = "35mm Slide Projector";
		$i++;
	}
	
	if ($proj003_benton.selected == true)
	{
		$bentonArray[$i] = "DVD/VCR Player";
		$i++;
	}
	
	if ($ac001_benton.selected == true)
	{
		$bentonArray[$i] = "Polycom Conference Phone";
		$i++;
	}
	
	if ($ac002_benton.selected == true)
	{
		$bentonArray[$i] = "Long Distance Calls";
		$i++;
	}
	
	if ($ac003_benton.selected == true)
	{
		$bentonArray[$i] = "Local Calls";
		$i++;
	}
	
	if ($oe001_benton.selected == true)
	{
		$bentonArray[$i] = "VGA/Audtio Extension Cables";
		$i++;
	}
	
	if ($oe002_benton.selected == true)
	{
		$bentonArray[$i] = "Handheld Crestron";
		$i++;
	}
	
	if ($oe003_benton.selected == true)
	{
		$bentonArray[$i] = "In-Table Data/Power Mounts";
		$i++;
	}
	
	if ($oe004_benton.selected == true)
	{
		$bentonArray[$i] = "2 Power Strips";
		$i++;
	}
	
	if ($oe005_benton.selected == true)
	{
		$bentonArray[$i] = "Data Cables";
		$i++;
	}

?>
In case it's needed, here's the PHP file that sends the email:

Code: Select all

<?php
$to = "digitalphoenixx@gmail.com";
$msg = "$name\n\n";
$msg .= "$message\n\n"; 

$msg .=  $bentonArray[0];


mail($to, $subject, $msg, "From: Website Correspondence\nReply-To: $email\n");
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jun 06, 2007 8:42 pm
by nickvd

Code: Select all

if($eq001_benton.selected == true)
   {
      $bentonArray[$i] = "Easel Chartpad";
      $i++;
   }
This is not proper php code... it seems like a mix of javascript with php...

Posted: Wed Jun 06, 2007 8:48 pm
by True Story
nickvd wrote:

Code: Select all

if($eq001_benton.selected == true)
   {
      $bentonArray[$i] = "Easel Chartpad";
      $i++;
   }
This is not proper php code... it seems like a mix of javascript with php...
I don't understand how it's not proper PHP. Can you explain?

Posted: Wed Jun 06, 2007 8:59 pm
by Benjamin
Your syntax is not correct. You cannot access a property of a variable with a .

Correct would be more along the lines of..

Code: Select all

if (isset($_POST['eq001_benton']) && $_POST['eq001_benton'] == 'checked')
{
    $bentonArray[$i] = "Easel Chartpad";
    $i++;
}
Assuming your input field was..

Code: Select all

<input type="checkbox" name="eq001_benton" value="checked" />

Posted: Wed Jun 06, 2007 9:06 pm
by True Story
astions wrote:Your syntax is not correct. You cannot access a property of a variable with a .

Correct would be more along the lines of..

Code: Select all

if (isset($_POST['eq001_benton']) && $_POST['eq001_benton'] == 'checked')
{
    $bentonArray[$i] = "Easel Chartpad";
    $i++;
}
Assuming your input field was..

Code: Select all

<input type="checkbox" name="eq001_benton" value="checked" />
My input field is a checkbox component in Flash. In Actionscript the way the property is accessed is:

Code: Select all

checkboxName.selected
The PHP files are being imported into Flash using the loadVariablesNum() function:

Code: Select all

loadVariablesNum("array.php", 1);
I'll try the way you did it and see if it works. I've tried everything else at this point. :?

Posted: Wed Jun 06, 2007 9:10 pm
by Benjamin
In that case, to debug the script, echo what is being submitted to your processing script with the following. It will tell you the names of the post variables actually being posted..

Code: Select all

echo '<pre>' . print_r($_POST, true) . '</pre>';

Posted: Wed Jun 06, 2007 9:22 pm
by True Story
Thanks. I'm gonna try that work on it for a few more hours tonight.