View Full Version : Quick Query Fix.
iceflyin
07-29-2007, 03:53 AM
I screwed up this query when I added WHERE user = '$ownerId'.
Do I add it before (userFeeds,userFeedTitles)? I'm kinda lost...
$sql="INSERT INTO userInfo (userFeeds,userFeedTitles) WHERE user = '$ownerId' VALUES ($urlArray,$titleArray) ON DUPLICATE KEY UPDATE userFeeds= $urlArray, userFeedTitles= $titleArray";
_Aerospace_Eng_
07-29-2007, 03:56 AM
The WHERE needs to go at the end after $titleArray.
iceflyin
07-29-2007, 04:05 AM
Sweet, thanks!
iceflyin
07-29-2007, 09:09 AM
Ah, help again... I'm getting a syntax error. Whats the deal... It all looks correct...
$sql="INSERT INTO $table (user,userFeeds,userFeedTitles,userImageURL)
VALUES ($ownerId,$urlArray,$titleArray,$imageURL)
ON DUPLICATE KEY UPDATE userFeeds= '$urlArray', userFeedTitles= '$titleArray', userImageURL = '$imageURL'
WHERE user = '$ownerId'";
Note, $ownerId is the key.
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 'WHERE user = 131212' at line 4"
_Aerospace_Eng_
07-29-2007, 09:41 AM
$sql="INSERT INTO $table (user,userFeeds,userFeedTitles,userImageURL)
VALUES ($ownerId,$urlArray,$titleArray,$imageURL) WHERE user = '$ownerId'
ON DUPLICATE KEY UPDATE userFeeds= $urlArray, userFeedTitles= $titleArray, userImageURL = $imageURL";
You may want to echo $sql to see the query so you can tell why its messing up.
iceflyin
07-29-2007, 09:48 AM
I already did, look at the bottom of my last post... Heres the new one with your latest code:
"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 user = '2313123'
ON DUPLICATE KEY UPDATE userFeeds= waefawf,wafwa, user' at line 2"
I'm using PHP5,SQL5. Note, this code is supposed to input four variables, including the index, if the index variable exists... It simply updates the last three. I dunno whats up. I had this working earlier before I started adding stuff.
Entire function, in case this is where the problem is:
Database screenshot: http://designmichael.com/screen.gif Testing Screenshothttp://designmichael.com/screen2.gif
function Save($ownerId, $urlArray, $titleArray, $imageURL){
$dbhost = 'localhost';
$dbuser = 'designmi_faceb';
$dbpass = 'faceb1';
$dbname = 'designmi_facebook';
$table = 'flashyUserInfo';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $conn);
//Save data in DB
$sql="INSERT INTO $table (user, userFeeds, userFeedTitles, userImageURL)
VALUES ($ownerId, $urlArray, $titleArray, $imageURL) WHERE user = '$ownerId'
ON DUPLICATE KEY UPDATE userFeeds= $urlArray, userFeedTitles= $titleArray, userImageURL = $imageURL";
if (!mysql_query($sql,$conn))
{
return mysql_error();
} else{
return "Sucess";
}
mysql_close();
}
_Aerospace_Eng_
07-29-2007, 10:18 AM
As I said you should echo $sql meaning physically echo it, instead of this
if (!mysql_query($sql,$conn))
{
return mysql_error();
} else{
return "Sucess";
}
Use this
$query = mysql_query($sql,$conn) or die('this is the query: '.$sql);
Post the query that you get after it says "this is the query: "
iceflyin
07-29-2007, 10:22 AM
Object)#0
message = "faultCode:INVALID_AMF_MESSAGE faultString:'Invalid AMF message' faultDetail:
'this is the query:
INSERT INTO flashyUserInfo (user, userFeeds, userFeedTitles, userImageURL)
VALUES (34234, fawwwfefffdd, waef, awef) WHERE user = '34234'
ON DUPLICATE KEY UPDATE userFeeds= fawwwfefffdd, userFeedTitles= waef, userImageURL = awef'"
name = "Error"
rootCause = (null)
Are you sure "WHERE" is supposed to be there? It's only supposed to use WHERE if user already exists...
_Aerospace_Eng_
07-29-2007, 10:25 AM
Try this
$sql="INSERT INTO $table (user, userFeeds, userFeedTitles, userImageURL) VALUES ($ownerId, '$urlArray', '$titleArray', '$imageURL') WHERE user = $ownerId ON DUPLICATE KEY UPDATE userFeeds= '$urlArray', userFeedTitles= '$titleArray', userImageURL = '$imageURL'";
iceflyin
07-29-2007, 10:28 AM
Omg, I just found what I did wrong... I found my working code in my old post...
$sql="INSERT INTO userInfo (user, rssURL, imageURL, feedSource) VALUES ('$_POST[user]','$_POST[rssURL]','$_POST[imageURL]','$_POST[feedSource]') ON DUPLICATE KEY UPDATE rssURL= '$_POST[rssURL]', imageURL= '$_POST[imageURL]', feedSource ='$_POST[feedSource]'";
Sorry about that... I should have known I didn't need WHERE! Thanks a ton for helping...
That was a one and a half hour headache... All cuz I added stupid "WHERE", when i didn't need it... MySQL is smart and already knew "WHERE".
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.