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 Link to comment https://forums.phpfreaks.com/topic/30372-inserting-record-into-mysql/ 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] Link to comment https://forums.phpfreaks.com/topic/30372-inserting-record-into-mysql/#findComment-139750 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? Link to comment https://forums.phpfreaks.com/topic/30372-inserting-record-into-mysql/#findComment-139764 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. Link to comment https://forums.phpfreaks.com/topic/30372-inserting-record-into-mysql/#findComment-139766 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? Link to comment https://forums.phpfreaks.com/topic/30372-inserting-record-into-mysql/#findComment-139790 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 !. Link to comment https://forums.phpfreaks.com/topic/30372-inserting-record-into-mysql/#findComment-139796 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. Link to comment https://forums.phpfreaks.com/topic/30372-inserting-record-into-mysql/#findComment-139819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.