LinuX Posted April 8, 2010 Report Share Posted April 8, 2010 (edited) Sveiki palīdziet lūdzu pareizi izvilkt datus no datubāzes, man vajag izvilkt tikai vienu rindu no datubāzes piemēram rindu kur id ir vienāds ar 1. Paldies jau iepriekš. $txt = $_GET['txt']; mysql_connect("$host", "$user", "$pass") or die("cannot connect db"); mysql_select_db("$db_name") or die ("cannot select db"); $sql = "SELECT txt FROM $tbl_name WHERE id = '$_GET[\'id\']' "; $result = mysql_query($sql); while($rows = mysql_fetch_array($result)) { $check_name = strip_tags($rows['txt']); $wrap = wordwrap($check_name, 100, "<br>"); echo $wrap; } Edited April 8, 2010 by LinuX Quote Link to comment Share on other sites More sharing options...
Turecky Posted April 8, 2010 Report Share Posted April 8, 2010 Šajā rindiņā liekas ka vajadzēja rakstīt šādi, ja atmiņa neviļ: Nevis: $sql = "SELECT txt FROM $tbl_name WHERE id = '$_GET[\'id\']' "; Bet: $sql = "SELECT txt FROM $tbl_name WHERE id = '$_GET[id]' "; Bet var jau arī vispirms: $id = $_GET['id']; Un tad: $sql = "SELECT txt FROM $tbl_name WHERE id = '$id' "; Quote Link to comment Share on other sites More sharing options...
LinuX Posted April 8, 2010 Author Report Share Posted April 8, 2010 (edited) stradā, izrādās kļūda bija citā failā, līdz ar to tas fails nosūtija nepareizus datus. Edited April 8, 2010 by LinuX Quote Link to comment Share on other sites More sharing options...
kirils Posted April 8, 2010 Report Share Posted April 8, 2010 papēti, kas notiks, ja iekš $_GET['id'] buus, piemēram vērtība ' or (truncate xxxx) or ' $_GET['id'] u.c. vajadzētu apstrādāt ar addslashes() vai mysql_escape_string() pirms padošanas uz sql. Quote Link to comment Share on other sites More sharing options...
codez Posted April 8, 2010 Report Share Posted April 8, 2010 Ja id ir vesels skaitlis, tad var izmantot typecastu pluss erroru atslēgšanu, ja gadījumā GET mainīgais nav padots, tad nevajag real_escape. $id=(int)@$_GET['id']; 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.