Selecting a table and setting a value in it in Mysql - php

I am trying to write a script that archives a user by setting the value of the archive column to the value of 1 . I have written the following script to do this, but I am not sure if I am using the syntax correctly as I am am getting the following error.
<?php
mysql_query("SELECT FROM archive hqfjt_chronoforms_data_addupdatelead
WHERE cf_uid = '{cf_uid}'
SET archive='1';"
) or die(mysql_error());
?>
The error I am getting 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 'WHERE cf_uid = 'c68235f3fb5c3f7fff6247b04c450dd7' SET archive='1'' at line 1

There's no SET in a SELECT statement, and you're missing the FROM part.
You need an UPDATE command, perhaps like:
UPDATE archive SET archive='1' WHERE cf_uid = '$cf_uid'

UPDATE archive, not SELECT archive. Also, you're inviting a visit from little Bobby Tables.

Related

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. :-)

Copy Data From 1 Database to Other Using IF

Hi i have 2 databases in local host i want to copy UPC field from one to other if their product models are same?
I have tried this:
USE `medway_opencart` , `medway_eski_bakkal`
UPDATE `medway_opencart.product`
SET `medway_opencart.product.upc` = `medway_eski_bakkal.product.upc`
WHERE `medway_opencart.product.model` = `medway_eski_bakkal.product.model`
And i am getting this error:
#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 near ' `medway_eski_bakkal` UPDATE `medway_opencart.product` SET `medway_opencart.' at line 1
Omit the first line, no need to use any database unless your using fully qualified name(db.table)
UPDATE `medway_opencart.product`
SET `medway_opencart.product.upc` = `medway_eski_bakkal.product.upc`
WHERE `medway_opencart.product.model` = `medway_eski_bakkal.product.model`
Unless you have priviledge to access both the databases..

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.

Inserting Metatag strings into a mysql table

I want to take meta tags from an external webpage and save it into my mysql db, although I keep getting an error. Some help would be appreciated.
$tags = get_meta_tags($_POST['url']);
if (array_key_exists("description", $tags)){
$desc = mysql_real_escape_string($tags['description']);
}
$postQ = mysql_query("INSERT INTO posts (userdesc,desc,title,url,userid) VALUES ('$userdesc','$desc','$title','$url','$userid')");
The error I keep getting is 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 'desc,title,url,userid) VALUES ('Wow this house is small','We've featu' at line 1
desc is a mysql reserved word either enclose that field name in backticks or rename the field name to something else.
eg.
mysql_query("INSERT INTO posts (userdesc,`desc`,title,url,userid)...

Categories