Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    AJax PHP Mysql Site load problem

    Hey Guys, frist my English is not so perfect, so respect it please.

    My following code has a few problems

    I would like to get information via selectbox the various sites, but does it work yet from me inexplicably.

    Please help



    PHP Code:
    <?php
    class game {
     
        public function 
    pageload($site) {
     
       for(
    $i=1$i 21$i++)
        {
            switch (
    $site) {
                case 
    "".$i."":
                
    $this->showcomment("".$i."");
                 
    $this->sendentry($_GET['gameid']);
            }
        }
     
     
        }
     
        public function 
    menubar() {
     
                
    $mysqli = new MySQLi('localhost','root','','gamespark');
                
    $result $mysqli->query("SELECT gameid,gamename FROM game");
     
                echo 
    "<form>
                            <select name=\"games\"onchange=\"showUser(this.value)\">
                            <option value=\"\">Select a Game:</option>"
    ;
     
                while(
    $entry $result->fetch_assoc()) {
     
                    echo 
    "<option value=\"".$entry['gameid']."\">".$entry["gamename"]."</option>";    
                }
     
                echo 
    " </select>
                     </form>"
    ;
     
                
    $result->close();
                
    $mysqli->close();
     
                echo 
    '</a></li>'."\n";
     
        }
     
        public function 
    showcomment($gameid) {
     
                  
    $mysqli = new MySQLi('localhost','root','','gamespark');
                  
    $result $mysqli->query("SELECT * FROM kommentiert AS K JOIN game AS g ON K.gameid = G.gameid WHERE G.gameid = '"$gameid ."'  ORDER BY date ASC ");
                  
    $result2 $mysqli->query("SELECT * FROM game WHERE gameid = '".$_GET["gameid"]."'");
     
                  while(
    $row2 $result2->fetch_assoc()){
                                    echo 
    "<center><img height=\"240\" width=\"240\" src=\" ".$row2["imgurl"]."\"/> <br/><br/>";
                                    echo 
    " ".$row2["gamename"]." ";
                                    echo 
    "<br/>Freigegeben ab ".$row2["usk"]." Jahren ";
                                    echo 
    "<br/>Entwickelt von ".$row2["entwickler"]." ";
                                    echo 
    "<br/>Genre:".$row2["genre"]." ";
                                    echo 
    "<br/> Verfügbar auf ".$row2["plattform"]." ";
                                    echo 
    "<br/> Release date: ".$row2["release"]." ";
                                    echo 
    "<br/> Publiziert von:".$row2["publisher"]." </center><br/>";
                                }
     
                                echo 
    "<hr/>";
     
                        if (
    $result) {
     
                            if(
    $result->num_rows 0) {
     
                                while(
    $row $result->fetch_assoc()){
                                    
    $phpdate strtotime($row["date"]);
                                    echo 
    "Verfasst von: " $row["creator"];
                                    echo 
    "&nbsp; Erstellt am:" .date'd-m-Y H:i:s'$phpdate ); echo "&nbsp;Uhr";
                                    echo 
    "<br>Titel: " $row["title"];
                                    echo 
    "<br>Kommentar: " str_replace("\n""<br>"$row["comment"]);
                                    echo 
    "<hr/>";
     
                                }
     
                                    
    $result->close();
     
                            }else{
                                    echo 
    "Es befinden sich der Zeit keine Kommentare in der Datenbank.<br/><hr/>";    
                            }
                        }
                                    
    $mysqli->close();    
            } 
     
        public function 
    sendentry ($id) {
     
     
     
                if(!
    $_POST) { 
     
                 echo 
    '<form id="send" action="" method="POST">
     
                        <table>
     
                            <tr>
                                    <td><label style="float:left; width:100px;">Name:</label><input type="text" name="creator" size="20"/></td>
                            </tr>
     
                            <tr>
                                    <td><label style="float:left; width:100px;">Titel:</label><input type="title" name="title" size="20"/></td>
                            </tr>
     
                            <tr>
                                    <td><label style="float:left; width:110px;">Ihr Kommentar:</label><textarea name="comment" cols="50" rows="10"></textarea></td>
                            </tr>
     
                            <tr>
                                    <td><label style="float:left; width:100px;">Aktionen:</label><input type="submit" name="senden" value="Absenden" /> <input type="reset" value="Abbrechen"/></td>
                            </tr>
     
                        </table>
     
                    </form>'
    ;
     
                 }else{
     
                        
    $mysqli = new MySQLi('localhost','root','','gamespark');
                           
    $fehler '';
     
                        if(empty(
    $_POST['creator'])) 
                         
    $fehler.= '<li>Bitte tragen Sie einen Namen ein.</li>'
     
                        if(empty(
    $_POST['title'])) 
                         
    $fehler.= '<li>Bitte tragen Sie einen Titel ein.</li>';
     
                      if(empty(
    $_POST['comment'])) 
                         
    $fehler.= '<li>Bitte verfassen Sie ein Kommentar.</li>'
     
                         if(
    $fehler != '') {
                                 
    $fehler 'Es ist einer der folgenden Fehler aufgetreten:<br /><ul>' $fehler '</ul>';
                         }else{
     
                        
    $result $mysqli->query("INSERT INTO kommentiert
                         (creator,title,comment,date,gameid)
                           VALUES (
                         '" 
    mysql_real_escape_string($_POST["creator"]) . "',
                         '" 
    mysql_real_escape_string($_POST["title"])     . "',
                         '" 
    mysql_real_escape_string($_POST["comment"])   . "',
                          NOW(),"
    .$id.")");
     
                        echo 
    "<b>Danke f&uuml;r Ihren Eintrag.</b><br><br>";
                         }
                        
    $mysqli->close();
                 }
     
     
        }
     
    }
      
    $game= new game();
     
    ?>
     
    <!DOCTYPE HTML>
    <head>
        <title>Game</title>
        <link rel="stylesheet" type="text/css" href="style.css">
        <meta name="DC.Language" content="de">
        <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
     
        <script>
    function showUser(str)
    {
    if (str=="")
      {
      document.getElementById("txtHint").innerHTML="";
      return;
      } 
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","commentx.php?gameid="+str,true);
    xmlhttp.send();
    }
    </script>
    </head>
     
    <body>
                <div id="gamebar">
                            <ul>
                                <?php
                                    $game
    ->menubar();
                                
    ?>
                            </ul>    
                </div>
     
    <div id='wrapper' class='shadow'>
     
     
            <div id="gamecontent">
     
                <?php
     
                    
    if(!isset($_GET['gameid'])) {
                        echo 
    "<div id=\"txtHint\"><b>Person info will be listed here.</b></div>";
     
                    }else{
     
                        
    $game->pageload($_POST["games"]);
     
                    }
                
    ?>
     
            </div>
    </div>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,084
    Thanks
    23
    Thanked 593 Times in 592 Posts
    I checked your ajax. It's good.
    I think the problem is in calling your sql
    use:
    PHP Code:
    $result mysqli->query("SELECT gameid,gamename FROM game"); 
    Not this:
    PHP Code:
    $result $mysqli->query("SELECT gameid,gamename FROM game"); 
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hey,

    thanks for your fast request.

    When i use your option, it will be shown as error in Dreamweaver.

    Any other idea?

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,084
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Sorry about that. I did something wrong on my end. Just forget that post.

    What is not working? Do you get the "Select a Game" dropdown? is it populated with game names?
    If good to here, do you get info posted when you select a game?
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    darkpuridee (04-01-2013)

  • #5
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    dropdown is working, but when i select a Game, it's not shown the infopage from the games what i selected

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,084
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Ok. The ajax is working for me, lets see if it works for you. Go to function showUser(str). Find this line:
    Code:
    xmlhttp.open("GET","commentx.php?gameid="+str,true);
    Change it to:
    Code:
    xmlhttp.open("GET","test.php?gameid="+str,true);
    and write that file(test.php) like this:
    PHP Code:
    <?php
    $name 
    $_GET['gameid'];
    echo 
    $name;
    ?>
    To save time: If it does not work; sometimes this line in the showUser(str) needs to be
    xmlhttp.send(''); or xmlhttp.send(NULL); At lest for me, so try them for fun.

    If you don't get a return message post the "commentx.php" file.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #7
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok i have created the test.php like your try, now it works for me too.

    But exists a other option where i must not create a new file for this?

    i want thats my code is OOP and not 1000 ... files .php :-)

    Thank YOu

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,084
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Quote Originally Posted by darkpuridee View Post
    Ok i have created the test.php like your try, now it works for me too.

    But exists a other option where i must not create a new file for this?

    i want thats my code is OOP and not 1000 ... files .php :-)

    Thank YOu
    Not sure what you are saying here.

    Anyway, If my php file works and yours still don't, the problem is in the "commentx.php" file. Please post it so we can see where the error is.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •