Jump to content

PHP_POST form problem


Lonig

Recommended Posts

this thing is stuck in a loop... I'm trying to figure out how I can do this loop to work to my needs. I know this is simple and I'm just doing it wrong.the previous page has a form that POSTs to this page. However, it posts lightName1, lightName2, etc etc. So I am trying to get the information to set variables that I am using farther down the page... which does another loop(one that works). Any ideas would be appreciated. Hopefully I find my mistake before you all have to, I know it's something simple...

$lt = 0;$lightTotal = $_POST["lightTotal"];do  {  $lt++;	$lightName .$lt = $_POST["lightName" . $lt];	$lcolor . $lt = $_POST["lightColor" . $lt . "Light"];	$lightEffect . $lt = $_POST["lightEffect" . $lt];	$lightColor . $lt = $_POST["lightColor" . $lt];	$goodRefer . $lt = $_POST["goodRefer" . $lt];	$badRefer . $lt = $_POST["badRefer" . $lt];  }while ($lt<$lightTotal);?>

Link to comment
Share on other sites

You can't make a variable name with DOT. A dot operation is what we call a right-hand value. Right of the equals sign, that is. What you really want is series of arrays. Like this:$lightName[$lt] = $_POST["lightName" . $lt]; #assuming your form names really look like that.

Link to comment
Share on other sites

Argh, why does w3schools and the php manual have to try and be so confusing on form data with arrays... I think I need to setup something like:

<?phpif ($_POST) {	echo '<pre>';	echo htmlspecialchars(print_r($_POST, true));	echo '</pre>';}?><form action="" method="post">	Name:  <input type="text" name="personal[name]" /><br />	Email: <input type="text" name="personal[email]" /><br />	Beer: <br />	<select multiple name="beer[]">		<option value="warthog">Warthog</option>		<option value="guinness">Guinness</option>		<option value="stuttgarter">Stuttgarter Schwabenbräu</option>	</select><br />	<input type="submit" value="submit me!" /></form>

But I cannot figure out how to READ it once I put it in... I dont understand how to read the array and separate it into variables after.ie: If I setup linkName to an array, how do I pull each one out and name them linkName1, linkName2, etc etc. the amount of linkNames will be however many "linkTotal" there is. Bleh... I have the first two pages done and naturally it doesn't display the dang data on the last page. This is rather frustrating...Sorry, i don't normally get this flustered. I just thought I had a good grasp on what I was doing and it turns out I don't I guess. 2 pages don't mean much if the 3rd doesn't work. And I'd rather not have to set each variable individually, as that will be a horrible mess to work with.

Link to comment
Share on other sites

You don't need to pull them out of the array, that's what the array is, it's a data storage structure. You can store it all right there. linkName1 would be $linkName[0], then $linkName[1], $linkName[2], etc. Arrays start at 0, not 1. But you don't need to remove the data from the array, a variable like $linkName[0] is just like any other variable, you can read it, write to it, whatever.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...