Jump to content

Array error, help!


uncaringuser

Recommended Posts

I am not adequate at PHP at all, I mostly dabble in HTML and CSS.  The problem here is that I have a form which has been assigned unique variables via database.  The user would select a checkbox and the value associated with it based on its name and id, would display the appropriate value on the next page.  For whatever reason when I active my form it just comes up with the word "Array".

 

Below is the code for both pages and I would be greatly appreciated if you could help me resolve this error and point me in the right direction to achieve my goal.

 

FORM WITH UNIQUE VARIABLES

 

<code>

<?php

 

$con = mysql_connect("database details");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("webnw_catering", $con);

 

$result= mysql_query("SELECT * FROM starters WHERE category='meat'");

 

while($row = mysql_fetch_array($result))

{

$nameid = $row['nameid'];

$amountid = $row['amountid'];

$title = $row['title'];

$checkbox = $_POST['checkbox'];

 

echo"<tr>";

echo"<td>";

echo"<p class=\"form2\">";

echo $row["title"];

echo " - £";

echo $row["price"];

echo"<br>";

echo"<span class=\"subtext\">". $row['subtext'] . "</span>";

echo"</p>";

echo"</td>";

echo"<td class=\"addon\">";

echo"<input type=\"checkbox\" class=\"largecheckbox\" name=\"checkbox[{$row['title']}]\" id =\"$nameid\" value=\"$title\">";

echo"</td>";

echo"<td class=\"addon\">";

echo"<input type=\"text\" class=\"amount\" name=\"amount[]\" id =\"$amountid\">";

echo"</td>";

echo"</tr>";

}

echo "";

 

mysql_close($con);

?>

</code>

 

RESPONSE PAGE

 

<code>

 

                        <div id="middle">

<div id="stepcontent" class="form">

 

<div id="content-left">

<img src="./images/meat.png" class="food"><br><br>

<table class="food">

<tr>

<td><p class="form2"><?php echo $_POST["checkbox"]; ?></p></td>

</tr>

<tr>

<td><p class="form2"></p></td>

</tr>

</table>

</div>

 

</code>

Link to comment
https://forums.phpfreaks.com/topic/262733-array-error-help/
Share on other sites

I did, and I know but it is, I dunno why it is coming up with it, I'm stumped.

 

Here's the entire code in a more appropriate format.

 

<!DOCTYPE html>
<html>
<head>
<title>Mistrys Catering</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div id="canvas">
	<div id="header">
		<div id="logo"></div>
		<div id="slogan"></div>
	</div>

	<div id="top">
	<div id="step">Step 3 of 10</div><div id="detail"><img src="./images/starters.png"></div>
	</div>

	<div id="middle">
		<div id="stepcontent" class="form">

		<div id="content-left">
		<img src="./images/meat.png" class="food"><br><br>
		<form method="post" action="step4.php">
		<table class="food">
		<?php

		$con = mysql_connect("database details");
		if (!$con)
		  {
		  die('Could not connect: ' . mysql_error());
		  }

		mysql_select_db("webnw_catering", $con);

		$result= mysql_query("SELECT * FROM starters WHERE category='meat'");

		while($row = mysql_fetch_array($result))
		{
		$nameid = $row['nameid'];
		$amountid = $row['amountid'];
		$title = $row['title'];
		$checkbox = $_POST['checkbox'];

		echo"<tr>";
		echo"<td>";
		echo"<p class=\"form2\">";
		echo $row["title"];
		echo " - £";
		echo $row["price"];
		echo"<br>";
		echo"<span class=\"subtext\">". $row['subtext'] . "</span>";
		echo"</p>";
		echo"</td>";
		echo"<td class=\"addon\">";
		echo"<input type=\"checkbox\" class=\"largecheckbox\" name=\"checkbox[{$row['title']}]\" id =\"$nameid\" value=\"$title\">";
		echo"</td>";
		echo"<td class=\"addon\">";
		echo"<input type=\"text\" class=\"amount\" name=\"amount[]\" id =\"$amountid\">";
		echo"</td>";
		echo"</tr>";
		}
		echo "";

		mysql_close($con);
		?>

		</table>
		</div>


		<div id="content-right">
		<img src="./images/veg.png" class="food"><br><br>
		<table class="food">

		</table>
		</div><br>

		</div>
	</div>

	<div id="bottom">
		<div id="build"></div>
		<div id="backbutt"><a href="step2.html"><img src="./images/prevbutt.png"></a></div>
		<div id="nextbutt"><input type="image" src="./images/nextbutt.png"></div>
		</form>
		</div>
	</div>

	<div id="footer">
	<p class="footer">Mistrys Catering | 01204 527 139 | [email protected]</p>
	</div>

</div>
</body>
</html>

 

<!DOCTYPE html>
<html>
<head>
<title>Mistrys Catering</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div id="canvas">
	<div id="header">
		<div id="logo"></div>
		<div id="slogan"></div>
	</div>

	<div id="top">
	<div id="step">Step 4 of 10</div><div id="detail"><img src="./images/starters.png"></div>
	</div>

	<div id="middle">
		<div id="stepcontent" class="form">

		<div id="content-left">
		<img src="./images/meat.png" class="food"><br><br>
		<table class="food">
		<tr>
		<td><p class="form2"><?php echo $_POST["checkbox"]; ?></p></td>
		</tr>
		<tr>
		<td><p class="form2"></p></td>
		</tr>
		</table>
		</div>


		<div id="content-right">
		<img src="./images/veg.png" class="food"><br><br>
		<table class="food">
		<tr>
		<td><p class="form2"></p></td>
		</tr>
		<tr>
		<td><p class="form2"></p></td>
		</tr>
		</table>
		</div><br>
		</div>
	</div>

	<div id="bottom">
		<div id="build"></div>
		<div id="backbutt"><a href="step2.html"><img src="./images/prevbutt.png"></a></div>
		<div id="nextbutt"><input type="image" src="./images/nextbutt.png"></div>
		</form>
		</div>
	</div>

	<div id="footer">
	<p class="footer">Mistrys Catering | 01204 527 139 | [email protected]</p>
	</div>

</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/262733-array-error-help/#findComment-1346598
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.