Request met ajax
POST_gb.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
$habbo=$_REQUEST['habbonaam'];
$username=$_REQUEST['username'];
$text=$_REQUEST['text'];
if($text = "") {
echo ubb('[fullalert]Je moet wel een tekst invoeren voordat je een bericht in het gastenboek kunt zetten!<br>
<input type="button" value="Sluiten" onclick="javascript:melding_close();" />[/fullalert]');
}else{
mysql_query('INSERT INTO guestbook (to_user,from_user,text,date,ip) VALUES ("'.$habbo.'","'.$username.'","'.$text.'",NOW(),"'.$_SERVER['REMOTE_ADDR'].'")"');
echo'<table>
<tr><td width="100%"><table width="100%" style="border: dashed 1px; border-color: #EFEFEF;" cellspacing="0" cellpadding="0">
<tr>
<td style="background: #EFEFEF;"><div style="float: left; margin-top: 5px;"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?user='.$_SESSION['username'].'&action=sta&frame=3&direction=2&head_direction=2&gesture=sml&size=s&img_format=png" border="0" onerror="this.src=(\'http://www.habbowereld.nl/assets/img/site/error_habboSmall.png\')" /></div>
<div style="float: left; margin-left: -25px;"><strong><a href="http://www.habbowereld.nl/leden/profiel/'.$_SESSION['username'].'">'.$_SESSION['username'].'</a></strong></div><br>'.userbb($text);.'
<div align="right" style="margin-bottom: 5px; margin-right: 5px;"><font style="color: gray; font-size: 10px;">'.date("d-m-Y")'.</font></div>
</td>
</tr>
</table>
</td></tr></table>';
}
?>
$habbo=$_REQUEST['habbonaam'];
$username=$_REQUEST['username'];
$text=$_REQUEST['text'];
if($text = "") {
echo ubb('[fullalert]Je moet wel een tekst invoeren voordat je een bericht in het gastenboek kunt zetten!<br>
<input type="button" value="Sluiten" onclick="javascript:melding_close();" />[/fullalert]');
}else{
mysql_query('INSERT INTO guestbook (to_user,from_user,text,date,ip) VALUES ("'.$habbo.'","'.$username.'","'.$text.'",NOW(),"'.$_SERVER['REMOTE_ADDR'].'")"');
echo'<table>
<tr><td width="100%"><table width="100%" style="border: dashed 1px; border-color: #EFEFEF;" cellspacing="0" cellpadding="0">
<tr>
<td style="background: #EFEFEF;"><div style="float: left; margin-top: 5px;"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?user='.$_SESSION['username'].'&action=sta&frame=3&direction=2&head_direction=2&gesture=sml&size=s&img_format=png" border="0" onerror="this.src=(\'http://www.habbowereld.nl/assets/img/site/error_habboSmall.png\')" /></div>
<div style="float: left; margin-left: -25px;"><strong><a href="http://www.habbowereld.nl/leden/profiel/'.$_SESSION['username'].'">'.$_SESSION['username'].'</a></strong></div><br>'.userbb($text);.'
<div align="right" style="margin-bottom: 5px; margin-right: 5px;"><font style="color: gray; font-size: 10px;">'.date("d-m-Y")'.</font></div>
</td>
</tr>
</table>
</td></tr></table>';
}
?>
Gedeelte van profiel.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$book_sql = mysql_query("SELECT *,DATE_FORMAT(date, '%d-%m-%Y') AS date FROM guestbook WHERE to_user = '".$user['username']."' ORDER BY date");
echo ubb('<a name="guestbook"></a>[box=Gastenboek]<div style="height: 132px; overflow-y: scroll; overflow-x: hidden;"><table width="100%" border="0" cellpadding="0" cellspacing="2">');
while($book_row = mysql_fetch_array($book_sql)) {
$writer_sql = mysql_query("SELECT *,DATE_FORMAT(register, '%d-%m-%Y') AS register FROM users WHERE username='".$book_row['from_user']."'");
$writer = mysql_fetch_array($writer_sql);
?>
<tr><td width="100%"><table width="100%" style="border: dashed 1px; border-color: #EFEFEF;" cellspacing="0" cellpadding="0">
<tr>
<td style="background: #EFEFEF;"><div style="float: left; margin-top: 5px;"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?user=<? echo $writer['habbo']; ?>&action=sta&frame=3&direction=2&head_direction=2&gesture=sml&size=s&img_format=png" border="0" onerror="this.src=('http://www.habbowereld.nl/assets/img/site/error_habboSmall.png')" /></div>
<? if(htmlentities($_GET['id']) == $_SESSION['username'] || htmlentities($_GET['page']) == $_SESSION['username']) {
echo'<a target="_blank" href="http://www.habbowereld.nl/leden/guestbook/'.$book_row['id'].'/delete"><img src="http://habbowereld.nl/v4/assets/img/icon/close.gif" align="right" border="0" /></a>';
} ?>
<div style="float: left; margin-left: -25px;"><strong><a href="http://www.habbowereld.nl/leden/profiel/<? echo $writer['username']; ?>"><? echo $writer['username']; ?></a></strong></div><br><? echo userbb($book_row['text']); ?>
<div align="right" style="margin-bottom: 5px; margin-right: 5px;"><font style="color: gray; font-size: 10px;"><?php
echo $book_row['date']; ?></font></div>
</td>
</tr>
</table>
</td></tr>
<?
} ?>
</table><div id="new_message"></div></div>
<form method="post" action="/leden/profiel/<?=$user['username'];?>">
<div id="masterdiv">
<div align="right" style="padding-top: 5px;" onclick="SwitchMenu('sub1')"><input type="button" name="AB-OC" value="Reactie toevoegen" /></div>
<span class="AddBook" id="sub1" style="display: none;">
<input type="hidden" id="habbonaam" name="habbonaam" value="<?=$_GET['id'];?>" />
<input type="hidden" id="username" name="username" value="<?=$_SESSION['username'];?>" />
<textarea id="text" name="text" rows="5" cols="43"></textarea><br>
<input type='button' onclick="newBook(this.form);SwitchMenu('sub1');"; value="submit"/>
</span>
</div>
<div id="status"></div>
</form>
<? echo ubb('[/box]');
?>
$book_sql = mysql_query("SELECT *,DATE_FORMAT(date, '%d-%m-%Y') AS date FROM guestbook WHERE to_user = '".$user['username']."' ORDER BY date");
echo ubb('<a name="guestbook"></a>[box=Gastenboek]<div style="height: 132px; overflow-y: scroll; overflow-x: hidden;"><table width="100%" border="0" cellpadding="0" cellspacing="2">');
while($book_row = mysql_fetch_array($book_sql)) {
$writer_sql = mysql_query("SELECT *,DATE_FORMAT(register, '%d-%m-%Y') AS register FROM users WHERE username='".$book_row['from_user']."'");
$writer = mysql_fetch_array($writer_sql);
?>
<tr><td width="100%"><table width="100%" style="border: dashed 1px; border-color: #EFEFEF;" cellspacing="0" cellpadding="0">
<tr>
<td style="background: #EFEFEF;"><div style="float: left; margin-top: 5px;"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?user=<? echo $writer['habbo']; ?>&action=sta&frame=3&direction=2&head_direction=2&gesture=sml&size=s&img_format=png" border="0" onerror="this.src=('http://www.habbowereld.nl/assets/img/site/error_habboSmall.png')" /></div>
<? if(htmlentities($_GET['id']) == $_SESSION['username'] || htmlentities($_GET['page']) == $_SESSION['username']) {
echo'<a target="_blank" href="http://www.habbowereld.nl/leden/guestbook/'.$book_row['id'].'/delete"><img src="http://habbowereld.nl/v4/assets/img/icon/close.gif" align="right" border="0" /></a>';
} ?>
<div style="float: left; margin-left: -25px;"><strong><a href="http://www.habbowereld.nl/leden/profiel/<? echo $writer['username']; ?>"><? echo $writer['username']; ?></a></strong></div><br><? echo userbb($book_row['text']); ?>
<div align="right" style="margin-bottom: 5px; margin-right: 5px;"><font style="color: gray; font-size: 10px;"><?php
echo $book_row['date']; ?></font></div>
</td>
</tr>
</table>
</td></tr>
<?
} ?>
</table><div id="new_message"></div></div>
<form method="post" action="/leden/profiel/<?=$user['username'];?>">
<div id="masterdiv">
<div align="right" style="padding-top: 5px;" onclick="SwitchMenu('sub1')"><input type="button" name="AB-OC" value="Reactie toevoegen" /></div>
<span class="AddBook" id="sub1" style="display: none;">
<input type="hidden" id="habbonaam" name="habbonaam" value="<?=$_GET['id'];?>" />
<input type="hidden" id="username" name="username" value="<?=$_SESSION['username'];?>" />
<textarea id="text" name="text" rows="5" cols="43"></textarea><br>
<input type='button' onclick="newBook(this.form);SwitchMenu('sub1');"; value="submit"/>
</span>
</div>
<div id="status"></div>
</form>
<? echo ubb('[/box]');
?>
gedeelte van general.js
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script type="text/javascript">
//AJAXPOST GB
function newBook(myform)
{
var message="habbonaam="+myform.elements["habbonaam"].value+"&username="+myform.elements["username"].value+"&text="+myform.elements["text"].value;
var message
var url="POST_gb.php";
var request=null;
if(window.XMLHttpRequest)
{
request=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
if(request)
{
request.open("POST",url);
request.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
request.onreadystatechange = function() {
if(request.readyState==0)
document.getElementById('status').innerHTML='Uninitialized';
else if(request.readyState==1)
document.getElementById('status').innerHTML='Loading...';
else if(request.readyState==2)
document.getElementById('status').innerHTML='Loaded';
else if(request.readyState==3)
document.getElementById('status').innerHTML='Interactive';
else if(request.readyState==4)
{
document.getElementById('status').innerHTML='Completed';
document.getElementById("new_message").innerHTML =
request.responseText;
}
}
request.send(message);
}
else
document.getElementById('Txtdata').value='Nothing';
}
</script>
//AJAXPOST GB
function newBook(myform)
{
var message="habbonaam="+myform.elements["habbonaam"].value+"&username="+myform.elements["username"].value+"&text="+myform.elements["text"].value;
var message
var url="POST_gb.php";
var request=null;
if(window.XMLHttpRequest)
{
request=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
if(request)
{
request.open("POST",url);
request.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
request.onreadystatechange = function() {
if(request.readyState==0)
document.getElementById('status').innerHTML='Uninitialized';
else if(request.readyState==1)
document.getElementById('status').innerHTML='Loading...';
else if(request.readyState==2)
document.getElementById('status').innerHTML='Loaded';
else if(request.readyState==3)
document.getElementById('status').innerHTML='Interactive';
else if(request.readyState==4)
{
document.getElementById('status').innerHTML='Completed';
document.getElementById("new_message").innerHTML =
request.responseText;
}
}
request.send(message);
}
else
document.getElementById('Txtdata').value='Nothing';
}
</script>
Kan iemand helpen?
Gewijzigd op 01/01/1970 01:00:00 door Stefan
Code (php)
1
2
3
2
3
<?
mysql_query('INSERT INTO guestbook (to_user,from_user,text,date,ip) VALUES ("'.$habbo.'","'.$username.'","'.$text.'",NOW(),"'.$_SERVER['REMOTE_ADDR'].'")"');
?>
mysql_query('INSERT INTO guestbook (to_user,from_user,text,date,ip) VALUES ("'.$habbo.'","'.$username.'","'.$text.'",NOW(),"'.$_SERVER['REMOTE_ADDR'].'")"');
?>
je mag volgens mij ook de " '. .' " vervangen door $var1 , $var2 , je hoeft bij $sleutels geen "" o.i.d. te gebruiken...
EDIT Geen id of dit het probleem oplost maar ik spreek hier uit mijn niet zo ruime ervaring
Gewijzigd op 01/01/1970 01:00:00 door Leon
Ok bedankt voor je opmerking, maar dat lost me probleem niet op :P
http://dutchlegion.ljwebdesign.nl/?p=gastenboek is de site... Als je wil kan ik je die gewoon geven, dat is er een die ik zelf ook uit een boek heb overgenomen, OOS dus... Je hoeft maar te kicken ^.^
Even een vraagje: ik heb zelf ook een gastenboekje, dat script is iets minder ingewikkeld dan deze... Edit:
Zelf werk ik niet met AJAX (heb eigenlijk geen id wat het precies is maar toch) dus heb ik het allemaal in PHP... Het zijn 2 pagina's, 1 voor weergeven en 1 voor invoeren.
EDIT2
Lol je gaat je gang maar, zeg maar als je de pages wilt gaan bekijken!
Zelf werk ik niet met AJAX (heb eigenlijk geen id wat het precies is maar toch) dus heb ik het allemaal in PHP... Het zijn 2 pagina's, 1 voor weergeven en 1 voor invoeren.
EDIT2
Lol je gaat je gang maar, zeg maar als je de pages wilt gaan bekijken!
Gewijzigd op 01/01/1970 01:00:00 door Leon