Schlo_50 Posted June 20, 2008 Share Posted June 20, 2008 Hi there, The script below adds address details to a temporary file (clients.DAT) along with a unique id number for each. I need a way of checking to see whether $aa (the variable that holds the id number) already exists in clients.DAT, and if it does redirect elsewhere and don't add anything new to my temp file. At the moment, even if the id number exists then the rest of the script runs regardless.. if($_GET['action'] == "Add_Client") { $a = $_POST['a']; $b = $_POST['b']; $c = $_POST['c']; $fileb = file("data/clients.DAT"); foreach($fileb as $keyb => $valb){ $datab[$keyb] = explode("|", $valb); $matchb = $datab[$keyb][0]; if ($a == $matchb){ print "Already Added!"; print "<meta HTTP-EQUIV=\"refresh\" content=\"1; url=?id=main\">"; } else { $content = "$a|$b|$c|"; $content = $content."\n"; $content = stripslashes($content); $fh = fopen("data/clients.DAT", "a+"); fwrite($fh, $content); fclose($fh); $title = "Client Added"; $msg = "A new head office has been added to the contact list."; $link = "?id=operate&action=Manage_Clients"; echo success_msg($title, $msg, $link); } } } Could someone show me how to do this please? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/111085-solved-checking/ Share on other sites More sharing options...
GingerRobot Posted June 20, 2008 Share Posted June 20, 2008 It's a little awkward to point out exactly what's wrong with your script without having some sample data. Either way, if you can guarantee that an ID couldn't be part of an address, you could just do a simple search for that ID in the file: $file = file_get_contents('data/clients.DAT'); if(strpos($file,$a) !== false){ //exists }else{ //doesn't exist -- write to file } Of course, using a database would be an easier alternative. Link to comment https://forums.phpfreaks.com/topic/111085-solved-checking/#findComment-570046 Share on other sites More sharing options...
Schlo_50 Posted June 20, 2008 Author Share Posted June 20, 2008 Thanks, I'll try that out. I'd like to be using a database, but that file only holds temporary data. I'll come back if I have any more problems. Thanks again. Link to comment https://forums.phpfreaks.com/topic/111085-solved-checking/#findComment-570048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.