Ich möchte ein Formular, das einen Text per AJAX an eine php-Datei übergibt. Die php-Datei schreibt dann alles in eine Datenbank.
Meine Ajax-Funktion:
Mein html-Formular:
Meine php-Datei (sendmsg.php):
Aber es passiert irgendwie nichts wenn ich auf den Button klicke und ich verstehe nicht warum.
Lg ueler
Meine Ajax-Funktion:
Code:
function ajaxSend(){
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;
}
}
}
var param="msg=hoi";
ajaxRequest.onreadystatechange=handleServerResponse;
ajaxRequest.open("POST", "sendmsg.php", true);
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", param.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(param);
}
Mein html-Formular:
HTML:
<form method="post" action="javascript:ajaxSend()">
<textarea id="msgback" name="tfmsgback" rows="3" style="width:500px"></textarea>
<br>
<input type="submit" name="sendback" value="Nachricht senden">
</form>
Meine php-Datei (sendmsg.php):
PHP:
<? $con = mysql_connect("localhost", "******", "******");
$db = mysql_select_db("*******", $con);
session_start();
$actconid=$_SESSION['conidsession'];
$msgback=mysql_real_escape_string($_POST['msg']);
$resultid = mysql_query("SELECT * FROM `conversations` WHERE `conid` = '$actconid'"); //anfrage an
$array = mysql_fetch_array($resultid);
$lastid=$array['lastid'];
$nextid=$lastid+1;
$sqlupcon="UPDATE `conversations` SET `lastid` = '".$nextid."' , `log1` = '1' , `log2` = '1' WHERE `conid` = '$actconid' LIMIT 1 ;";
mysql_query($sqlupcon);
mysql_query("INSERT INTO messages (conid, id, sender, nachricht) VALUES ('$actconid', '$nextid', '$activeuser', '$msgback')") or die( mysql_error());
?>
Aber es passiert irgendwie nichts wenn ich auf den Button klicke und ich verstehe nicht warum.
Lg ueler