eggo9432
New Member
- Messages
- 151
- Reaction score
- 1
- Points
- 0
I am using ajax to insert a form using GET. When that form is submitted, it goes into a mysql database. I know that the error is occurring when this data is being submitted into mysql and not when I am retrieving it. My problem is that all line breaks, and when you press the "enter" key are not being submitted into the database. All of the text just goes in as a straight line without breaks or anything of the sort. I would appreciate any help as to figuring out how to get these breaks to actually be inserted into mysql because this is a big problem for my site. Any help is very much appreciated.
Here is the code for the ajax that I am using
$echovar400=
"
<script language='javascript' type='text/javascript'>
function ajaxFunction(){
var ajaxRequest;
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;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('pagecomments');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var age = document.getElementById('age').value;
var wpm = document.getElementById('wpm').value;
var queryString = '?age=' + age + '&wpm=' + wpm;
ajaxRequest.open('GET', 'ajaxprofilechat.php' + queryString, true);
ajaxRequest.send(null);
}
</script>
<form name='myForm' method='GET' >
<textarea rows='4' name='message' class='comment' maxlength='250' id='age' wrap='hard'> </textarea><br><h40>
<input type='hidden' id='wpm' value='$profilename'/>
<input type='button' onclick='ajaxFunction()' value='Comment' />
</form>
";
}
?>
I realize that is not the start of the php, but the rest is unimportant.
here is the code for ajaxprofilechat
$age = strip_tags($_GET['age']);
$wpm = $_GET['wpm'];
// Escape User Input to help prevent SQL Injection
$wpm = mysql_real_escape_string($wpm);
$chatname6 = ($_SESSION['username']);
$message6 = $_GET['site_message'];
$month6 = date("F");
$dayofmonth6 = date("d");
$year6 = date("Y");
$date10 = "$month6 $dayofmonth6 $year6";
$hours6 = date("g");
$min6 = date("i");
$sec6 = date("s");
$amorpm6 = date("A");
$time6 = "$hours6:$min6 $amorpm6";
if (strlen($age)>4)
{
mysql_connect("","","") or die($error);
mysql_select_db("") or die($error);
mysql_query("INSERT INTO guestbook VALUES ('','$wpm','$chatname6','$age','$date10','$time6')");
echo " <h80><b>Comment Posted</b></h80<p><p>";
}
else
{
echo " <h80><b>Your comment must be greater than four characters</b></h80><p>";
}
?>
Any help would be great. Thanks!
if you need to see my site to look at the error, here is a link to my profile page http://www.pearlsquirrel.com/profile.php?u=eggo
I know for a fact that the error is occurring when the data is being put into mysql. I have literally spent like 3 hours a day for the past week trying to fix this problem. I really need help. Thanks.
Here is the code for the ajax that I am using
$echovar400=
"
<script language='javascript' type='text/javascript'>
function ajaxFunction(){
var ajaxRequest;
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;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('pagecomments');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var age = document.getElementById('age').value;
var wpm = document.getElementById('wpm').value;
var queryString = '?age=' + age + '&wpm=' + wpm;
ajaxRequest.open('GET', 'ajaxprofilechat.php' + queryString, true);
ajaxRequest.send(null);
}
</script>
<form name='myForm' method='GET' >
<textarea rows='4' name='message' class='comment' maxlength='250' id='age' wrap='hard'> </textarea><br><h40>
<input type='hidden' id='wpm' value='$profilename'/>
<input type='button' onclick='ajaxFunction()' value='Comment' />
</form>
";
}
?>
I realize that is not the start of the php, but the rest is unimportant.
here is the code for ajaxprofilechat
$age = strip_tags($_GET['age']);
$wpm = $_GET['wpm'];
// Escape User Input to help prevent SQL Injection
$wpm = mysql_real_escape_string($wpm);
$chatname6 = ($_SESSION['username']);
$message6 = $_GET['site_message'];
$month6 = date("F");
$dayofmonth6 = date("d");
$year6 = date("Y");
$date10 = "$month6 $dayofmonth6 $year6";
$hours6 = date("g");
$min6 = date("i");
$sec6 = date("s");
$amorpm6 = date("A");
$time6 = "$hours6:$min6 $amorpm6";
if (strlen($age)>4)
{
mysql_connect("","","") or die($error);
mysql_select_db("") or die($error);
mysql_query("INSERT INTO guestbook VALUES ('','$wpm','$chatname6','$age','$date10','$time6')");
echo " <h80><b>Comment Posted</b></h80<p><p>";
}
else
{
echo " <h80><b>Your comment must be greater than four characters</b></h80><p>";
}
?>
Any help would be great. Thanks!
if you need to see my site to look at the error, here is a link to my profile page http://www.pearlsquirrel.com/profile.php?u=eggo
I know for a fact that the error is occurring when the data is being put into mysql. I have literally spent like 3 hours a day for the past week trying to fix this problem. I really need help. Thanks.
Last edited: