DrTrans Posted October 23, 2009 Share Posted October 23, 2009 $connect = mysql_connect("localhost","damgears_evil","****"); mysql_select_db("damgears_evil", $connect); $result = mysql_query("SELECT * FROM sales WHERE key = '$key'"); if (mysql_num_rows($result)== FALSE) { echo "Error: Contact Affliction Lexington."; mysql_close($connect); } else { $queryb = mysql_query("INSERT INTO titles VALUES ('','$fname','$lname','$key','$slname','$skey','$date','$striped','$region')"); mysql_close($connect); echo "$title"; } basically what i want to do here is if there are no records in the sales table for that key . then echo" Error" . if there is a key that matchs.. insert record. Please help. Quote Link to comment Share on other sites More sharing options...
gizmola Posted October 23, 2009 Share Posted October 23, 2009 And what is your error? Quote Link to comment Share on other sites More sharing options...
dreamlove Posted October 23, 2009 Share Posted October 23, 2009 what is the error message? Quote Link to comment Share on other sites More sharing options...
DrTrans Posted October 23, 2009 Author Share Posted October 23, 2009 Result is not a valid Mysql resource. Quote Link to comment Share on other sites More sharing options...
gizmola Posted October 23, 2009 Share Posted October 23, 2009 First things first, you should check to see if your database connection was successful. Your code assumes it is, but that could be an erroneous assumption. Ditto, with your database select. Quote Link to comment Share on other sites More sharing options...
DrTrans Posted October 23, 2009 Author Share Posted October 23, 2009 the connection works and so does the select: I replaced the code with this if($title){ echo "$title"; $connect = mysql_connect("localhost","damgears_evil","damgears"); mysql_select_db("damgears_evil"); // $queryb = mysql_query("INSERT INTO titles VALUES (fname, lname, key, sname, skey, date, title, region) VALUES ('$fname','$lname','$key','$slname','$skey','$date','$title','$region')"); $queryb = mysql_query("INSERT INTO titles VALUES ('','$fname','$lname','$key','$slname','$skey','$date','$striped','$region')"); mysql_close($connect); } else echo"Problem.. Check Database"; And it inserts the information just fine into the "titles" table. However like i said, Im wanting to check to make sure the " Sale" has happened before it inserts into the "titles" table. by using that SELECT * FROM sales WHERE key = '$key' In my sales table i have fname lname key date region Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 23, 2009 Share Posted October 23, 2009 Hi DrTrans, The problem is occuring because you are using the reserved word "key" in your statement. When using reserved words you must escape them with backticks, i.e. `key`. Click here for further information on MySQL reserved words. Hope this helps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.