Can't insert data into mysql after user chooses from an arra

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ossieboy
Forum Newbie
Posts: 1
Joined: Mon Jul 05, 2010 7:22 am

Can't insert data into mysql after user chooses from an arra

Post by Ossieboy »

Good afternoon to you all,

Please could someone kindly help me out with the below? Basically I'm pulling information back from mysql database in the form of football teams and then I've managed to put a drop down next to each of them in order for the user to choose the score. I then can't insert that value into my predictions table:

Code: Select all

<?php


$goals = array ("0", "1", "2","3", "4", "5","6", "7", "8","9", "10");
    
$conn = mysql_connect("localhost","root","swarve") or die(mysql_error());
mysql_select_db("predictions");

$sql = processInput();

function processInput(){
//extract information from above

$WeekNo = $_POST["WeekNo"];


$sql = "SELECT name
FROM `fixtures_table`
INNER JOIN teams_table ON Home_Team_ID = Team_ID
WHERE WeekNo = '$WeekNo'
ORDER BY ID";
return $sql;

} // end processInput
$result = mysql_query($sql, $conn) or die(mysql_error());

while($row = mysql_fetch_assoc($result)){
  foreach ($row as $name => $value){
    print "$value";
    echo "<select>";
    foreach($goals as $goal)
    {
        echo "<option name='$goal'>$goal</option> <br />\n";
    }
    echo "</select>";
} // end foreach
  print "<br> <br />\n";
 
} //end while
               


?>
I'm then trying to insert this into my predictions_table:

<?php
        
$conn = mysql_connect("localhost","root","swarve") or die(mysql_error());
mysql_select_db("predictions");
       
$GoalInsert = $_POST['$goal'];          


$sql = "INSERT INTO predictions_table (,Home_Prediction,Away_Prediction)VALUES ('$GoalInsert','$GoalInsert')";
$result = mysql_query($sql, $conn) or die(mysql_error());
       
    

?>
Basically zero values are being pushed across into the predictions table. Therefore connection is ok, but I'm obviously not doing something right

Thanking you in advance for any help you could give me.

Thanks,

Dave
Last edited by Benjamin on Mon Jul 05, 2010 8:59 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Can't insert data into mysql after user chooses from an

Post by Benjamin »

:arrow: Moved to PHP - Code
Post Reply