Jon12345 Posted December 12, 2006 Share Posted December 12, 2006 If someone goes to mypage1.php and their ip address is already in a record in my mysql database, how can I find that record and update the "status" field so it says "Yes"?Each record has id, ipaddress, date,status.Something like this maybe?[code]$query="INSERT INTO log (status) VALUES 'Yes' (WHERE ipaddress='".$ipaddress."'";[/code]Thanks,Jon Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 12, 2006 Share Posted December 12, 2006 Use an UPDATE query...[code]UPDATE tablename SET field1 = 'newvalue', field2 = 'newvalue' WHERE idfield = 'a value'[/code] Quote Link to comment Share on other sites More sharing options...
Jon12345 Posted December 12, 2006 Author Share Posted December 12, 2006 Ahh update huh? Would it look like this?[code]$query="UPDATE visitor_log SET status = '1' WHERE ipaddress ='".$ipaddress."'";$result=mysql_query($query);[/code]What happens if there is no value for $ipaddress? Does the code break? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 12, 2006 Share Posted December 12, 2006 it will update all reacords in the database that have no value for ip address. Quote Link to comment Share on other sites More sharing options...
Jon12345 Posted December 12, 2006 Author Share Posted December 12, 2006 Ok, so I presume I would do this:[code]if (!isset($ipaddress)) {$query="UPDATE visitor_log SET status = '1' WHERE ipaddress ='".$ipaddress."'";$result=mysql_query($query);}[/code]Would that ensure it only gets updated if there is a value in $ipaddress? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 12, 2006 Share Posted December 12, 2006 don't use the !...[code]if (isset($ipaddress)) { $query="UPDATE visitor_log SET status = '1' WHERE ipaddress ='".$ipaddress."'"; $result=mysql_query($query);}[/code]You're saying "If $ipaddress is not set" by using the !. Quote Link to comment Share on other sites More sharing options...
Jon12345 Posted December 12, 2006 Author Share Posted December 12, 2006 Oh yes, sorry. Stupid mistake. So if I remove the !, it will work as I stated? I'm a beginner if the question sounds lame. 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.