Ciao a tutti,
ho il seguente problema: il file che segue, viene importato dentro una pagina .php tramite l'istruzione include("pagina.php");
pagina.php è la seguente:
Codice PHP:
<script language="javascript">
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
//document.myForm.time.value = ajaxRequest.responseText;
}
}
ajaxRequest.open("POST", "insertMarker.php", true);
ajaxRequest.send(null);
}
</script>
<div id="infoWindow" align="center" >
<form name="newMarker" method="post">
<fieldset>
<legend>Marker details</legend>
<div class="input">
<label for="user">Title [b]*[/b]</label>
<input id="title">
</div>
<div class="input">
<label for="user">Comment [b]*[/b]</label>
<input id="comment" type="text">
</div>
<input type="hidden" name="author" value="Prova Trez"/>
<input type="hidden" name="latitude" value="<?php echo $lat; ?>"/>
<input type="hidden" name="longitude" value="<?php echo $lng; ?>"/>
<input type="hidden" name="projectID" value="020"/>
<input type='button' onclick='ajaxFunction()' value='Query MySQL' />
</fieldset>
</form>
</div>
insertMarker.php è la pagina che effettuerà la richiesta, ovvero inserirà i dati del form.
Ecco il suo codice:
Codice PHP:
<?php
$author = $_POST['author'];
$lat = $_POST['latitude'];
$lng = $_POST['longitude'];
$title = $_POST['title'];
$comment = $_POST['comment'];
$projectID = $_POST['projectID'];
$coordinates = $lat.' '.$lng;
include("connection.php");
$stream = mysql_connect($host,$user,$password)or die("Connessione non riuscita: " . mysql_error());
mysql_select_db($db, $stream) or die("Errore nella selezione del database");
$sql = "INSERT INTO markers (author, coordinates, title, comment, project_id) VALUES ('".$author."','".$coordinates."','".$title."','".$comment."', '".$projectID."')";
//$sql = "INSERT INTO markers (author, coordinates, title, comment, project_id) VALUES ('prova Treddy',')";
mysql_query($sql) or die('Error, insert query failed');
mysql_close($stream);
echo "Query inserita con successo";
?>
Non riesco a capire perché non funziona.
Che sia perché pagina.php viene importata dentro un'altra pagina php, quindi ci sono problemi tra i caratteri <? php ?> e <script....></script> ??
Aiuto, sto impazzendo T_T!
Grazie!