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 '-userfile WHERE id='642' AND userid='459'' at line 1 This is the code

$query = "SELECT * FROM ue-userfile WHERE id='$imageid' AND userid='$userid'";
	$result = mysql_query($query) or die(mysql_error());

	$row = mysql_fetch_array($result) or die(mysql_error());

		$oldalbum = $row['albumname'];
		//if($oldalbum < 2){$oldalbum = "";}
	//albumname = '$oldalbum' BY
	$result6 = mysql_query("UPDATE ue-userfile SET albumname =$newalbum WHERE id=$imageid")or die(mysql_error()); 
	if($result6){echo "Done!";}else echo "Something went wrong...";

Dani AI

Generated

The syntax error was caused by the hyphen in the table name: an unquoted identifier with a dash is parsed as subtraction. correctly pointed out that quoting the identifier fixes the immediate error, but a better long-term approach is to rename the table to use underscores or plain alphanumeric characters so you avoid the need for quoting and reduce surprises across tools and SQL dialects.

Also review how values are being inserted into SQL. Concatenating PHP variables into queries without quoting or escaping can cause syntax errors (and security issues). The album name is a string and must be quoted or, preferably, bound as a parameter. The old mysql_* API is deprecated; switch to mysqli or PDO and use prepared statements. Example (PDO) pattern for a safe update:

$pdo = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8mb4', 'dbuser', 'dbpass', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

$stmt = $pdo->prepare('UPDATE `user_files` SET albumname = :album WHERE id = :id AND userid = :userid');
$stmt->execute(['album' => $newalbum, 'id' => (int)$imageid, 'userid' => (int)$userid]);

Extra tips: check query success before fetching, verify row counts when expecting rows, cast or validate numeric IDs, and enable exception-based error reporting so you get meaningful messages. confirmed the syntax fix; the items above will help avoid similar problems and secure the code.

Recommended Answers

All 2 Replies

That dash is being interpreted as a minus sign. Try wrapping the table name in back quotes:

SELECT * FROM `ue-userfile` WHERE id='$imageid' AND userid='$userid'

Fixed. thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.