Jump to content
php.lv forumi

register.php


student

Recommended Posts

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;

 

?>

post-4959-081274100 1290247246_thumb.jpg

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...