Jump to content

webdevdea

Members
  • Posts

    144
  • Joined

  • Last visited

Everything posted by webdevdea

  1. Still having trouble getting my array's to associate, could someone give me a hint as to where I am going wrong? v
  2. Ok here is what I am working with right now, I still am really confused as to how I am messing up.. Help please and thank you .. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Didja Know?</title> </head> <body> <h1>Didja Know?</h1> <?php //create arrays $cust1 = array ( "CustName" => "Fred", "CustAddress" => "123", "CustCity" => "Atlanta", "CustState" => "GA" ); $cust = array ( "CustName" => "dred", "CustAddress" => 1293, "CustCity" => "Atlanhta", "CustState" => "GA" ); $cust3 = array ( "CustName" => "Frsded", "CustAddress" => "132423", "CustCity" => "Atlan2343ta", "CustState" => "G23A" ); $cust4 = array ( "CustName" => "Fre34d", "CustAddress" => "114323", "CustCity" => "Atlafdasfnta", "CustState" => "GafdasA" ); //set up master array $customers = array ( "001" => $cust1, "002" => $cust2, "003" => $cust3, "004" => $cust4 ); $CustName = filter_input(INPUT_POST, "CustName"); $cust_info = filter_input(INPUT_POST, "cust_info"); $did_ja = $customers[$CustName][$cust_info]; print "<h3>$CustName and $cust_info is $did_ja. </h3>"; ?> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DIDJA KNOW</title> </head> <body> <h1>DIDJA KNOW</h1> <form action = "http://localhost/Assignments php class/assign7.php" method = "post"> <table border = "1"> <tr> <th>Customer Number</th> <th>Customer Info</th> </tr> <!-- note each option value is a string --> <tr> <td> <select name = "CustName"> <option value = "DeAnna">069</option> <option value = "Josh">088</option> <option value = "Eden">087</option> <option value = "Aubs">2009</option> </select> </td> <td> <select name = "cust_info"> <option value = "CustName">Customer Name</option> <option value = "CustAddress">Address</option> <option value = "CustCity">City</option> <option value = "CustState">state</option> </select> </td> </tr> <tr> <td colspan = "2"> <input type = "submit" value = "Didja Know This?" /> </td> </tr> </table> </form> </body> </html>
  3. I worked on the Php file a little more, maybe closer? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Didja Know?</title> </head> <body> <h1>Didja Know?</h1> <?php //create arrays $cust069 = array ( "cust_name" => "DeAnna", "cust_addr" => 103, "cust_city" => "Atlanta", "cust_email" => "d@d.com" ); $cust088 = array ( "cust_name" => "Josh", "cust_addr" => 104, "cust_city" => "Columbus", "cust_email" => "J@J.com" ); $cust087= array ( "cust_name" => "Eden", "cust_addr" => 107, "cust_city" => "Smyrna", "cust_email" => "E@E.com" ); $cust2009 = array ( "cust_name" => "Aubrey", "cust_addr" => 103, "cust_city" => "Atlanta", "cust_email" => "A@A.com" ); //set up master array $customers = array ( "cust069" => $cust069, "cust088" => $cust088, "cust087" => $cust087, "cust2009" => $cust2009 ); $cust_name = filter_input(INPUT_POST, "cust_name"); $cust_info = filter_input(INPUT_POST, "cust_info"); $did_ja_know = $customers[$cust_name][$cust_info]; print "<h3>$cust_name and $cust_info is $did_ja_know.</h3>"; ?> </body> </html>
  4. I changed the html some <td> <select name = "cust_name"> <option value = "DeAnna">069</option> <option value = "Joshua">088</option> <option value = "Eden">087</option> <option value = "Aubrey">2009</option> </select> </td> <td> <select name = "cust_info"> <option value = "cust_name">Customer Name</option> <option value = "cust_addr">Address</option> <option value = "cust_city">City</option> <option value = "cust_email">email</option> </select> </td> </tr> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Didja Know?r</title> </head> <body> <h1>Didja Know?</h1> <?php //create arrays $cust069 = array ( "cust_name" => "DeAnna", "cust_addr" => 103, "cust_city" => "Atlanta", "cust_email" => "d@d.com" ); $cust088 = array ( "cust_name" => "Josh", "cust_addr" => 104, "cust_city" => "Columbus", "cust_email" => "J@J.com" ); $cust087= array ( "cust_name" => "Eden", "cust_addr" => 107, "cust_city" => "Smyrna", "cust_email" => "E@E.com" ); $cust2009 = array ( "cust_name" => "Aubrey", "cust_addr" => 103, "cust_city" => "Atlanta", "cust_email" => "A@A.com" ); //set up master array $customers = array ( "069" => $cust069, "cust088" => $cust088, "cust087" => $cust087, "cust2009" => $cust2009 ); $cust_name = filter_input(INPUT_POST, "cust_name"); $cust_info = filter_input(INPUT_POST, "cust_info"); $customers = $customers[$cust_name][$cust_info]; print "<h3>$cust_name and $cust_info is $customers .</h3>"; ?> </body> </html> so I have something confused when calling out the $cust_info variable
  5. Oh ok, lol let me check it out and see, Ok so I have changed my php could you see if its anything close to right lol <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Didja Know?r</title> </head> <body> <h1>Didja Know?</h1> <?php //create arrays $cust069 = array ( "cust_name" => "DeAnna", "cust_addr" => 103, "cust_city" => "Atlanta", "cust_email" => "d@d.com" ); $cust088 = array ( "cust_name" => "Josh", "cust_addr" => 104, "cust_city" => "Columbus", "cust_email" => "J@J.com" ); $cust087= array ( "cust_name" => "Eden", "cust_addr" => 107, "cust_city" => "Smyrna", "cust_email" => "E@E.com" ); $cust2009 = array ( "cust_name" => "Aubrey", "cust_addr" => 103, "cust_city" => "Atlanta", "cust_email" => "A@A.com" ); //set up master array $customers = array ( "069" => $cust069, "cust088" => $cust088, "cust087" => $cust087, "cust2009" => $cust2009 ); $cust_name = filter_input(INPUT_POST, "cust_name"); $cust_info = filter_input(INPUT_POST, "cust_info"); $customers = $customers[$cust_name][$cust_info]; print "<h3>$cust_name and $cust_info is $customers .</h3>"; ?> </body> </html> I know I have something worded wrong, one of my variables maybe in the wrong place????
  6. you can go to this link and see what is happening, its a link from an old course I took but I can still up load files and play with them http://www.ctcsports.org/upload/Fall2012/CIST1520/900104329/Assignment13/Assignment7.html
  7. Ok a dropdown comes up and you choose a person's name, then in another drop down you choose customer number,address,city,email and it is supposed to come up with the name, the data name and the data it comes up with the name and the variable name of the data but that's it.. does that help you ?
  8. I am supposed to have an array so that when you choose a customer and one of the information items, its displays, well its almost there here is my php and html, when you run it it hast cust_num or cust_city or cust_state instead of the data itself so help please <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Didja Know?r</title> </head> <body> <h1>Didja Know?</h1> <?php //create arrays $cust_num = array ( "DeAnna" => 069, "Joshua" => 088, "Eden" => 087, "Aubrey" => 2009 ); $cust_addr = array ( "DeAnna" => 102, "Joshua" => 113, "Eden" => 104, "Aubrey" => 420 ); $cust_city = array ( "DeAnna" => "Atlanta", "Joshua" => "Columbus", "Eden" => "Smyrna", "Aubrey" => "Vinnings" ); $cust_email = array ( "DeAnna" => "deanna@gmail.com", "Joshua" => "josh@gmail.com", "Eden" => "eden@gmail.com", "Aubrey" => "Aubrey@gmail.com" ); //set up master array $distance = array ( "DeAnna" => $cust_num, "Joshua" => $cust_addr, "Eden" => $cust_city, "Aubrey" => $cust_email ); $cust_name = filter_input(INPUT_POST, "cust_name"); $cust_info = filter_input(INPUT_POST, "cust_info"); $result = $distance[$cust_name][$cust_info]; print "<h3>$cust_name and $cust_info is $result .</h3>"; ?> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DIDJA KNOW</title> </head> <body> <h1>DIDJA KNOW</h1> <form action = "http://localhost/Assignments php class/assign7.php" method = "post"> <table border = "1"> <tr> <th>Customer Name</th> <th>Customer Info</th> </tr> <!-- note each option value is a string --> <tr> <td> <select name = "cust_name"> <option value = "DeAnna">DeAnna</option> <option value = "Joshua">Joshua</option> <option value = "Eden">Eden</option> <option value = "Aubrey">Aubrey</option> </select> </td> <td> <select name = "cust_info"> <option value = "cust_num">Customer Number</option> <option value = "cust_addr">Address</option> <option value = "cust_city">City</option> <option value = "cust_email">email</option> </select> </td> </tr> <tr> <td colspan = "2"> <input type = "submit" value = "Didja Know This?" /> </td> </tr> </table> </form> </body> </html>
  9. Yeah, the styling is up to us, I could not get any colors that I could see with that background, but I liked it lol, so Im pretty sure I should get an A lol.. thanks again for the help, You should be teaching this stuff lol..
  10. http://www.ctcsports.org/upload/Summer2013/CIST2351/900104329/Assignments.php Go to Assignment 6
  11. working on some style now, will post the final uploaded playable result tomorrow.. goodnight and thank you so much,
  12. Ok so I got a little more work done, it still will not recycle when you click submit the second time, for loop maybe? help please.. <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; $start_game = isset($_POST['start_game']) ? $_POST['start_game'] : 0; $myGuess=rand($lowest,$highest); if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; else if ($_POST['choice']=="start_game"){ echo "My Guess: $myGuess "; } //This is used for debugging - keeping track of what each value is when the submit button is pressed //if(isset($_POST['choice'])){ //print_r($_POST); //} } ?> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="radio" name="choice" value="start_game"><b>StartGame</b><br /> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> <p>Guess: <?php print $myGuess; ?> </p> <?php echo "<br> <a href='http://localhost/Assignments php class/As6.php'>Reset Game</a>" ?>; </form> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <form method = "post" action="" name= "start_game"> <input type ="Submit" name = "start_game" value = "Start Game" align ="MIDDLE"> </form> </body> </html>
  13. Ok Getting a Little closer Now when you start the game and hit submit, well it does not guess another number <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["start_game"])){ if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); } //This is used for debugging - keeping track of what each value is when the submit button is pressed //if(isset($_POST['choice'])){ //print_r($_POST); //} ?> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> <p>Guess: <?php print $myGuess; ?> </p> <?php echo "<br> <a href='http://localhost/Assignments php class/As6.php'>Reset Game</a>" ?>; </form> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <form method = "post" action="" name= "start_game"> <input type ="Submit" name = "start_game" value = "Start Game" align ="MIDDLE"> </form> </body> </html>
  14. Closer? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["start_game"])){ if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); } else { echo "<br> <a href='http://localhost/Assignments php class/As6.php'>Reset Game</a>" ; } //This is used for debugging - keeping track of what each value is when the submit button is pressed //if(isset($_POST['choice'])){ //print_r($_POST); //} ?> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> <?php echo "<br> <a href='http://localhost/Assignments php class/As6.php'>Reset Game</a>" ?>; </form> <form method = "post" action="" name= "start_game"> <input type ="Submit" name = "start_game" value = "Start Game" align ="MIDDLE"> </form> <p>Guess: <?php print $myGuess; ?> </body> </html>
  15. Ok I am stuck, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["start_game"])){ if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); } else { //This is used for debugging - keeping track of what each value is when the submit button is pressed //if(isset($_POST['choice'])){ //print_r($_POST); //} ?> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> <?php echo "<br> <a href='Assignment6.php'>Reset Game</a>" ?>; </form> <form method = "post" action="" name= "start_game"> <input type ="Submit" name = "start_game" value = "Start Game" align ="MIDDLE"> </form> <p>Guess: <?php print $myGuess; ?> } </body> </html>
  16. Almost there, try this .. <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["start_game"])){ if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); } //This is used for debugging - keeping track of what each value is when the submit button is pressed //if(isset($_POST['choice'])){ //print_r($_POST); //} ?> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> <?php echo "<br> <a href='Assignment6.php'>Reset Game</a>" ?>; </form> <form method = "post" action="" name= "start_game"> <input type ="Submit" name = "start_game" value = "Start Game" align ="MIDDLE"> </form> <p>Guess: <?php print $myGuess; ?> </body> </html>
  17. Is this anything close? its not working right but maybe its close? <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } if (isset($_POST["start_game"])){ $myGuess=rand($lowest,$highest); } //This is used for debugging - keeping track of what each value is when the submit button is pressed //if(isset($_POST['choice'])){ //print_r($_POST); //} ?> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> <?php echo "<br> <a href='Assignment6.php'>Reset Game</a>" ?>; </form> <form method = "post" action="" name= "start_game"> <input type ="Submit" name = "start_game" value = "Start Game" align ="MIDDLE"> <?php echo "<br> <a href='Assignment6.php'>Reset Game</a>" ?>; </form> <p>Guess: <?php print $myGuess;?> </body> </html>
  18. How could i fix it so that you have to click the button before the computer starts picking a number? <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); //This is used for debugging - keeping track of what each value is when the submit button is pressed //if(isset($_POST['choice'])){ //print_r($_POST); //} ?> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> <?php echo "<br> <a href='http://localhost/Assignments%20php%20class/Assignment6.php'>Reset Game</a>" ?>; </form> <p>Guess: <?php print $myGuess;?> </body> </html>
  19. Oh and it works great on firefox, it gets stuck on high number on safari, I do not have explorer on my mac
  20. So I had this mixed up, was that what was making it keep go back to one? //Before $myGuess = isset($_POST['correct']) ? $_POST['correct'] : 0; //After $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0;
  21. <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['myGuess']) ? $_POST['myGuess'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); //This is used for debugging - keeping track of what each value is when the submit button is pressed if(isset($_POST['choice'])){ print_r($_POST); } ?> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="high" name="high" value="<?php echo $highest ?>"/> <input type="hidden" id="low" name="low" value="<?php echo $lowest ?>"/> <input type="hidden" id="myGuess" name="myGuess" value="<?php echo $myGuess ?>"/> <input type="hidden" id="counter" name="counter" value="<?php echo $counter ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> </form> <p> You,The user, Think of a number, and I, the computer will try and guess it </p> <p>Guess: <?php print $myGuess;?> </body> </html> This is what I have now, the mystery code was something a friend had tried to add to make it work, obviously it did not work. I had added print_r($_POST); so that I could make sure the variables were getting passed correctly, I think it may be acting the right way now, I am going to take your advise and go over the code so I can understand what I did not understand. Thank you so much. Did you try the game?
  22. For some reason when you hit to high it always goes back to one, is there any way to prevent this or should I just leave well enough alone? <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_SESSION["counter"])){ $counter = $_SESSION["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; print <<< HERE <form action = "" method = "post"> HERE; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['correct']) ? $_POST['correct'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); $show_submit = true; if(!isset($_SESSION['number_to_guess'])){ $num = rand(1, 100); $_SESSION['number_to_guess'] = $num; } else{ $num = $_SESSION['number_to_guess']; } if(isset($_POST['btn_new'])){ session_destroy(); header("location: index.php"); } if(isset($_POST['btn_new'])){ session_unset($_SESSION['number_guess']); header("location: index.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Guess the number</title> </head> <body> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="hidden" id="highest" value="<?php echo $highest ?>"/> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="hidden" id="lowest" value="<?php echo $lowest ?>"/> <input type="Submit" value="Submit" align="MIDDLE"> </form> <p>Guess: <?php print $myGuess;?> <form method="post" action="" name="myGuess"> <br /> </form> </body> </html>
  23. But remember each time you must save the values of low and high either as hidden in the form or as a session variable. Then they must be retrieved back whenever needed (such as right before you reset low or high or get a random value
  24. It seems to be passing the variable I do believe, can you run this and see ? Please and thank you <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php print_r($_POST); if (isset($_SESSION["counter"])){ $counter = $_SESSION["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; print <<< HERE <form action = "" method = "post"> HERE; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['correct']) ? $_POST['correct'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); $show_submit = true; if(!isset($_SESSION['number_to_guess'])){ $num = rand(1, 100); $_SESSION['number_to_guess'] = $num; } else{ $num = $_SESSION['number_to_guess']; } if(isset($_POST['btn_new'])){ session_destroy(); header("location: index.php"); } if(isset($_POST['btn_new'])){ session_unset($_SESSION['number_guess']); header("location: index.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Guess the number</title> </head> <body> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="Submit" value="Submit" align="MIDDLE"> </form> <p>Guess: <?php print $myGuess;?> <form method="post" action="" name="myGuess"> <br /> </form> </body> </html>
  25. OK if someone could run this and see if you could help me figure out my little problems, Its almost there .. :-) Please and thank you . <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Computer can you guess my number</title> <style type = "text/css"> body { background: pink; color: green; } </style> </head> <body> <?php if (isset($_SESSION["counter"])){ $counter = $_SESSION["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; print <<< HERE <form action = "" method = "post"> HERE; $highest = isset($_POST['high']) ? $_POST['high'] : 100; $lowest = isset($_POST['low']) ? $_POST['low'] : 1; $myGuess = isset($_POST['correct']) ? $_POST['correct'] : 0; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; else if($_POST['choice']=="high") $highest=$myGuess-1; else if($_POST['choice']=="low") $lowest=$myGuess+1; } $myGuess=rand($lowest,$highest); $show_submit = true; if(!isset($_SESSION['number_to_guess'])){ $num = rand(1, 100); $_SESSION['number_to_guess'] = $num; } else{ $num = $_SESSION['number_to_guess']; } if(isset($_POST['btn_new'])){ session_destroy(); header("location: index.php"); } if(isset($_POST['btn_new'])){ session_unset($_SESSION['number_guess']); header("location: index.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Guess the number</title> </head> <body> <form method="post" action="" name="choice"> <input type="radio" name="choice" value="correct"><b>Correct!</b><br> <input type="radio" name="choice" value="high"><b>Too High</b><br> <input type="radio" name="choice" value="low"><b>Too Low</b><br> <input type="Submit" value="Submit" align="MIDDLE"> </form> <p>Guess: <?php print $myGuess;?> <form method="post" action="" name="myGuess"> <br /> </form> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.