dc_jt Posted May 24, 2007 Share Posted May 24, 2007 Hi I have a table containg name, description, url which contains many records When I submit a new form, I want it to check the url fields in the table and check it against what I have posted. Therefore something like $check_table = function here to get all urls if($_POST['url'] == $check_table) { return false; } else { return true } However, how do I get all the urls and get it to check each one? Thanks Link to comment https://forums.phpfreaks.com/topic/52782-checking-_post-against-records-in-table/ Share on other sites More sharing options...
DanDaBeginner Posted May 24, 2007 Share Posted May 24, 2007 $query= mysql_query("SELECT url FROM TABLE WHERE url = $_POST['url'] "); if (mysql_num_rows >= 1) { return false; } else { return true; } Link to comment https://forums.phpfreaks.com/topic/52782-checking-_post-against-records-in-table/#findComment-260581 Share on other sites More sharing options...
dc_jt Posted May 24, 2007 Author Share Posted May 24, 2007 Thanks I just realised how. What about when I update instead of add. Because if it looks in table it will find the one im trying to update. Shall I do a different query for update and do where id != $_POST[id] ?? Thanks Link to comment https://forums.phpfreaks.com/topic/52782-checking-_post-against-records-in-table/#findComment-260584 Share on other sites More sharing options...
DanDaBeginner Posted May 24, 2007 Share Posted May 24, 2007 yes, and also use mysql_real_escape_string to avoid sql injections... Link to comment https://forums.phpfreaks.com/topic/52782-checking-_post-against-records-in-table/#findComment-260587 Share on other sites More sharing options...
dc_jt Posted May 24, 2007 Author Share Posted May 24, 2007 Thanks for your help and tip but whats that? These are my functions now function validateAdd($from=NULL){ $valid = true; if(!$_POST[name]){$_POST[errors][name] = "<li>Please enter a headline for the campaign</li><br>"; $valid = false;} if(!$_POST[content]){$_POST[errors][content] = "<li>Please enter some content for the campaign</li><br>"; $valid = false;} if(!$_POST[url]){$_POST[errors][no_url] = "<li>Please enter a URL for the campaign</li><br>"; $valid = false;} if($_POST[discount_level_id] == 0){ $_POST[errors][discount_level_id] = "<li>Please enter a discount level</li><br>"; $valid = false; } if(!$_POST[code]){$_POST[errors][code] = "<li>Please enter a HEX code for the campaign</li><br>"; $valid = false;} if($_POST[url] != ''){ $get_url = $this->getUrl($_POST[url]); if($get_url > 0){ $_POST[errors][url] = "<li>This URL has already been taken. Please choose another.</li><br>"; $valid = false; } } return $valid; } function getUrl($iUrlId) { $db = new RCDB; $query = "SELECT COUNT(url) AS num FROM campaign WHERE url = '$_POST[url]' "; $db->query($query); $db->next_record(); return $this->listSize = $db->get_field('num'); } [/code][/code] Link to comment https://forums.phpfreaks.com/topic/52782-checking-_post-against-records-in-table/#findComment-260602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.