Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Update mysql database after PHP script has been executed
    primarykey
    data
    text
    <p>I'm working on a php script and using mysql databases to make a sports picks website. The users will submit their picks into a mysql database, and based on whether those picks are right or wrong, I want to give them a certain score. </p> <p>The problem is of course the users will be making these picks BEFORE each sporting event so I need a way to update the page after each event to score users based on the information(picks) they gave in the table. I have everything scripted out including a FUNCTION called <code>fun();</code> that would score users based on their picks. I tested the script, and after I submitted my picks I tried to add <code>fun();</code> to the script and save it. The score table didn't update.</p> <p>How can I update the PHP script? I hope all this makes sense. Here is the function code and the script I'm trying to add the function to.</p> <p>Here is the Function. It tests pick1. <pre><code>function fun() { //loop declare begin $quer = "SELECT * FROM sffedorvsdan WHERE username = '$_SESSION[username]'"; if($quer_run = mysql_query($quer)) { while($row = mysql_fetch_assoc($quer_run)) { $pick1 = $row['pick1']; $pick2 = $row['pick2']; $pick3 = $row['pick3']; $pick4 = $row['pick4']; $pick5 = $row['pick5']; $pick6 = $row['pick6']; //loop end EXCEPT CLOSE $user = $_SESSION['username']; if($pick1 == '11') { $score = mysql_query("UPDATE stats SET score = (score + 10), mmascore = (mmascore + 10), wins = (wins + 1), games =(games + 1) WHERE username = '$user'"); return $score; } else if($pick1 == '21') { $score2 = mysql_query("UPDATE stats SET score = (score - 5), mmascore = (mmascore - 5), games = (games + 1) WHERE username = '$user'"); return $score2; } } }else{ echo mysql_error(); } } ?&gt; </code></pre> <p>Heres the main script including html and where I want fun(); to go. In the //Pick Start comments only pay attention to //Pick 1 Start as it's the only one I'm trying to test.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;?php session_start(); if ($_SESSION['username']) { $connect2 = //WHERE I CONNECT TO DATABASE $sql = "SELECT * FROM access WHERE username = '$_SESSION[username]'"; $query = mysql_query($sql,$connect2); if ($query) { while ($row = mysql_fetch_assoc($query)) { $activated = $row['sf']; if ($activated!='0') { die("You've already submitted your answers&lt;br&gt;&lt;a href='mmanav.php'&gt;BACK&lt;/a&gt;"); } } } $user = "Welcome, ".$_SESSION['username']."!&lt;br&gt;&lt;a href='logout.php'&gt;Logout&lt;/a&gt;"; } else { die("You must be logged in!"); } //PICK VARIABLES $dan_status = 'unchecked'; $fedor_status = 'unchecked'; $paul_status = 'unchecked'; $tyron_status = 'unchecked'; $tim_status = 'unchecked'; $robbie_status = 'unchecked'; $tarec_status = 'unchecked'; $scott_status = 'unchecked'; $marloes_status = 'unchecked'; $miesha_status = 'unchecked'; //function file include('fun.php'); //function file end if (isset($_POST['submit'])) { $connect = //WERE I CONNECT TO DATABASE //PICK 1 START $selected_radio = $_POST['fighter']; if ($selected_radio == 'dan') { $dan_status = 'checked'; mysql_query("INSERT INTO sffedorvsdan (id,username,pick1) VALUES ('','$_SESSION[username]','11')"); //insert table data picks } else if ($selected_radio == 'fedor') { $fedor_status = 'checked'; mysql_query("INSERT INTO sffedorvsdan (id,username,pick1) VALUES ('','$_SESSION[username]','21')"); //insert table data picks } //PICK 2 START $selected2_radio = $_POST['fighter2']; if ($selected2_radio == 'paul') { $paul_status = 'checked'; /*mysql_query("UPDATE stats SET score = (score + 10), mmascore = (mmascore + 10) WHERE username = '$_SESSION[username]'");*/ } else if ($selected2_radio == 'tyron') { $tyron_status = 'checked'; /*mysql_query("UPDATE stats SET score = (score - 5), mmascore = (mmascore - 5) WHERE username = '$_SESSION[username]'");*/ } //PICK 3 START $selected3_radio = $_POST['fighter3']; if ($selected3_radio == 'tim') { $tim_status = 'checked'; /*mysql_query("UPDATE stats SET score = (score + 10), mmascore = (mmascore + 10) WHERE username = '$_SESSION[username]'");*/ } else if ($selected3_radio == 'robbie') { $robbie_status = 'checked'; /*mysql_query("UPDATE stats SET score = (score - 5), mmascore = (mmascore - 5) WHERE username = '$_SESSION[username]'");*/ } //PICK 4 START $selected4_radio = $_POST['fighter4']; if ($selected4_radio == 'tarec') { $tarec_status = 'checked'; //mysql_query("UPDATE stats SET score = (score + 10), mmascore = (mmascore + 10) //WHERE username = '$_SESSION[username]'"); } else if ($selected4_radio == 'scott') { $scott_status = 'checked'; //mysql_query("UPDATE stats SET score = (score - 5), mmascore = (mmascore - 5) //WHERE username = '$_SESSION[username]'"); } //PICK 5 START $selected5_radio = $_POST['fighter5']; if ($selected5_radio == 'marloes') { $marloes_status = 'checked'; //mysql_query("UPDATE stats SET score = (score + 10), mmascore = (mmascore + 10) //WHERE username = '$_SESSION[username]'"); } else if ($selected5_radio == 'miesha') { $miesha_status = 'checked'; //mysql_query("UPDATE stats SET score = (score - 5), mmascore = (mmascore - 5) //WHERE username = '$_SESSION[username]'"); } mysql_query("UPDATE access SET sf ='1' WHERE username = '$_SESSION[username]'"); fun(); //WHERE FUN WILL GO AFTER I RUN THE SCRIPT ONCE die("Your picks have been submitted!&lt;br&gt;&lt;a href='gamenav.php'&gt;Return&lt;/a&gt;"); } ?&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;link rel="stylesheet" type="text/css" href="home.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="container"&gt; &lt;div class="log"&gt; &lt;?php echo $user; ?&gt; &lt;/div&gt; &lt;div class="logo"&gt; &lt;img src="IB SportsTV Logo.png" width="240px" height="180px"/&gt; &lt;/div&gt; &lt;FORM name ="form" method ="POST" action ="picks.php"&gt; &lt;div class="mainform"&gt; &lt;Input type = 'Radio' Name ='fighter' value= 'dan' &lt;?PHP print $dan_status; ?&gt; &gt;Dan Henderson&lt;br&gt; &lt;img src="Dan_Henderson.jpg" width="100" height="100"/&gt;&lt;br&gt; &lt;Input type = 'Radio' Name ='fighter' value= 'fedor' &lt;?PHP print $fedor_status; ?&gt; &gt;Fedor Emelianenko&lt;br&gt; &lt;img src="Fedor_Emelianenko.png" width="100" height="100"/&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div class="form2"&gt; &lt;Input type = 'Radio' Name ='fighter2' value= 'paul' &lt;?PHP print $paul_status; ?&gt; &gt;Paul Daley&lt;br&gt; &lt;img src="Paul_Daley.png" width="100" height="100"/&gt;&lt;br&gt; &lt;Input type = 'Radio' Name ='fighter2' value= 'tyron' &lt;?PHP print $tyron_status; ?&gt; &gt;Tyron Woodley&lt;br&gt; &lt;img src="Tyron_Woodley.jpg" width="100" height="100"/&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div class="form3"&gt; &lt;Input type = 'Radio' Name ='fighter3' value= 'tim' &lt;?PHP print $tim_status; ?&gt; &gt;Tim Kennedy&lt;br&gt; &lt;img src="Tim_Kennedy.png" width="100" height="100"/&gt;&lt;br&gt; &lt;Input type = 'Radio' Name ='fighter3' value= 'robbie' &lt;?PHP print $robbie_status; ?&gt; &gt;Robbie Lawler&lt;br&gt; &lt;img src="Robbie_Lawler.png" width="100" height="100"/&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div class="form4"&gt; &lt;Input type = 'Radio' Name ='fighter4' value= 'tarec' &lt;?PHP print $tarec_status; ?&gt; &gt;Tarec Saffiedine&lt;br&gt; &lt;img src="Tarec_Saffiedine.png" width="100" height="100"/&gt;&lt;br&gt; &lt;Input type = 'Radio' Name ='fighter4' value= 'scott' &lt;?PHP print $scott_status; ?&gt; &gt;Scott Smith&lt;br&gt; &lt;img src="Scott_Smith.png" width="100" height="100"/&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div class="form5"&gt; &lt;Input type = 'Radio' Name ='fighter5' value= 'marloes' &lt;?PHP print $marloes_status; ?&gt; &gt;Marloes Coenen&lt;br&gt; &lt;img src="Marloes_Coenen.jpg" width="100" height="100"/&gt;&lt;br&gt; &lt;Input type = 'Radio' Name ='fighter5' value= 'miesha' &lt;?PHP print $miesha_status; ?&gt; &gt;Miesha Tate&lt;br&gt; &lt;img src="Miesha_Tate.png" width="100" height="100"/&gt;&lt;br&gt; &lt;/div&gt; &lt;div class="submitbutton"&gt; &lt;P&gt; &lt;Input type = "Submit" Name = "submit" VALUE = "SUBMIT PICKS"&gt; &lt;/FORM&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload