...

View Full Version : AJax PHP Mysql Site load problem



darkpuridee
03-29-2013, 12:16 PM
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
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>

sunfighter
03-29-2013, 02:22 PM
I checked your ajax. It's good.
I think the problem is in calling your sql
use:

$result = mysqli->query("SELECT gameid,gamename FROM game");
Not this:

$result = $mysqli->query("SELECT gameid,gamename FROM game");

darkpuridee
03-29-2013, 09:27 PM
Hey,

thanks for your fast request.

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

Any other idea?

sunfighter
04-01-2013, 01:30 AM
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?

darkpuridee
04-01-2013, 12:47 PM
dropdown is working, but when i select a Game, it's not shown the infopage from the games what i selected

sunfighter
04-01-2013, 02:36 PM
Ok. The ajax is working for me, lets see if it works for you. Go to function showUser(str). Find this line:

xmlhttp.open("GET","commentx.php?gameid="+str,true);
Change it to:
xmlhttp.open("GET","test.php?gameid="+str,true);
and write that file(test.php) like this:

<?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.

darkpuridee
04-01-2013, 09:53 PM
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

sunfighter
04-02-2013, 01:32 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum