Jump to content

for looping problem


vividona

Recommended Posts

Hi,

 

Plz examin this code

 

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

for($i = 1; $i <= $this->pnum; $i++){
	if($_POST["text$i"] == "")
	{
			throw new Exception('You have to fill all options');
	}
}

for($i = 1; $i <= $this->pnum; $i++){
	$option = $_POST["text$i"];
	$pollq2 = $SiteDatabase->dbqueries("INSERT INTO
	" . BhlPoll::BHL_DB_PREFIX . "" . BhlPoll::BHL_POLL_V . " (`pid`, `options`, `optid`)
	VALUES (
	'".$_GET['pid']."',
	'".mysql_real_escape_string($option)."',
	'".mysql_real_escape_string($this->pnum)."')") or die(mysql_error());
}
}else{	
?>
<form action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?action=rpoll&pnum=<?PHP echo  $this->pnum; ?>' method='post'>
<fieldset>
<legend>Poll Form</legend>
<p>Fields marked * are compulsory.</p>
<dl>
	<dt><label for='username'>Poll Question: *</label></dt>
<?PHP
	for($i = 1; $i <= $this->pnum; $i++){
		echo "<dd>option".$i." : <input type='text' name='text$i' id='name' value='' /></dd>";
		echo "text$i";
	}
?>
	<dd><input type="submit" name="submit" value="Add a poll" /><dd>
</dl>
</fieldset>
</form>
<?PHP
}

 

this code works fine

 

The problem in [iNSERT INTO]. I need to insert [for looping $i] into [option column]

and the other columns remain without any changes. I try many time but other columns repeat when (for looping $i) repeats.

Link to comment
https://forums.phpfreaks.com/topic/204366-for-looping-problem/
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.