Jump to content

notsophpfreakish

New Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by notsophpfreakish

  1. Ah, that explains it. Now that I think back, I had 'text' there and the entire file was put into the table cell. So, if that's the case, what do I use instead? (I'm very new at javascript and jquery! :-( )
  2. The form wants the user to input a display name. The goal is to check via the jquery $.POST function to send back to this page to check to see if the display name is available. This is the table on the registration page. <table border = '1'> <form id = 'register' action = '#' method = 'post'> <tr><td width = '150'>Display: </td><td width = '200'><input id = 'display' type = 'text' name = 'display' maxlength = '35'></td><td id = 'displaycheck' align = 'center' width = '80'> <?php if(isset($_POST['display'])) { $display = htmlspecialchars($_POST['display']); $display = mysql_real_escape_string($display); $result = mysql_query("SELECT display FROM user WHERE display = '$display' "); $count = mysql_num_rows($result); if($count == 1) { echo "<font color = 'red'>Taken.</font>"; } else { echo "<font color = 'green'>Accepted.</font>"; } } ?> </td></tr></table> This is the Jquery Code: $(document).ready( function () { //Display $('#display').focusin( function() { $('#directions').html('For your display name, you can have up to 35 characters which includes letters, numbers, underscores, periods, and spaces.'); }); $('#display').keyup( function() { var display = $(this).val(); $.post('/registration.php', {display: display}, function(data) { $('#displaycheck').html(data); }); }); ); }); What's happening is the ENTIRE table is reprinted in the table CELL 'displaycheck'. I have NO idea why the entire table is being resent. Can someone pelase help?? I haven't got a clue on how to fix this.
  3. I found a simple way to do the game, BUT, I can't seem to get an array to work.. What happens is that I delete letters form the array instead of going through all the fancy crap.. This is what I have so far: <?php if(!(isset($_POST['set']))) { $words = explode(";", file_get_contents('words.list.txt')); shuffle($words); $word = $words[0]; $arraya = ''; $arrayb = ''; $lowletters = array('a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'); $upletters = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $arraya = ".a.,.b.,.c.,.d.,.e.,.f.,.g.,.h.,.i.,.j.,.k.,.l.,.m., .n.,.o.,.p.,.q.,.r.,.s.,.t.,.u.,.v.,.w.,.x.,.y.,.z."; $arrayb = ".A.,.B.,.C.,.D.,.E.,.F.,.G.,.H.,.I.,.J.,.K.,.L.,.M., .N.,.O.,.P.,.Q.,.R.,.S.,.T.,.U.,.V.,.W.,.X.,.Y.,.Z."; } else if(!(empty($_POST['guess']))) { $word = $_POST['word']; $arraya = $_POST['arraya']; $arrayb = $_POST['arrayb']; $guessa = strtolower($_POST['guess']); $guessb = strtoupper($_POST['guess']); $arraya = str_replace('.', ''', $arraya); $arrayb = str_replace('.', '\'', $arrayb); $guessa = ", $guessa, "; $guessb = ", $guessb, "; $arraya = str_replace($guessa, '', $arraya); $arrayb = str_replace($guessb, '', $arrayb); $lowletters = array($arraya); $upletters = array($arrayb); echo $arraya . "<br>" . $arrayb . "<br>"; echo $guessa . "<br>" . $guessb; echo "<br>$lowletters<br>$upletters<br>"; } foreach($lowletters as $stuff) { echo $stuff . "<br>"; } foreach($upletters as $stuff) { echo $stuff . "<br>"; } $broken = explode(' ', $word); $part1 = $broken[0]; $part2 = @$broken[1]; $part3 = @$broken[2]; $part4 = @$broken[3]; $word1 = str_replace($lowletters, ' _ ', $part1); $word1 = str_replace($upletters, ' _ ', $word1); $word2 = str_replace($lowletters, ' _ ', $part2); $word2 = str_replace($upletters, ' _ ', $word2); $word3 = str_replace($lowletters, ' _ ', $part3); $word3 = str_replace($upletters, ' _ ', $word3); $word4 = str_replace($lowletters, ' _ ', $part4); $word4 = str_replace($upletters, ' _ ', $word4); echo $word1 . " " . $word2 . " " . $word3 . " " . $word4; echo "<form action = '1.php' method = 'POST'>"; echo "<input type = 'text' name = 'guess' size = '5'>"; echo "<input type = 'hidden' name = 'word' value = '$word'>"; echo "<input type = 'hidden' name = 'arraya' value = '$arraya'>"; echo "<input type = 'hidden' name = 'arrayb' value = '$arrayb'>"; echo "<input type = 'hidden' name = 'set' value = 'TRUE'>"; echo "<br><input type = 'submit' value = 'Guess!'></form>"; ?> But for some reason, the edited 'array' doesn't work.. the entire string IS the array rather than the pieces within the string are parts of the array.. how do i fix that?
  4. The frustrating thing for me is that I have coded the rest of my site just fine, using MySQL queries. I have a forum on there, messaging, friending, (it's a neopets type website) so I have shops, a number guessing game, pet and user profiles and everything else, and that's all using mysql queries.. but for some reason, when it comes to this, I can't seem to wrap my mind around it..? Maybe my thought process is a little tainted from the downloaded code and I'm trying to figure that one out too much rather than starting from a true fresh start.. I know what needs to happen with all the little details, just not sure of all the functions I need to do as such.. By other details, I literally mean just the capitalization and spacing, which is a very huge issue with the downloaded code.. not sure why that guy didn't code the game allowing the site to use multiple words, at LEAST. :-/
  5. Can someone point me to a layman's tutorial for a simple hangman game? I downloaded one off the internet, but it doesn't do what I want. The one I use doesn't allow capitalized letters or spaces! I can live without the capitlization but MOST of the words will have spaces and therefore, this code will not work. I want to start a brand new code from scratch but I can't seem to figure it out. I am new to coding and have been coding my site using MySQL, and that's fine, but ALL of the coding for hangman is very confusing for me! $letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z', ' '); if(empty($_POST)) { $rightcount = '0'; $wrongcount = '0'; $words = explode("\n", file_get_contents('words.list.txt')); $right = array_fill_keys($letters, ' _ '); $wrong = array(); shuffle($words); $word = strtolower($words[0]); $rightstr = serialize($right); $wrongstr = serialize($wrong); $wordletters = str_split($word); $show = ''; foreach($wordletters as $letter) { $show .= $right[$letter]; } } else { $show = $_POST['show']; $word = $_POST['word']; $lettercount = strlen($word); echo $lettercount . "<br>"; $word = htmlspecialchars($word); $word = mysql_real_escape_string($word); $rightcount = $_POST['rightcount']; $wrongcount = $_POST['wrongcount']; $guess = strtolower($_POST['guess']); $guess = ctype_alpha($guess); if($guess == TRUE) { $guess = strtolower($_POST['guess']); } else { echo "<b>Please use only letters.</b><br>"; $guess = ''; } $letterinstance = @substr_count($word, $guess); $right = unserialize($_POST['rightstr']); $wrong = unserialize($_POST['wrongstr']); $wordletters = str_split($word); if(!(empty($guess))) { if(stristr($word, $guess)) { $show = ''; $right[$guess] = $guess; $wordletters = str_split($word); $rightcount = $rightcount + (1*$letterinstance); foreach($wordletters as $letter) { $show .= $right[$letter]; } } else { $show = ''; $wrong[$guess] = $guess; $wrongcount = $wrongcount + 1; if(count($wrong) == 6) { $show = $word; echo "You lost this round of hangman.<br>"; } else { foreach($wordletters as $letter) { $show .= $right[$letter]; } } } } $rightstr = serialize($right); $wrongstr = serialize($wrong); echo "Right: $rightcount<br>Wrong: $wrongcount<br>"; if($rightcount == $lettercount) { echo "You win!<br>"; } } echo "Incorrect Guesses: "; echo implode(', ', $wrong); echo "<br>"; echo $show; echo "<br />"; echo "<form method='post'> <input name='guess'>"; echo "<input type='hidden' name='show' value='$show'> "; echo "<input type='hidden' name='rightcount' value='$rightcount'> "; echo "<input type='hidden' name='wrongcount' value='$wrongcount'> "; echo "<input type='hidden' name='word' value='$word'> "; echo "<input type='hidden' name='rightstr' value='$rightstr'>"; echo "<input type='hidden' name='wrongstr' value='$wrongstr'>"; echo "<input type='submit' value='guess'> "; echo "</form>"; echo "<a href='hangman.php'>Reset</a>"; That is the code I am using now. The connect to the database and rewarding the user when they guess all the letters work fine, but I need for my other details to be in there and I have NO clue how to do that. I've tried a lot of things but everything just screws up. Here's the code I have now that is from scratch, and it's very basic. I really have no freakin' clue where to go from there. <?php $words = explode(";", file_get_contents('words.list.txt')); shuffle($words); $word = $words[0]; $upletters = array('a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'); $lowletters = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); echo $word . "<br>"; $word1 = str_replace($upletters, ' _ ', $word); $word1 = str_replace($lowletters, ' _ ', $word1); echo $word1 . "<br><br>"; echo "<form action = '1.php' method = 'POST'>"; echo "<input type = 'text' name = 'guess' size = '10'>"; echo "<input type = 'hidden' name = 'word' value = '$word'>"; echo "<input type = 'hidden' name = 'word1' value = '$word1'>"; echo "<br><input type = 'submit' value = 'Guess!'></form>"; ?> Can someone PLEASE point me in the right direction! Or give me all the functions I need to use to get through this! Thanks in advance.
  6. I'm very new to PHP and have been working on my site idea for the past couple of weeks and have been working on the basic sign up, logging in, activation and log out. The log out works fine, but when I sign in with a second username, the first user name's information comes up instead. Here's the log out script: <?php session_start(); session_unset(); session_destroy(); setrawcookie('user'); ?> I tried a bunch of other stuff but nothing seems to work. Closing the window and stuff works fine but obviously, that's not the safest method.
×
×
  • 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.