Results 1 to 4 of 4

Thread: Ajax don't send ENTER's to PHP script

  1. #1
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default Ajax don't send ENTER's to PHP script

    Hi,
    I have AJAX form, which sends text to message.php page ans there text is inserted to the mysql.

    Here is my message.php
    PHP Code:
    <?php
    if (isset($_GET['action'])) {
    $nikas $_GET['nick'];
    $zinute $_GET['zinute'];
    $failas $_GET['failas'];
    $time date("H:i:s");

    include 
    $_SERVER['DOCUMENT_ROOT'] . '/content/processes/db_conn.php'//db 

    $nikas mysql_real_escape_string($nikas);
    $zinute mysql_real_escape_string($zinute);
    $failas mysql_real_escape_string($failas);
    $nikas mysql_real_escape_string($nikas);

    $zinute str_replace('\r\n','<br \>',$zinute);

    if(
    $zinute == '') {
        
    $error .= "Prašome įvesti tekstą.";
    }

    if(isset(
    $error)) {
            echo 
    "$error";
        } else {
            
    mysql_query("INSERT INTO `pamoka_zinutes` (Nick, Time, Zinute, failas) 
            VALUES('
    $nikas', '$time', '$zinute', '$failas')") or die(mysql_error());
        }}

    if (isset(
    $_GET['truncate'])) {
    include 
    $_SERVER['DOCUMENT_ROOT'] . '/content/processes/db_conn.php'//db 
    $nikas $_GET['truncate'];
    $nikas mysql_real_escape_string($nikas);
    if (
    $nikas == 'admin') {
    mysql_query("TRUNCATE TABLE `pamoka_zinutes`");
    echo 
    "Žinutės ištrintos";} else {echo "Tik mokytojas gali trinti žinutes";}
    }
    ?>
    This part should detect ENTER pushing but it doesn't
    PHP Code:
    $zinute str_replace('\r\n','<br \>',$zinute); 
    What is wrong?

    Thanks for your time.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    \n and \r are read literally as the text reads not as "new line" and "return", try using double quotes ".

    You may also need to separate them.

    Code:
    $zinute = str_replace("\r", '<br \>', $zinute);  
    $zinute = str_replace("\n", '<br \>', $zinute);
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    nl2br() will do that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    I am using
    PHP Code:
    httpObject3.open("GET", "post.php?action="
                            +document.getElementById('send').value+"&zinute="
                            +document.getElementById('zinute').value+"&failas="
                            +document.getElementById('failas').value+"&nick=<?php echo "$nick";?>", true);
    in my AJAX script which sends the information to post.php (message.php) page...
    Maybe some java will do <br /> effect? I mean doing like this
    PHP Code:
    $zinute str_replace("\n"'<br \>'$zinute); 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •