Skip navigation links

MySQL Forums :: PHP :: SOLVED: error when trying to update xbmc db via php - help needed


Advanced Search

SOLVED: error when trying to update xbmc db via php - help needed
Posted by: Thomas Lysdal ()
Date: September 20, 2012 08:05AM

Im trying to update my movie database but something is off. Anybody see the error?

Any help is appreciated, thank you!


Here is the code:
<?php

$db = "xbmc_video60";
$table = "tvshowview";
$changefield = "strPath";
$idfield = "idShow";

// Make a MySQL Connection
mysql_connect("localhost", "xbmc", "xbmc") or die(mysql_error());
mysql_select_db($db) or die(mysql_error());


$query = "SELECT * FROM $table";
$result = mysql_query($query) or die(mysql_error());
#echo $result;

while($row = mysql_fetch_array($result)){

$id = $row[$idfield];
$str = $row[$changefield];
$newstr = str_replace("/home/thomas/", "/storage/", $str);
echo $idfield . " = " . $id . "<br><b>Old value:</b> <i>" . $str . "</i><br><b>New value:</b> <i>" . $newstr . "</i><br><br>";

mysql_query("UPDATE $table SET $changefield = $newstr WHERE $idfield = $id") or die(mysql_error());


}

?>




And this is the output i get:

idShow = 1
Old value: /home/thomas/Nas/Medier/Serier/how I met your mother/
New value: /storage/Nas/Medier/Serier/how I met your mother/

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 '/storage/Nas/Medier/Serier/how I met your mother/ WHERE idShow = 1' at line 1


Version: 5.1.63-0ubuntu0.11.04.1

SOLVED: it seemed I needed to do this
mysql_query("UPDATE $table SET $changefield = '$newstr' WHERE $idfield = $id") or die(mysql_error());

I suppose its because of the spaces in the variable. but i dont know for sure!



Edited 2 time(s). Last edit at 09/20/2012 09:23AM by Thomas Lysdal.

Options: ReplyQuote


Subject Written By Posted
SOLVED: error when trying to update xbmc db via php - help needed Thomas Lysdal 09/20/2012 08:05AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.