php - phpmysql inserts blank instead of value -
i have next function:
function insert($database, $table, $data_array) { # connect mysql server , select database $mysql_connect = connect_to_database(); mysql_select_db ($database, $mysql_connect); # create column , info values sql command foreach ($data_array $key => $value) { $tmp_col[] = $key; $tmp_dat[] = "'$value'"; } $columns = join(",", $tmp_col); $data = join(",", $tmp_dat); # create , execute sql command $sql = "insert ".$table."(".$columns.")values(". $data.");"; $result = mysql_query($sql, $mysql_connect); # study sql error, if 1 occured, otherwise homecoming result if(mysql_error($mysql_connect)) { echo "mysql update error: ".mysql_error($mysql_connect); $result = ""; } else { homecoming $result; } }
the values in php following:
$content_table = "p_content"; $insert_array['title'] = $title; $insert_array['content'] = $content; $insert_array['url'] = $get_source; $insert_array['video'] = $video; $insert_array['date'] = $date; insert(database, $content_table, $insert_array);
the result of adds row id (key, autoimcrement), url, , date. title, content , video blank. if echo title right result, if var_dump title string(15)"blablablabla", 1 time again correct.
now if hand set $title = "asdf"; getting inserted correctly. same goes content , video.
table structure
id int(8) unsigned no pri null auto_increment
title varchar(1000) yes null
content longtext yes null
video varchar(3000) yes null
url varchar(300) yes null
date date yes null
try adding quotes variables. :-) reason mysql column types set varchar. , inserting info requires surround inserts quotes.
b.t.w. if new code recommend switch mysqli or pdo library.
php mysql insert
No comments:
Post a Comment