0

The following table query is not executing properly, what is the correct syntax?

$m_query = 'Insert into'.$job_id.'(`mobile`,`routeID`,`status`) values ('$mobile','$routeID','Sent')';

Edited by blueguy777: title modified

3
Contributors
5
Replies
36
Views
1 Year
Discussion Span
Last Post by pritaeas
1

Hi, you are enclosing the query into single quotes:

$a = 'apples';
$b = 'oranges';

So in order to append another variable you have to use the dot operator:

$c = 'list '. $b . ' and ' .$a;

Basically is this. You have done that when defining the table name ($job_id), so the query would turn to:

$m_query = 'Insert into '.$job_id.'(`mobile`,`routeID`,`status`) values ('.$mobile.','.$routeID.',"Sent")';

Note:

  • the space after the into keyword
  • also 'Sent' becomes "Sent"

But it will not work, unless $mobile and $routeID are integers, if those are strings, then you have to add quotes (double quotes in this case):

$m_query = 'Insert into '.$job_id.'(`mobile`,`routeID`,`status`) values ("'.$mobile.'","'.$routeID."',"Sent")';

This can be refactored with double quotes:

$m_query = "insert into {$job_id} (`mobile`, `routeID`, `status`) values ('{$mobile}', '{$routeID}', 'Sent')";

In any case, you really don't want to create a query like this, you want to use prepared statements, as explained here:

Edited by cereal

0

thanks cereal for your solution, one more similar issue, the code is below.
the rows are not inserting into to table

$values = '("'.$mobile.'","'.$routeID.'","INVALID")';

$m_query = 'Insert into `'. $job_id. '` (`mobile`,`routeID`,`status`) values ' .$values;

Edited by blueguy777: spelling correction

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.