Reputation: 13
<? if($_POST['submit'])
{ $taskSelect =$_POST['taskOption'];
$sql =array();
foreach($_POST['task'] as $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 it possible to do so , As i've tried this but no value is being inserted into table when I'm using table name taken from form?
<select name="taskOption">
<option value="today">Today</option>
<option value="weekly">Weekly</option>
<option value="month">Monthly</option>
</select>
Upvotes: 0
Views: 62
Reputation: 33521
You miss some spaces:
$ab ="INSERT INTO" .$taskSelect. "(u_id,task) VALUES ('".$...
should be
$ab ="INSERT INTO " .$taskSelect. " (u_id,task) VALUES ('".$...
That being said, do not use mysql_*
anymore, read up on prepared statements and input validation. You are wide open to SQL injection right now.
Upvotes: 2
Reputation: 1462
You have to add a space after INTO and before "
$ab ="INSERT INTO " .$taskSelect. "(u_id,task) VALUES ('".$_SESSION['id']."','".implode(',', $sql)."')";
Upvotes: 1