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. Link to comment https://forums.phpfreaks.com/topic/178708-solved-php-parse-not-working/ Share on other sites More sharing options...
gizmola Posted October 23, 2009 Share Posted October 23, 2009 And what is your error? Link to comment https://forums.phpfreaks.com/topic/178708-solved-php-parse-not-working/#findComment-942690 Share on other sites More sharing options...
dreamlove Posted October 23, 2009 Share Posted October 23, 2009 what is the error message? Link to comment https://forums.phpfreaks.com/topic/178708-solved-php-parse-not-working/#findComment-942692 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. Link to comment https://forums.phpfreaks.com/topic/178708-solved-php-parse-not-working/#findComment-942693 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. Link to comment https://forums.phpfreaks.com/topic/178708-solved-php-parse-not-working/#findComment-942698 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 Link to comment https://forums.phpfreaks.com/topic/178708-solved-php-parse-not-working/#findComment-942701 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. Link to comment https://forums.phpfreaks.com/topic/178708-solved-php-parse-not-working/#findComment-942706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.