p4F Posted December 6, 2007 Report Share Posted December 6, 2007 Kā var parbaudīt vai id existē man ir comment.php kurā ir if(preg_match('/^[0-9]*$/i', $_GET['id'])) { // sheit rāda jaunumus } bet ja es izvadu kādu citu comment.php?id=600 (nepareizu) man rāda tukšu! Link to comment Share on other sites More sharing options...
Vebers Posted December 6, 2007 Report Share Posted December 6, 2007 No kurienes tev tie jaunumi nāk? No DB ? Ja tā, tad paskaties vai ir atbiltošs ieraksts db.. Link to comment Share on other sites More sharing options...
andrisp Posted December 6, 2007 Report Share Posted December 6, 2007 preg_match nevajag. function id_exists($id) { // sql, kas pārbauda vai $id ir atrodas iekš db } if (!is_numeric($_GET['id']) || !id_exists($_GET['id'])) { die(); } Link to comment Share on other sites More sharing options...
p4F Posted December 6, 2007 Author Report Share Posted December 6, 2007 preg_match nevajag. function id_exists($id) { // sql, kas pārbauda vai $id ir atrodas iekš db } if (!is_numeric($_GET['id']) || !id_exists($_GET['id'])) { die(); } vot man un vajaga kodu kas pārbauda vai $id atrodas DB Link to comment Share on other sites More sharing options...
Val Posted December 6, 2007 Report Share Posted December 6, 2007 http://dev.mysql.com/doc/en/SELECT.html Link to comment Share on other sites More sharing options...
p4F Posted December 6, 2007 Author Report Share Posted December 6, 2007 function id_exists($id) { mysql_query("SELECT name, nov, time FROM news WHERE id = {$_GET['id']}"); } if (!is_numeric($_GET['id']) || !id_exists($_GET['id'])) { die(); } tā? Link to comment Share on other sites More sharing options...
Kristabs Posted December 6, 2007 Report Share Posted December 6, 2007 function id_exists($id) { $rez= mysql_query("SELECT count(*) FROM news WHERE id = '".addslashes($id)."'"); list($num) = mysql_fetch_array($rez); if($num > 0){ return TRUE; } else { return TRUE; } } if (!is_numeric($_GET['id']) || !id_exists($_GET['id'])) { die(); } Link to comment Share on other sites More sharing options...
andrisp Posted December 6, 2007 Report Share Posted December 6, 2007 Manuāli vajag lasīt, bet: function id_exists() { $result = mysql_query("SELECT COUNT(*) FROM news WHERE id = ".(int) $id); list($count) = mysql_get_row($result); return $count > 0 ? true : false; } Link to comment Share on other sites More sharing options...
p4F Posted December 6, 2007 Author Report Share Posted December 6, 2007 http://paste.php.lv/6534 re kur ir pilns kods bet man nestradā ;[ Link to comment Share on other sites More sharing options...
Aleksejs Posted December 6, 2007 Report Share Posted December 6, 2007 Kas tieši? Vēlams saliktā, paplašinātā teikumā. ;) Link to comment Share on other sites More sharing options...
Aleksejs Posted December 6, 2007 Report Share Posted December 6, 2007 Un obligāti izlasi šo: SQL injekcijas * http://php.lv/f/index.php?showtopic=1729 * http://php.lv/f/index.php?showtopic=2347 Link to comment Share on other sites More sharing options...
p4F Posted December 6, 2007 Author Report Share Posted December 6, 2007 man ir jaunākais jaunums ar ?id=14 bet ja es uzlieku piemēram ?id=17. Viņš nerāda echo "Netu takova novosti"; bet es nezinu kaa lai izdara lai stradaatu Link to comment Share on other sites More sharing options...
Aleksejs Posted December 6, 2007 Report Share Posted December 6, 2007 1) Tev nav tāda echo "Netu takova novosti"; 2) Select count... atgriež vienu ciparu, kas parāda, cik šādu id ir - tātad vai nu nulle, vai viens. Negribu iedziļināties, bet minējums no zila gaisa, ka list atgriež vaicājuma atgriezto ierakstu skaitu (kas ir 1 vai tāds id ir, vai nav). Link to comment Share on other sites More sharing options...
p4F Posted December 6, 2007 Author Report Share Posted December 6, 2007 (edited) ehh nevaru saprast kā lai izdara? kādu tad variantu izmantot andrisp vai Kristaba? Edited December 6, 2007 by p4F Link to comment Share on other sites More sharing options...
Aleksejs Posted December 6, 2007 Report Share Posted December 6, 2007 Pareizo! :D Nu paskaties pats, ko tas list dara un "ziemā ēd" Papēti, ko atgriež vaicājums: select count(id) from news where id=17 un ko select count(id) from news where id=14 ... Info par list var atrast dokumentācijā: http://lv.php.net/manual/en/ Link to comment Share on other sites More sharing options...
Recommended Posts