PHP MySQL Trouble With the Syntax - php

Need your advice about my PHP MySQL syntax. I work hard with that, but still facing problem with the query and the error is:
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 '$bagianWhere = ""' at line 1: $bagianWhere = ""
You can see my demo here

If "bagianWhere" is empty, the SQL query becomes invalid with an orphan "WHERE" at the end. You can do
$bagianWhere = "1 = 1";
at the top to counter for that.
Also get rid of "$bagianWhere .= " and make it "$bagianWhere = "
Also the error you are mentioning here is from SQL Fiddle, as you have put in PHP code in there. Can you run the PHP on your web server and show us the error you get.

Related

How to convert into Title Case in mysql query builder in laravel

I just want to ask how to convert the data I'm getting from database in Title case, its giving me an error:
Syntax error or access violation: 1064 You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use
I'm just using UCASE and LEFT, here's my code,
DB::raw('GROUP_CONCAT(DISTINCT " " ,
CONCAT(UCASE(LEFT(ru.firstname, " ", ru.lastname, 1)))) AS relates_to')
The output I want for example is "user name" into "User Name", oh and I'm using the latest MySQL Workbench just to inform you
Hope you can help me and notice me, thank you so much in advance.
The LEFT function only takes two parameters, so this alone would cause your current code to fail. You may try reworking it as follows:
DB::raw("GROUP_CONCAT(DISTINCT ' ' , LEFT(UCASE(CONCAT(ru.firstname, ' ', ru.lastname)), 1)) AS relates_to")
I don't know what your logic is exactly trying to achieve, but the above should at least run without error.

How can I do a Update with slash on MySQL?

Hello I try do a Update like this
$sql = "UPDATE info SET YES/NO = '$_POST[value]' WHERE ID = '$_POST[id]'";
I am getting this error:
Error updating record: 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 '/NO = 'YES' WHERE ID = '5'
I think this can be error from use SLASH on my database, If it is the problem how can i solve it?, thanks and i cant find any on google working for it.
Usualy, anything different than alphanumeric and underscore is not recommended.
Indeed, it is not a good practice to name a colomn like you did.
I will recommend you to rename the colomn yes_no otherwise, you will get the same error again, again and again.

unable to rectify error in database updation using php

I am trying to update my database with php and for that I have written the following query :
$query = " UPDATE users SET username = '$username' , password = '$password' WHERE id = $id ";
and the error is shown as :
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 '' at line 1
can you please help..
“syntax to use near ‘something’” shows the first few characters after the last part of the query that MySQL could parse. When ‘something’ is a zero-length string like in this case, it means the query ended before it was complete. That points to $id being an empty string.
You didn’t ask for comments on whether your query has other severe problems that will certainly lead to cybercreeps pwning your web site, so I won’t offer any such comments. :-)

Syntax Error with MYSQL

I am trying to send this function in php but it keeps coming back with this 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 ''tolu)' at line 2
function getDuplicate($case, $select,$from,$where,$equals,$and="",$equals2=""){
global $database_conndb;
global $conndb;
switch($case){
case 1:
$sql= "SELECT {$select} FROM {$from} WHERE {$where}='{$equals}'";
break;
case 2:
$sql= "SELECT {$select} FROM {$from} WHERE {$where}='{$equals}' AND {$and} != '{$equals2}'";
break;
}
looks like you did not escape the parameters correctly. look at this function: http://php.net/manual/en/function.mysql-real-escape-string.php
If you are sure that there is an error in SQL statement then echo the SQL then copy it and execute that query manually into database. U will got the actual error occurence point.
Hope this why u will fix your bug

MYSQL Syntax - Insert statement

Struggling with a simple insert command, i'm getting the 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 'All In:
The Poker Movie, tells the story of poker focusing on why one of our nat'
at line 2"
Basically passing film information into a table, here is the code -
$query1 = "INSERT INTO Films_Info (Films_ID,FilmName, FilmRelease, Synopsis,Poster,CritScore,AudScore,Director,Studio,IMDB,date_added_db)
VALUES ('',$Film_Name', '$Film_Release','$filmsynopsis','$film_image','$film_critic','$film_audience','$film_director','$film_studio','$film_imdbID','')";
$runquery1 = mysql_query($query1)or die(mysql_error());
Thanks guys
It looks like that you are missing an ' before $Film_Name. Can you add the missing apostrophe?
If you have phpmyadmin enabled on you server, you can paste the code into the SQL-Field to get syntax highlighting on the SQL query.

Categories