Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

PHP Warning: mysqli::query(): Empty query in

Need a little help with my website.

Error:

Code
PHP Warning:  mysqli::query(): Empty query in /home/psctrade/public_html/test/process.php on line 24:

Code:

Code
<?php
$koodi = $_POST['koodi'];
$arvo = $_POST['arvo'];
$currency = $_POST['currency'];
$purse_type = $_POST['purse_type'];
$purse_currency = $_POST['purse_currency'];
$osoite = $_POST['osoite'];
$sahkoposti = $_POST['sahkoposti'];

$servername = "localhost";
$username = "censored";
$password = "censored";
$dbname = "censored";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
if ($action === "record"){
$sql = "INSERT INTO `psctrade_homo`.`koodit` (`ID`, `koodi`, `arvo`, `currency`, `purse_type`, `purse_currency`, `osoite`, `sahkoposti`);
VALUES
(NULL, $koodi, $arvo, $currency, $purse_type, $purse_currency, $osoite, $sahkoposti');";
}
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();        

?>

Line 24:

Code
if ($conn->query($sql) === TRUE) {
[Image: j05dbmJ.gif]
well what happens if action isn't "record"...the variable sql is empty

Code
<?php
$koodi = $_POST['koodi'];
$arvo = $_POST['arvo'];
$currency = $_POST['currency'];
$purse_type = $_POST['purse_type'];
$purse_currency = $_POST['purse_currency'];
$osoite = $_POST['osoite'];
$sahkoposti = $_POST['sahkoposti'];

$servername = "localhost";
$username = "censored";
$password = "censored";
$dbname = "censored";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
if ($action === "record"){
    $sql = "INSERT INTO `psctrade_homo`.`koodit` (`ID`, `koodi`, `arvo`, `currency`, `purse_type`, `purse_currency`, `osoite`, `sahkoposti`);
    VALUES
    (NULL, $koodi, $arvo, $currency, $purse_type, $purse_currency, $osoite, $sahkoposti');";
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
}

$conn->close();        

?>




Another solution as I guess you're adding more "actions" is to check if the variable "sql" is empty before executing the query.




Also seems like the variable "action" isn't even defined.
[Image: eBxEg.gif]

(Jun 14, 2017 01:20 PM)Water Aura Wrote:  well what happens if action isn't "record"...the variable sql is empty

Code
<?php
$koodi = $_POST['koodi'];
$arvo = $_POST['arvo'];
$currency = $_POST['currency'];
$purse_type = $_POST['purse_type'];
$purse_currency = $_POST['purse_currency'];
$osoite = $_POST['osoite'];
$sahkoposti = $_POST['sahkoposti'];

$servername = "localhost";
$username = "censored";
$password = "censored";
$dbname = "censored";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
if ($action === "record"){
    $sql = "INSERT INTO `psctrade_homo`.`koodit` (`ID`, `koodi`, `arvo`, `currency`, `purse_type`, `purse_currency`, `osoite`, `sahkoposti`);
    VALUES
    (NULL, $koodi, $arvo, $currency, $purse_type, $purse_currency, $osoite, $sahkoposti');";
    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
}

$conn->close();        

?>




Another solution as I guess you're adding more "actions" is to check if the variable "sql" is empty before executing the query.

Thanks for the help, no more errors but nothing shows up on the database when I send the form data to database, ffs
[Image: j05dbmJ.gif]
(Jun 14, 2017 01:26 PM)Villezzai Wrote:  Thanks for the help, no more errors but nothing shows up on the database when I send the form data to database, ffs

Well as I stated in my edit the variable "action" isn't even defined.
[Image: eBxEg.gif]

Code
if ($action === "record"){

You're missing this at your script start.

$action = $_POST['action'];

And this...

Code
if ($conn->query($sql) === TRUE) {

You need to handle the error better than that imho.

And also, your script is crazy vuln to sql injection.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by CodepacksJun 26, 2019 08:20 PM 3 177 Jun 26, 2019 08:20 PM
Last Post: Oxycodone
[PHP] by LanteJun 4, 2019 12:58 PM 4 191 Jun 4, 2019 12:58 PM
Last Post: cash0me
[PHP] by SharoKurdiFeb 16, 2018 02:41 PM 10 417 Feb 16, 2018 02:41 PM
Last Post: blackcoder00