how do i write this properly?
$sql_totalbooknumber = "SELECT SUM(items_counter) FROM probid_categories WHERE items_counter>0 AND `category_id` <>355";
i get this
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT SUM(items_counter) FROM probid_categories WHERE items_counter>0 AND `cate' at line 1
if (!mysql_query($sql_totalbooknumber))
{
die('Error: ' . mysql_error());
};
Try
$sql_totalbooknumber = "SELECT SUM(items_counter) FROM probid_categories WHERE items_counter>0 AND category_id != 355";
Related
I have a problem with my UPDATE code. It gives me this error:
Update Failed!! You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id ='2'' at line 4
I'm searching online and I cant find any solution to my problem.
THIS IS MY UPDATE CODE:
<?php
include('db.php');
$id = $_GET['id'];
if (isset($_POST['id'])){
$sql = "UPDATE tbl_student SET stud_id ='".$_POST['stud_id']."',
fullname ='".$_POST['fullname']."',
course ='".$_POST['course']."',
WHERE id ='".$_POST['id']."'";
$result = $conn->query($sql) or die ("Update Failed!!" . $conn->error);
header("location: index.php");
}
else {
echo "ERROR" . $conn->error;
header ("location: update.php");
}
?>
You have added , at last after course . Remove it. Change your query to:
$sql = "UPDATE tbl_student SET stud_id ='".$_POST['stud_id']."',
fullname ='".$_POST['fullname']."',
course ='".$_POST['course']."'
WHERE id ='".$_POST['id']."'";
How can i fix error in my sql syntax? The error is like this:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id= 20' at line 11
This is the code :
<?php
ob_start();
require_once('dbConfig.php');
if(isset($_GET['id'])){
$id = $_GET['id'];
$sql = "select * from usersreg where id=".$id;
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_assoc($result);
}else{
$errorMsg = 'Could not select a record';
}
}
Line 11 is at : $result = mysqli_query($conn, $sql);
I get an error with my PHP code when updating the table patient. I cannot find the problem.
Here is my error:
Verification Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
<?php
$edit = mysql_query("UPDATE `patient` SET `date`='$date', `fname`='$fname', `lname`='$lname', `birthday`='$dob', `address`='$address', `work`='$work', `civil`='$civil', `gender`='$sex', `btype`='$bloodtype', `height`='$hgt', `weight`='$wgt', `fallergy`='$fallergy', `mallergy`='$mallergy' WHERE `patientid`='$vara'");
$result = mysql_query($edit) or die("Verification Error: " . mysql_error());
You are calling mysql_query twice; the second time you pass the result, of the first call, into it as an argument. That is not how mysql_query works. The SQL should just be a string:
$edit = "UPDATE `patient` SET `date`='$date', `fname` ...";
$result = mysql_query($edit) or die("Verification Error: " . mysql_error());
We cannot see the rest of your code, so we do not know if there are more problems, but this should fix the problem in your question.
My code is throwing this error:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-contact-info' at line 1
my code:
<?php
//connect
$connection = mysqli_connect("myh","myu","myp","mydb") or die("Error " . mysqli_error($connection));
//consultation:
$query = "SELECT * FROM web-contact-info";
//execute the query.
$result = mysqli_query($connection, $query);
if (!$result) {
printf("Error: %s\n", mysqli_error($connection));
exit();
}
//display information:
while($row = mysqli_fetch_array($result)) {
echo $row["live_name"] . "<br>";
}
?>
I've tried to put quotes around web-contact-info and get a slightly different error:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''web-contact-info'' at line 1
What am I writing wrong?
You can try this:
SELECT * FROM `web-contact-info`
As mysql_* is deprecated consider switching to mysqli or PDO.
Try and use the name of the table within simple quotes like this
$query = "SELECT * FROM `web-contact-info`";
I'm getting this error:
Invalid query: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'INET_ATON('188.92.x.x')' at line 1
While trying to insert IP Address in database. The column type is:
'LastIP int(10) unsigned NOT NULL,'.
The function to execute the query is:
function onNewUser($ip, $hostname, $con)
{
$query = "INSERT INTO tableMachine (LastIP, LastHostName) VALUES ".
"INET_ATON('".mysql_real_escape_string($ip, $con)."'), ".
"'".mysql_real_escape_string($hostname, $con)."'";
$result= mysql_query($query, $con);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
}
I call this function with the parameters:
$ip = $_SERVER['REMOTE_ADDR'];
$hostname = #gethostbyaddr($ip);
onNewUser($ip, $hostname, $con);
What's wrong with it guys?
your values list should be encapsulated inside of parenthesis if I am not mistaken
You should try this :
$query = "INSERT INTO tableMachine (LastIP, LastHostName) VALUES (".
"INET_ATON('".mysql_real_escape_string($ip, $con)."'), ".
"'".mysql_real_escape_string($hostname, $con)."')";
I just add parenthesis for VALUES(...)
Also, as #Shamil said, the functions mysql_* are depricated. You should use mysqli_*This link should help you with the mysqli_* functions.