Uniting two sql syntax in php

Hi,

Have you an idea to bring these two PHP expression. The ‘code’ Here is a JavaScript variable. I would like to unite these SQL query.
<?php $sql = "SELECT TheDateTime, ResponseTime,IncomingBitsSecond,OutgoingBitsSecond FROM dbvsat.tbrute WHERESiteID= ''" ?> code <?php "'' And TheDateTimebetween '$azodebut 00:00:00' AND '$azofin 23:59:59' ORDER BYTheDateTime "; ?>

Best regards,

I see only one query in your example code. What am I not seeing?

<?php
$sql = "
SELECT TheDateTime, ResponseTime, IncomingBitsSecond, OutgoingBitsSecond
FROM dbvsat.tbrute
WHERE SiteID = ''" 
?>
 code 
<?php
 "'' And TheDateTime between '$azodebut 00:00:00' AND '$azofin 23:59:59' 
ORDER BY TheDateTime"; 
?>

PhpStorm does not accept the second.

I don’t know what “code” looks like, but even so the query looks off

SiteID = '' [code] '' And

Is SiteID supposed to be empty as is whatever “field =” [code] is putting there?

I need the variable ‘code’ because he have a data

And i need SiteID = code in my sql request

Then it looks like the extra quotation marks are a problem. Try changing iy to

WHERE SiteID = " 
?>
 code 
<?php
 " And

The same problem

Can you call php code directly from javascript like that? I thought you’d need to connect to a server using something like AJAX to be able to interact between client-side javascript (presuming that’s what this is) and server-side PHP.

As long as `code’ is a field name it would be more like

WHERE SiteID = '" 
?>
 code 
<?php
 "' And

* single quotation mark, not two

But droopsnoot is correct. Your approach is off. It is easy to use PHP to put values into JavaScript code

<script> 
var something = "<?php echo $something; ?>";

but not so easy to put JavaScript values into PHP code.

The usual approach is to either pass the variable value using $_POST or $_GET eg.

WHERE SiteID = '" . $code . "' And

where

$code = safe($_POST['code']);

Or better still, using bound parameters

WHERE SiteID = ? And
$stmt->bind_param("s", $code);

http://php.net/manual/en/mysqli-stmt.bind-param.php
http://php.net/manual/en/pdostatement.bindparam.php

If you don’t want the browser to go to a “new” page, but update the current one, then AJAX is the way to do it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.