Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding php code after If statment
    primarykey
    data
    text
    <p>I'm new to PHP, and I'm working on a random number game. If the user guesses the right number, he gets a point. However, I am having trouble giving the point to the user. This is the code that I have for the game:</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;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;result&lt;/title&gt; &lt;link href="style.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="main"&gt;&lt;/div&gt; &lt;div id="enterNumber"&gt; &lt;?php $number_actual = rand(1, 20); $number_guess = $_REQUEST["inputnumber"]; echo "You chose: " . $number_guess . "&lt;br /&gt;"; echo "The random number is: " . $number_actual . "&lt;br /&gt;"; if ($number_guess == $number_actual) echo "You guessed &lt;b&gt;Correctly!&lt;/b&gt;"; elseif ($number_guess &lt; $number_actual) { echo "You are too &lt;b&gt;Low&lt;/b&gt;!"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Try guessing again..."; echo "&lt;form&gt; &lt;input type='text' name='inputnumber' /&gt; &lt;input type='submit' value='Guess' /&gt; &lt;/form&gt;"; } elseif ($number_guess &gt; $number_actual) { echo "You are too &lt;b&gt;High&lt;/b&gt;!"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Try guessing again..."; echo "&lt;form&gt; &lt;input type='text' name='inputnumber' /&gt; &lt;input type='submit' value='Guess' /&gt; &lt;/form&gt;"; } ?&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This is the code that gives the user a point, but I am getting a problem adding them together!</p> <pre><code>$query = mysql_query("SELECT * FROM quiz WHERE username='$username'"); $insert = "UPDATE `users` SET `points` = (`points` + 1) WHERE `username` = '".$username."'"; mysql_query($insert); header('location: succes.php'); } } ?&gt; </code></pre> <p>When I tried to add them, I did it like this:</p> <pre><code>&lt;?php $number_actual = rand(1, 20); $number_guess = $_REQUEST["inputnumber"]; echo "You chose: " . $number_guess . "&lt;br /&gt;"; echo "The random number is: " . $number_actual . "&lt;br /&gt;"; if ($number_guess == $number_actual) $query = mysql_query("SELECT * FROM quiz WHERE username='$username'"); $insert = "UPDATE `users` SET `points` = (`points` + 1) WHERE `username` = '" . $username . "'"; mysql_query($insert); header('location: succes.php'); } echo "You guessed &lt;b&gt;Correctly!&lt;/b&gt;"; elseif ($number_guess&lt;$number_actual) { echo "You are too &lt;b&gt;Low&lt;/b&gt;!"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Try guessing again..."; echo "&lt;form&gt; &lt;input type='text' name='inputnumber' /&gt; &lt;input type='submit' value='Guess' /&gt; &lt;/form&gt;"; } elseif ($number_guess&gt;$number_actual) { echo "You are too &lt;b&gt;High&lt;/b&gt;!"; echo "&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Try guessing again..."; echo "&lt;form&gt; &lt;input type='text' name='inputnumber' /&gt; &lt;input type='submit' value='Guess' /&gt; &lt;/form&gt;"; } ?&gt; </code></pre>
    singulars
    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