Hi I have following string to insert into database
$data = array('url' => http://www.amazon.co.uk/hedge-trimmers/s?ie=UTF8&page=1&rh=i:aps,k:'hedge trimmers);
I tired to insert that but I am getting 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 'hedge trimmers''' at line 1
SELECT * FROM seo_websites WHERE website = 'http://www.amazon.co.uk/hedge-trimmers/s?ie=UTF8&page=1&rh=i:aps,k:'hedge trimmers''
I think it is do with single quotes. Please I would really appreciate if someone can help me.Thank you
You can write your query using Active Record
$url="http://www.amazon.co.uk/hedge-trimmers/s?ie=UTF8&page=1&rh=i:aps,k:'hedge trimmers'";
$this->db->select('*');
$this->db->from('seo_websites');
$this->db->where('website',$url);
$data = array('url' => addslashes("http://www.amazon.co.uk/hedge-trimmers/s?ie=UTF8&page=1&rh=i:aps,k:'hedge trimmers"));
Related
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.
i'm trying to create a tagging sys demo here. And i'm stumped why i get this error
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 '#ok )' at line 1
here is my code:
$insert=mysqli_query($conn, 'insert into `hashtag` (posts) values ('.$data1.')') or die(mysqli_error($conn));
any help would be appreciated.
In mysqli query you don't have to put $conn .
Just remove it and in query put like this '".$data1."' And check.
I've been using this for loop to insert information into my database:
$values = array();
for($x=1;$x<=3;$x++){
$values[]= $_POST["FCKeditor".$x];
}
echo implode(",",$values);
$sql = "INSERT INTO virus (v1,v2,v3) VALUES(".implode(",",$values).")";
However, when I looked at the result on the webpage, it gave me this message:
a1
,b2
,c3
INSERT INTO virus (v1,v2,v3) VALUES(a1
,b2
,c3
)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 '>,b2
,c3
)' at line 1
Can someone help solve this issue?
Very likely the problem is the missing quotes, and you probably wanted something like the following for your values portion:
"'".implode("','",$values)."'"
Which gives you something like:
'abc','xyx','123'
Of course I am assuming that they are all of string type. If some are not, then you need to make sure strings are quoted and numbers are not etc.
The best is for sure to use place holders, then you do not need to go through this trouble at all.
I have a problem with CodeIgniter and Mysql. I am getting an error with a very simple query:
$o = "INSERT INTO usuarios (user, password) VALUES ('deesggsd', 'dsggd')";
$query = $this->db->query($o);
$this->db->query($query);
produces:
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
1
Filename: C:\wamp\www\newWeb\system\database\DB_driver.php
Line Number: 330
But the query is actually executed; the row appears on the database. What i'm doind wrong?
If I execute the same query on phpmyadmin, all is ok.
Thanks!!!
What you are doing with $query = $this->db->query($o); is executing the query and storing the result to the $query variable. So you've already run the INSERT once which is why it stores properly to the database.
Now when you try to run $this->db->query($query); you're basically trying to run a mysql procedure using the result (TRUE) as your query string. This is where it throws the error. Make sense?
Try doing this instead:
$this->db->insert('usuarios', array(
'user' => 'deesggsd',
'password' => 'dsggd'
);
I suggest looking into Active Record and how interaction between PHP & mysql work in general. No offense but this is a beginner level mistake.
you should use activer recored it's sample and easy,
that will be solve your problem
$values = array('user'=>'deesggsd', 'password'=> 'dsggd');
$this->db->insert('usuarios',$values)
http://ellislab.com/codeigniter/user-guide/database/active_record.html
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.