INSERT queries
Moderator: General Moderators
INSERT queries
Hi Guys.
I'm trying to make a form for users to submit an entry for a competition. All they hgave to do is select the comp(s) they want from a multiple choice SELECT box and tell us whatever we ask for for that issue (i.e. this issue we are asking for short stories (100 words or less).
How do I get a select box to enter into the DB which selections have been made? So far I'm only able to enter in whatever the last selection made is, and that doesn't help!!
Cheers
~Chris
P.S. Sorry if it's already been answered, i've been searching for hours and no answers
I'm trying to make a form for users to submit an entry for a competition. All they hgave to do is select the comp(s) they want from a multiple choice SELECT box and tell us whatever we ask for for that issue (i.e. this issue we are asking for short stories (100 words or less).
How do I get a select box to enter into the DB which selections have been made? So far I'm only able to enter in whatever the last selection made is, and that doesn't help!!
Cheers
~Chris
P.S. Sorry if it's already been answered, i've been searching for hours and no answers
I've read the PHP manual and 90% of it means jack to me.
I just don't get the manual, I learn better through real world example.
I have written while loops before but never anything to do this. so I do something along the lines of:
What I don't understand if what should be inside the while loop. I can't set all of them into the same varaible.
I just don't get the manual, I learn better through real world example.
I have written while loops before but never anything to do this. so I do something along the lines of:
Code: Select all
while(isset($_POST['comp[])) {
$comp=$_POST['comp[]'];
}Code: Select all
foreach($_POST['comp'] as $temp) {
echo $temp;
}Well here is the deal. (and I am not being sarcastic or anything) Go to php.net and use the search box. Type in while. You will see an example.enigm4_ wrote:What I don't understand if what should be inside the while loop. I can't set all of them into the same varaible.
You will see...
Code: Select all
$i = 1;
while ($i <= 10) {
echo $i++; /* the printed value would be
$i before the increment
(post-increment) */
}Another example would be...
Code: Select all
$Apples = 0;
$GiveMeAnApple = 1;
$MaxApples = 10;
while ($Apples <= $MaxApples) {
$Apples = $Apples + $GiveMeAnApple;
echo "You were just given an apple!<br />";
}ALSO::: If you don't understand what all the !=, ==, <=, etc are. Then you can read about these in the "Operands" section of the manual.
Hey guys,
When I try to submit into my database it gives me an error on line 49 (the foreach line)
error:
Warning: Invalid argument supplied for foreach() in /home/dxqmyhvh/public_html/reakt/inner.php(43) : eval()'d code on line 49
Can anyone tell me why this is? $_POST['entries'] is deffinately the select field.
cheers
When I try to submit into my database it gives me an error on line 49 (the foreach line)
error:
Warning: Invalid argument supplied for foreach() in /home/dxqmyhvh/public_html/reakt/inner.php(43) : eval()'d code on line 49
Code: Select all
if(isset($_POST['submit'])) {
foreach($_POST['entries'] as $comps) {
echo $comps;
}
$story=$_POST['story'];
//Inset everything into the database
$compentry=mysql_query("INSERT INTO tblCompetitionSubmissions (compUserID, compStory, compEntries, compEntryDate) VALUES ('$userid', '$story', '$comps', NOW())");
//Check whether or not the inset worked:
if($compentry) {
//If it worked, echo a success
echo "<div class=\"information\"><h4>Success!</h4><p>Thankyou, your submission has been received. We will let you know if you win!</p></div>";
} else {
//If it failed, show the error:
echo "<div class=\"phpoutput\"><h4>Error</h4><p>Sorry, your submission could not be sent at this time. Please try again later, or <a href=\"mailto:online@reakt.com.au\">email Chris</a> to report your problems.</p></div>";
}
}cheers
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
add
$_POST['entries'] must be an array, what is the var_dump returning?
Code: Select all
var_dump($_POST['entries']);Code: Select all
Warning: Invalid argument supplied for foreach() in /home/dxqmyhvh/public_html/reakt/inner.php(43) : eval()'d code on line 49
array(13) { [0]=> string(38) "I Bet You Look Good on the Dance Floor" [1]=> string(47) "Whatever People Say I Am, That\'s What I\'m Not" [2]=> string(11) "Dirty Harry" [3]=> string(14) "Suddenly I See" [4]=> string(4) "Talk" [5]=> string(17) "Lights and Sounds" [6]=> string(28) "Nobody Move, Nobody Get Hurt" [7]=> string(23) "Can I Have it Like That" [8]=> string(13) "Raven\'s Gate" [9]=> string(83) "Ultimate 10 Passes entitling you and nine friends to two ultimare laser games free!" [10]=> string(13) "One Game Free" [11]=> string(22) "Double Surprise Passes" [12]=> string(36) "T-Shirts (available in red or black)" }here's the PHP that evals and submits it to the db :
Code: Select all
if(isset($_POST['submit'])) {
foreach($_POST['entries[]'] as $comps) {
echo $comps;
}
$story=$_POST['story'];
var_dump($_POST['entries']);
//Inset everything into the database
$compentry=mysql_query("INSERT INTO tblCompetitionSubmissions (compUserID, compStory, compEntries, compEntryDate) VALUES ('$userid', '$story', '$comps', NOW())");
//Check whether or not the inset worked:
if($compentry) {
//If it worked, echo a success
echo "<div class=\"information\"><h4>Success!</h4><p>Thankyou, your submission has been received. We will let you know if you win!</p></div>";
} else {
//If it failed, show the error:
echo "<div class=\"phpoutput\"><h4>Error</h4><p>Sorry, your submission could not be sent at this time. Please try again later, or <a href=\"mailto:online@reakt.com.au\">email Chris</a> to report your problems.</p></div>";
}
}Code: Select all
echo "
<fieldset>
<legend>Entry Form</legend>
<form action=\"";$_SERVER['PHP_SELF'];echo "\" method=\"post\">
<label for=\"entries\">Prizes:</label>
<select name=\"entries[]\" id=\"entries\" size=\"7\" WIDTH=\"250\" STYLE=\"width:250px;\" multiple>
";
$prizes=mysql_query("SELECT * FROM tblPrizes WHERE prizeIssue='$issue' AND prizeVolume='$volume'");
while($prize=mysql_fetch_array($prizes)) {
echo "
<option name=\"$prize[0]\" selected>$prize[2]</option>
";
}
echo"
</select>
<label for=\"story\">Tell us a short story</label>
<textarea name=\"story\" cols=\"5\" rows=\"5\">"; if(isset($_POST['story'])) echo $_POST['story']; echo"</textarea>
<label></label>
<input name=\"submit\" type=\"submit\" value=\"Submit\">
</form>
</fieldset>
";- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: