PDA

View Full Version : Dynamic Ajax Content script and POST method



sneeze
04-22-2010, 01:12 PM
1) Script Title:
Dynamic Ajax Content
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm
3) Describe problem:

I'm using this script on my index page to load a guestbook script i'm writing myself. It loads the guestbook very well but when i try to submit the form
it does not receive the post variables.

how do i get this to work?
it just keeps showing me the form even after i submitted it
instead of adding the form values to the database
my php script doesnt even see that the submit button has been pressed.

index.php:

<?php include('config.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<?php include('ajaxpage.js'); ?>
</head>

<body><div align="center">
<table width="923" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="banner">&nbsp;</td>
</tr>
<tr>
<td><img src="images/nav_unborn.jpg" width="923" height="104" border="0px" usemap="#Map" /></td>
</tr>
<tr>
<td><table width="923" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="body_top">&nbsp;</td>
</tr>
<tr>
<td class="body_filler">
<?php
if(!isset($_COOKIE['loginkey'])){
if(!isset($_POST['submit'])){
echo'
<div align="center">
<form method="post" action="">
Loginkey:<br /><input type="password" name="loginkey" class="logininput" /><br />
Naam:<br /><input type="text" name="naam" class="logininput" /><br /><br />

<input type="submit" name="submit" value="verzenden" />
</form>
</div>
';
}else{
if($loginerror!=""){echo $loginerror;}
}
}else{
?>
<div id="content"><?php include('home.php'); ?></div>
<?php
}
?>
</td>
</tr>
<tr>
<td class="body_bottom">&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="footer"><blockquote><a href="logout.php">logout</a></blockquote></td>
</tr>
</table>



<map name="Map" id="Map">
<area shape="rect" coords="44,30,131,72" href="javascript:ajaxpage('home.php','content');" />
<area shape="rect" coords="145,30,229,72" href="javascript:ajaxpage('dagboek.php','content');" />
<area shape="rect" coords="248,30,353,72" href="javascript:ajaxpage('geboortelijstje.php','content');" />
<area shape="rect" coords="363,30,449,72" href="javascript:ajaxpage('gastenboek.php','content');" />
<area shape="rect" coords="464,30,556,72" href="javascript:ajaxpage('fotoboek.php','content');" />
<area shape="rect" coords="571,30,665,72" href="javascript:ajaxpage('stamboom.php','content');" />
<area shape="rect" coords="682,30,763,72" href="javascript:ajaxpage('bezoekons.php','content');" />
<area shape="rect" coords="778,29,882,71" href="javascript:ajaxpage('raadsel.php','content');" />
</map>
</div>
</body>
</html>

guestbook.php: notice the script isn't finished yet, i'd like to get the post to work before i continue my work on this script.

<?php
$dbname = "*****"; // The name of the database
$dbuser = "*****"; // MySQL username
$dbpwd = "*****"; // MySQL Password
$host = "localhost"; // most likely you wont need to change this

$cxn = mysql_connect($host,$dbuser,$dbpwd);
if (!$cxn) {
print "ERROR: " . mysql_error() . "\n";
}
mysql_select_db("$dbname") or die(mysql_error());
//--------------------------------------------------------------------------------------------------------------------------------------
$sql="SELECT * FROM gastenboek";
$qry=mysql_query($sql);
echo'<table width="95%" cellpadding="0" cellspacing="0" border="0">';
while($r=mysql_fetch_array($qry)){
echo'
<tr>
<td></td>
</tr>
';
}
echo'</table>';

if(isset($_POST['gb_submit'])){
$naam=$_COOKIE['naam'];
$datum=date("d-m-Y");
$bericht=mysql_real_escape_string(nl2br($_POST['bericht']));
echo'test';
}else{
echo'
<form method="post" action="javascript:ajaxpage(\'gastenboek.php\',\'content\');">
naam: <input type="text" name="naam" value="'.$_COOKIE['naam'].'" /><br />
bericht: <textarea name="bericht" rows="10" cols="90"></textarea><br />
<input type="submit" name="gb_submit" value="plaats bericht" />
</form>
';
}
?>

So i hope there's a way to get this to work... or is this just not possible???