student Posted November 20, 2010 Report Share Posted November 20, 2010 Kur ir kļūda?Man darbojas tikai pirmais query un nenotiek nekas tālāl.Skatīt zemāk. <html> <head><title>register</title></head> <body> <h1>Register</h1> <table> <form action="register.php" method="POST"> <tr><td>Name:<td><input type="text" name="name"> <tr><td>Surname:<td><input type="text" name="surname"> <tr><td>Username:<td><input type="text" name="username"> <tr><td>Password:<td><input type="text" name="password"> <tr><td><td><input type="submit" value="turpināt"> </table> </body> </html> <?php mysql_connect("localhost","root",""); mysql_select_db("message"); if(isset($_POST['name'],$_POST['surname'],$_POST['username'],$_POST['password']) && $_POST['name']!=="" && $_POST['surname']!=="" && $_POST['username']!=="" && $_POST['password']!=="" ){ $name=$_POST['name']; $surname=$_POST['surname']; $username=$_POST['username']; $password=$_POST['password']; $query="select * from lietotajs"; $result=mysql_query($query); while ($row = mysql_fetch_assoc($result)) { // Šeit notiek pārbaude vai ir iepriekš bijis izveidots šāds username un ja nav tad tiek iedots nākamais query.Bet tas nenotiek un vissu laiku tikai darbojas pirmais query. if($row['username']==$_POST['username']){ header('location:register.php'); } else{ $query="insert into lietotajs VALUES ('$name','$surname','username','$password')"; mysql_query($query); echo $query; } } } else{ $_POST['name']=""; $_POST['surname']=""; $_POST['username']=""; $_POST['password']=""; } echo $query; ?> Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 20, 2010 Report Share Posted November 20, 2010 Izmanto " ". Quote Link to comment Share on other sites More sharing options...
Code Posted November 20, 2010 Report Share Posted November 20, 2010 Tu katru reizi atlasi visus lietotājus no datu bāzes un tad katram skaties vai atgrieztais username sakrīt ar tevis padoto, ja nesakrīt, tad pie katras rindas apstrādes tu veido jaunu lietotāju. Īsāk sakot - WTF?! Es ieteiktu nemeklēt kļūdu esošajā risinājumā, bet uzrakstīt pa jaunu normāli, SQL pieprasījumā izmantojot WHERE nosacījumus. Quote Link to comment Share on other sites More sharing options...
student Posted November 20, 2010 Author Report Share Posted November 20, 2010 Pilnīgi biju aizmirsis par where esamību... Quote Link to comment Share on other sites More sharing options...
student Posted November 20, 2010 Author Report Share Posted November 20, 2010 Bet tad pie kā man vajadzētu koriģēt to while?Pie select *,vai pie INSERT INTO? Quote Link to comment Share on other sites More sharing options...
Code Posted November 20, 2010 Report Share Posted November 20, 2010 Priekš kam vispār tev tas while cikls jātaisa? Quote Link to comment Share on other sites More sharing options...
student Posted November 20, 2010 Author Report Share Posted November 20, 2010 Nevis while,bet where Quote Link to comment Share on other sites More sharing options...
mounkuls Posted November 20, 2010 Report Share Posted November 20, 2010 $query = "SELECT * FROM `lietotaji` WHERE username='".mysql_real_escape_string($_POST['username'])."' LIMIT 1"; Un to while tur točna nevajag, kāda jēga dzīt ciklu, ja pats selekts ar WHERE jau vai nu atlasīs to lietotāju, būs TRUE vai arī neatlasīs un būs FALSE. Quote Link to comment Share on other sites More sharing options...
Code Posted November 20, 2010 Report Share Posted November 20, 2010 ... $query="select * from lietotajs"; $result=mysql_query($query); while ($row = mysql_fetch_assoc($result)) { ... Es par šito brīnumu runāju. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 20, 2010 Report Share Posted November 20, 2010 Bet tad pie kā man vajadzētu koriģēt to while?Pie select *,vai pie INSERT INTO? Nevis while,bet where R u kiddin' me? xDD 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.