SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question problem about function concat

    <form action="reply.php" method="post">
    <textarea name="reply" rows=7 cols=60></textarea><br>
    <input type=submit name="submit" value="ok"/>
    </form><p>
    <?php
    include("conn.php");
    $sql="update msg set msgs=concat(msgs,".$_POST[reply].") where id=$num";
    $query=mysql_query($sql);
    ?>



    i dont know how to write concat()
    something wrong with $_POST[reply]
    help me, plz.thank u!

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You need to place apostrophes around the posted reply in your SQL string.
    PHP Code:
    <?php
    $sql 
    sprintf(
        
    "UPDATE msg SET msgs = CONCAT(msgs, '%s') WHERE id = %d LIMIT 1",
        
    mysql_real_escape_string($_POST['reply']),
        
    $id
    );
    $result mysql_query($sql);
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx for your reply,

    tried it,but not work ..

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    What error do you receive?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No error , but data has no change

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Post the code you're using.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    <center><form action="reply.php" method="post">
       <textarea name="reply" rows=7 cols=60></textarea><br>
       <input type=submit name="submit" value="ok"/>
       </form><p>
    <?php
       include("conn.php");
       $sql = sprintf(
        "UPDATE msg SET msgs = CONCAT(msgs,'%s') WHERE id = %d LIMIT 1",
        mysql_real_escape_string($_POST['reply']),
        $num);
       $query=mysql_query($sql);
    ?>
    <p><a href="admin.php">[back]</a>
    </center>

  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    ..and with this...
    PHP Code:
    <?php
    if('POST' === $_SERVER['REQUEST_METHOD'])
    {
        include(
    "conn.php");
        
        
    $sql sprintf(
            
    "UPDATE msg SET msgs = CONCAT(msgs, '%s') WHERE id = %d LIMIT 1",
            
    mysql_real_escape_string($_POST['reply']),
            
    $num
        
    );
        
        
    $result mysql_query($sql);
        
        if(
    mysql_affected_rows() !== 1)
        {
            
    printf(
                
    '
                <h4>Error</h4>
                <p><strong>Message:</strong>%s</p>
                <p><strong>SQL:</strong>%s</p>
                '
    ,
                
    mysql_error(),
                
    $sql
            
    );
            exit;
        }
    }
    ?>
    <center>
        <form action="reply.php" method="post">
           <textarea name="reply" rows=7 cols=60></textarea>
           <br>
           <input type=submit name="submit" value="ok"/>
        </form>
    <p>
    ?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  9. #9
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's the result.....


    Error

    Message:

    SQL:UPDATE msg SET msgs = CONCAT(msgs, 'test') WHERE id = 0 LIMIT 1

  10. #10
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where is $num coming from?
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  11. #11
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Bah, beaten to it, so...$num ?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  12. #12
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    .... the code of admin.php

    Code PHP:
    <?php
    include "conn.php";
    ?>
    <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
    <?
      $sql="select *from msg order by id desc";
      $query=mysql_query($sql);
      while($row=mysql_fetch_array($query)){
    ?>
      <tr bgcolor="#eff3ff">
      <td><?=$row[id]?>#  Name:<?=$row[name]?> </td>
      </tr>
      <tr bgcolor="#ffffff">
      <td>Tel.<?=$row[tele]?>  Time:<?=$row[lastdate]?></td> 
      </tr>
      <tr bgColor="#ffffff">
      <td>Message.<?=$row[msgs]?> 
    <a href="del.php?num=<?=$row[id]?>">[Del.]</a>
    <a href="reply.php?num=<?=$row[id]?>">[Reply]</a> </td>
      </tr>
    <?
    }
    ?>

  13. #13
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ah, assuming this is 'reply.php', then this should do it.
    PHP Code:
    <?php
    if('POST' === $_SERVER['REQUEST_METHOD'])
    {
        include(
    "conn.php");
        
        
    $sql sprintf(
            
    "UPDATE msg SET msgs = CONCAT(msgs, '%s') WHERE id = %d LIMIT 1",
            
    mysql_real_escape_string($_POST['reply']),
            
    $_GET['id']
        );
        
        
    $result mysql_query($sql);
        
        if(
    mysql_affected_rows !== 1)
        {
            
    printf(
                
    '
                <h4>Error</h4>
                <p><strong>Message:</strong>%s</p>
                <p><strong>SQL:</strong>%s</p>
                '
    ,
                
    mysql_error(),
                
    $sql
            
    );
            exit;
        }
    }
    ?>
    <form action="reply.php?id=<? echo $_GET['id']; ?>" method="post">
       <textarea name="reply" rows=7 cols=60></textarea>
       <br>
       <input type=submit name="submit" value="ok"/>
    </form>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  14. #14
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Er....not work

    Error

    Message:

    SQL:UPDATE msg SET msgs = CONCAT(msgs, 'fdsfsdfdf') WHERE id = 0 LIMIT 1

  15. #15
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    OK. All this num -> id switching is confusing!

    PHP Code:
    <?php
    if('POST' === $_SERVER['REQUEST_METHOD'])
    {
        include(
    "conn.php");
        
        
    $sql sprintf(
            
    "UPDATE msg SET msgs = CONCAT(msgs, '%s') WHERE id = %d LIMIT 1",
            
    mysql_real_escape_string($_POST['reply']),
            
    $_POST['id']
        );
        
        
    $result mysql_query($sql);
        
        if(
    mysql_affected_rows() !== 1)
        {
            
    printf(
                
    '
                <h4>Error</h4>
                <p><strong>Message:</strong>%s</p>
                <p><strong>SQL:</strong>%s</p>
                '
    ,
                
    mysql_error(),
                
    $sql
            
    );
            exit;
        }
    }
    ?>
    <form action="reply.php" method="post">
       <textarea name="reply" rows=7 cols=60>
       </textarea>
       <input type="hidden" name="id" value="<?php echo $_GET['num']; ?>" />
       <br>
       <input type=submit name="submit" value="ok"/>
    </form>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  16. #16
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aha, really Thannnnnks!!!

    but another problem, it cannot show other languages , except English characters.

    why?

  17. #17
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Cor blimey, you want the world!

    You need to set the right encoding on both the database, table collation, connection and some of php's internals.

    UTF-8 is a good start.

    No small task.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  18. #18
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh,sorry, i forgot to save as utf-8

    aha,thank u again ,

    hava a nice day..


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
  •