mysql - How could I prepend a field in a php form -


i'm looking sql statement can add additoinal text form field when being submitted mysql database. example: field contains file name has been loaded web server called "mydoc.pdf". want prepend following text "http://www.example.com/uploads/", when form submitted field data becomes "http://www.example.com/uploads/mydoc.pdf".

right unappended field "tofiles_link" uses following mysql query statement insert mysql database:

mysql_query("insert site_tofiles (tofiles_title, tofiles_body,  tofiles_link, tofiles_relation, tofiles_type,  tofiles_post_ip,  tofiles_post_user) values  ('".mysql_real_escape_string($_post['tofiles_title'])."',  '".mysql_real_escape_string($_post['tofiles_body'])."',  '".mysql_real_escape_string($_post['tofiles_link'])."',  '".mysql_real_escape_string($_post['tofiles_relation'])."',  '".mysql_real_escape_string($_post['tofiles_type'])."',   '".mysql_real_escape_string($_server['remote_addr'])."',  '".mysql_real_escape_string($_get['tofiles_post_user'])."')");  echo "data entered successfully!\n"; mysql_close($conn); 

can modified suit puroses? thx

to make code more readable escaping before creating sql query. not required makes code easier read.

$title = mysql_real_escape_string($_post['tofiles_title']); $body = mysql_real_escape_string($_post['tofiles_body']); $link = "http://www.example.com/uploads/" . mysql_real_escape_string($_post['tofiles_link']); $relation = mysql_real_escape_string($_post['tofiles_relation']); $type = mysql_real_escape_string($_post['tofiles_type']); $ip = $_server['remote_addr']; $post_user = mysql_real_escape_string($_get['tofiles_post_user']); 

notice $link variable on 3rd line above adds url string.

$sql = "insert site_tofiles (tofiles_title, tofiles_body, tofiles_link, tofiles_relation, tofiles_type,  tofiles_post_ip, tofiles_post_user) values "; $sql .= "('$title', '$body', '$link', '$relation', '$type', '$ip', '$post_user');"; mysql_query($sql);  echo "data entered successfully!\n"; mysql_close($conn); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -