gitlez

YA: Simple MySQL Update 20120714180226AA10QTY

Jul 14th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2.  
  3. include("sql.php");
  4.  
  5. // $_REQUEST, not a fan of this type of variable retrieval, could be a potential security risk
  6. $pid = $_REQUEST["pid"];
  7. $url = $_POST["url"];
  8.  
  9. // Prevent SQL Injection Errors
  10. $pid = mysql_real_escape_string($pid);
  11.  
  12. $raw = "SELECT desc FROM post WHERE post_id='{$pid}' LIMIT 1";
  13. // Switched * - desc No Need For more information returned than you need.
  14. // Added Apostrophes around $pid; ( { } not needed, but helpful
  15. // LIMIT 1 - Stops MySQL From looking for more matches.
  16.  
  17. $query = mysql_query($raw) or die("no go");
  18. $row = mysql_fetch_assoc( $query );
  19. $ndesc = mysql_real_escape_string( $row['desc'] . '<img src="' . $url . '" />' );
  20. // Cleans it up. No need to while, if there is only one result row
  21. // your $ndesc variable declaration had some quoting issues.
  22. // mysql_real_escape_string() will help with injection and escaping issues.
  23.  
  24.  
  25. $string_raw = "UPDATE post SET desc='{$ndesc}' WHERE post_id='{$pid}'";
  26. // 'desc' should be desc (no apostrophes);
  27. // $pid should be encased with apostrophes
  28. // { } not needed but helpful for reading
  29.  
  30. $input = mysql_query($string_raw) or die("error");
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment