PDA

View Full Version : loading an external php page



woodplease
09-22-2010, 05:34 PM
l have a script i got of this site that loads another page inside a div tag. This works. the page that is loading contains code than when run, reloads that php page to insert data into a database. The problem is that it just reloads the entire page and doesnt enter the data into the database.

The main page

<div id='fcontrol'>

<table border='1' class ='tstyle'>
<tr height ='700'><td valign='top' class='ssbg' width='120'><div id='menu'>

<a href='javascript:ajaxpage("new_section.php", "contentarea");'>Add new section</a><br/><br/>
<a href='javascript:ajaxpage("new_sub_section.php", "contentarea");'>Add new section to forum</a><br/><br/><a href='index.php'>Back to forum</a><br/><br/></div></td><td class='tcontrol' width='700' valign='top'>
<center><div id='contentarea'>Control Panel</div></center></td></tr>
</table></div>

</div>


the page inside the div

if (isset($_POST['new_section'])) {
if (!$section_title ) {
die('You did not complete all of the required fields<br/><a href="./new_section.php">Back</a>');
}
$query = "INSERT INTO section_main (section_title) VALUES ('$section_title')";
$add_section = mysql_query($query) or die ('could not add new section');
?>
<h1>section added</h1>
<?php
}
else
{


?>
<form name="add_section" method="post" action="<?php echo $_SERVER['../PHP_SELF']; ?>">
<table>
<tr>
<td>Section Name</td>
<td><input type="text" name="section_title" maxlength="200" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="new_section" value="Add Section"/></td>
</tr>
</table>
</form>

<?php
}
?>

the javascript

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}


I've included all the code related to the problem. i know its a lot, but i wanted to give as much info as possible