mysql & php error . can't find solution . updating problem ....

Discussion in 'PHP' started by someone100, Oct 23, 2008.

  1. #1
    problem :
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's job is to deliver the orders to his customers on the beach in time! ' WHERE g' at line 1

    problem :
    without update i got all the data printed .
    without while the single data is updated .
    with update & while i got the error !!!!

    
    
    
    
    
    // Make a MySQL Connection
    
    
    
    
    mysql_connect("localhost", "username", "pass") or die(mysql_error());
    
    
    
    
    mysql_select_db("databasetry") or die(mysql_error());
    
    
    
    
    
    // Get all the data from the "text" table
    
    
    
    
    $alldata = mysql_query("SELECT * FROM text") or die(mysql_error());  
    
    
    
    
    
    
    
    // keeps getting the next row until there are no more to get
    
    
    
    
    
    while($row = mysql_fetch_array( $alldata ))
    {
    
    
    // tryprint
    
    	 echo $row['texttitle'];
    
                 $temparray[0] = 1;
    
        
    
    
    // update
     $catroom = mysql_query("UPDATE text SET textdesc='$temparray[0] <BR> $row[textdesc]'  WHERE textid='$row[textid]'")   or die(mysql_error()); 
    
    
    
    
    
     
     }    
    
    
     
    ?>
    
       
    
    Code (markup):
     
    someone100, Oct 23, 2008 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi, try to copy this :
    "UPDATE text SET textdesc='".$temparray[0]." <BR> ".$row[textdesc]."' WHERE textid='".$row[textid]."'"
    I guess you problem is that you're using the array as a string and not the real value
    Does it work now?
     
    lp1051, Oct 23, 2008 IP
  3. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Actually,
    "UPDATE text SET textdesc='".mysql_real_escape_string($temparray[0])." <BR> ".mysql_real_escape_string($row[textdesc])."' WHERE textid='".mysql_real_escape_string($row[textid])."'"
     
    Kyosys, Oct 23, 2008 IP
  4. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i have copied it . now i will try
     
    someone100, Oct 23, 2008 IP
  5. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    lp1051 , thanks but same error !!!!


    Kyosys , no error but no update too :(
     
    someone100, Oct 23, 2008 IP
  6. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    use Kyosys's example, but add the 'or die (mysql_error());' at the end. ;)
     
    Dirty-Rockstar, Oct 23, 2008 IP
  7. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Dirty-Rockstar , i did but the data base wasn't updated :(
    i am not just copy and glue .

    no error and no update . the data base should be updated !
    the code above by me ,update the data base, this not update the data base.
     
    someone100, Oct 23, 2008 IP
  8. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    wrap mysql_query(); to the sql
     
    Dirty-Rockstar, Oct 23, 2008 IP
  9. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9

    i don't understand that you have said !
    can you rewrite you answer ?
     
    someone100, Oct 23, 2008 IP
  10. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    
    $catroom = mysql_query("UPDATE games SET gamedesc='".mysql_real_escape_string($temparray[0])." <BR> ".mysql_real_escape_string($row[gamedesc])."' WHERE   gamedesc='".mysql_real_escape_string($row[gameid])."'")  or die(mysql_error()); 
    
    
    
    
    Code (markup):

    this my code . it isn't update data .
     
    someone100, Oct 23, 2008 IP
  11. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #11
    mysql_query("UPDATE text SET textdesc='".mysql_real_escape_string($temparray[0])." <BR> ".mysql_real_escape_string($row[textdesc])."' WHERE textid='".mysql_real_escape_string($row[textid])."'");
    PHP:
    kyosys's
     
    ads2help, Oct 23, 2008 IP
  12. someone100

    someone100 Peon

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    works !!!!!!!!!!!!!!!!!!! thanks a lot . it was my small mistake !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    wow !!!!!!!
     
    someone100, Oct 23, 2008 IP
  13. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #13
    you're welcome
     
    Kyosys, Oct 24, 2008 IP
  14. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    mysql_real_escape_string does the magic. The problem was special characters in the text.
     
    salahsoftware, Oct 24, 2008 IP