php - How to insert data into table taking table name value from form? -


<? if($_post['submit']) {   $taskselect =$_post['taskoption'];      $sql =array();     foreach($_post['task'] $key => $value){ $sql[] =mysql_real_escape_string($value);     }     $ab ="insert into" .$taskselect. "(u_id,task) values ('".$_session['id']."','".implode(',', $sql)."')"; } $asc =mysql_query($ab);  ?> 

html

is possible , i've tried no value being inserted table when i'm using table name taken form?

<select name="taskoption">  <option value="today">today</option>   <option value="weekly">weekly</option>   <option value="month">monthly</option> </select>   

you miss spaces:

$ab ="insert into" .$taskselect. "(u_id,task) values ('".$... 

should

$ab ="insert " .$taskselect. " (u_id,task) values ('".$... 

that being said, not use mysql_* anymore, read on prepared statements , input validation. wide open sql injection right now.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -