vividona Posted June 10, 2010 Share Posted June 10, 2010 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 More sharing options...
vividona Posted June 10, 2010 Author Share Posted June 10, 2010 no help? Link to comment https://forums.phpfreaks.com/topic/204366-for-looping-problem/#findComment-1070449 Share on other sites More sharing options...
thomashw Posted June 10, 2010 Share Posted June 10, 2010 Your question is confusing... can you explain what the problem is better? Possibly with an example? Link to comment https://forums.phpfreaks.com/topic/204366-for-looping-problem/#findComment-1070452 Share on other sites More sharing options...
mrMarcus Posted June 10, 2010 Share Posted June 10, 2010 ya...what? Link to comment https://forums.phpfreaks.com/topic/204366-for-looping-problem/#findComment-1070456 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.