Вот в чом проблема!! Возвращает пустую строку! помогите!!! $guery = "SELECT id FROM user WHERE user_name = '$user_name';"[/html]
PHP: $guery = "SELECT `id` FROM `user` WHERE `user_name` = '" . $_GET['user_name'] . "'"; Кстати... По-моему должно быть так Код (Text): '$user_name'";
<?php $db = mysql_connect("localhost", "root","") or die("Error"); mysql_select_db("mydb",$db); $supersecret_hash_padding = 'A string that is used to pad out short string for md5 encryption.' ; $submit = $_POST['submit']; function user_register(){ global $supersecret_hash_padding; if (strlen($_POST['last_name'])<=25 && strlen($_POST['last_name'])>0 && strlen($_POST['first_name'])<=25 && strlen($_POST['first_name'])>0 && strlen($_POST['user_name'])<=25 && strlen($_POST['user_name'])>0 && strlen($_POST['password1'])>0 && strlen($_POST['password1'])<=25 && ($_POST['password1'])==($_POST['password2']) && strlen($_POST['email'])<=25 && strlen($_POST['email'])>0 && validate_email($_POST['email'])){ if (account_namevalid($_POST['user_name']) || strlen($_POST['password1'])>=6){ $user_name = strtolower($_POST['user_name']); $user_name = trim($user_name); $email = $_POST['email']; $query1 = "SET NAMES 'cp1251'"; echo $result = mysql_query($query1); echo $result = 2; echo $guery = "SELECT 'id' FROM 'user' WHERE 'user_name' = '$user_name'"; echo "G:".$result = mysql_query($query); if (($result)){ $feedback = 'ERROR - Username or email address laready exists'; return $feedback; } else { $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $password = $_POST['password1']; $hash = md5($email.$supersecret_hash_padding); $query = " INSERT INTO user (first_name, last_name, user_name, password, email, confirm_hash, is_confirmed, date_create) VALUES ('$first_name', '$last_name', '$user_name', '$password', '$email', '$hash', '1', NOW());"; $result = mysql_query($query); if (!$result){ mysql_close($db); $feedback = 'ERROR - Database error'; mysql_close($db); return $feedback; } else { $encoded_email = urlencode($_POST['email']); $mail_body = <<<EOMAILBODY Thank you for registering at Example.com. Clock this link to confirm your registration: http://localhost/confirm.php?hash=$hash ... oded_email Once you see a confirmation message, you will be logged into Example.com EOMAILBODY; mail ($email, 'Exaple.com Registration Confirmation', $mail_body, 'From noreply@example.com'); $feedback = '<a href="http://localhost/surreal/confirm.php?hash=$hash&email=$encoded_email">RR</a>!!Дякуємо за реєстрацію! <a href="index.html">На головну сторінку</a>'; return $feedback; } } } else { $feedback = 'ERROR - Username or password invalid '; return $feedback; } } else { $feedback = 'ERROR - Please fill in all fields correctly'; return $feedback; } } function account_namevalid(){ $span_str = "abcdefghijklmnopqrstuvwxyz"."ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"; if (strspn($_POST['user_name'],$span_str) == 0){ return false; } if (strspn($_POST['user_name'],$span_str) != strlen($name)){ return false; } if (strspn($_POST['user_name']) < 5){ return false; } if (strspn($_POST['user_name']) > 25){ return false; } if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)|(uucp)|(operator)|(games)|(mysql)| (httpd)|(nobody)|(dummy)|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))", $_POST['user_name'])){ return false; } if (eregi("^(anoncvs_)", $_POST['user_name'])) { return false; } return true; } function validate_email(){ return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $_POST['email'])); } function user_confirm (){ global $supersecret_hash_padding; $new_hash = md5($_GET['email'].$supersecret_hash_padding); if ($new_hash && ($new_hash == $_GET['hash'])){ $query = "SELECT user_name FROM user WHERE confirm_hash = '$new_hash'"; $result = mysql_query($query); if (!$result || mysql_num_rows($result)<1){ $feedback = 'ERROR - Hash not found'; return $feedback; } else { $email = $_GET['email']; $hash = $_GET['hash']; $query = "UPDATE user SET email='$email', is_confirmed = '1' WHERE confirm_hash = '$hash'"; $result = mysql_query($query); return 1; } } else { $feedback = 'ERROR - Values do not match'; return $feedback; } } if ($submit == 'Mail confirmation'){ $feedback = user_register(); $feedback_str = "<P class\"errormess\">$feedback</P>"; } else { $feedback_str = ''; } $php_self = $_SERVER['PHP_SELF']; $reg_str = <<<EOREGSTR <TABLE CELLPADDING=0 CELLPACING=0 BORDER=0 ALIGN=CENTER WIDTH=621> <TR> <TD ROWSPAN=10><IMG WIDTH=15 HEIGHT=1 SRC=""></TD> <TD WIDTH=606></TD> </TR> <tr> <td> $feedback_str <p class="left"><b>REGISTER</b></p> kjh;lkernqg;oerkn;lkwqmng;lekwnmg;lewkng;lewkrng;oiewn eogiw poginmoirmn ;lgkmwg e gne;wginm;oeigj;lekmng gikjelkw giojnerokjgnrgroinlkrgnmrl;kgtnmltrk <form action="$php_self" method="POST"> <p class="bold">First Name<br> <input type="text" name="first_name" value="first_name" size="20" maxlength="25"></p> <p class="bold">Last Name<br> <input type="text" name="last_name" value="last_name" size="20" maxlength="25"></p> <p class="bold">Username<br> <input type="text" name="user_name" value="user_name" size="20" maxlength="25"></p> <p class="bold">Password<br> <input type="password" name="password1" value="1234567" size="20" maxlength="25"></p> <p class="left">Password(again)<br> <input type="password" name="password2" value="1234567" size="20" maxlength="25"></p> <p class="left">Email<br> <input type="text" name="email" value="we@email.ru" size="30" maxlength="50"></p> <p><input type="submit" name="submit" value="Mail confirmation"></p> </form> </td> </tr> </table> EOREGSTR; echo $reg_str; ?>
извеняюсь за то что код не форматирований!!! времени нет а строк много!!! ничего не помогает!!! пишу в консоле: mysql>SELECT id mysql>FROM user mysql>WHERE user_name = '$user_name'; работает переношу в скрипт не роботает!!!((( возвращает "" а должно 1; <?php $db = mysql_connect("localhost", "root","") or die("Error"); mysql_select_db("mydb",$db); $supersecret_hash_padding = 'A string that is used to pad out short string for md5 encryption.' ; $submit = $_POST['submit']; function user_register(){ global $supersecret_hash_padding; if (strlen($_POST['last_name'])<=25 && strlen($_POST['last_name'])>0 && strlen($_POST['first_name'])<=25 && strlen($_POST['first_name'])>0 && strlen($_POST['user_name'])<=25 && strlen($_POST['user_name'])>0 && strlen($_POST['password1'])>0 && strlen($_POST['password1'])<=25 && ($_POST['password1'])==($_POST['password2']) && strlen($_POST['email'])<=25 && strlen($_POST['email'])>0 && validate_email($_POST['email'])){ if (account_namevalid($_POST['user_name']) || strlen($_POST['password1'])>=6){ $user_name = strtolower($_POST['user_name']); $user_name = trim($user_name); $email = $_POST['email']; echo $guery = "SELECT 'id' FROM 'user' WHERE 'user_name' = '$user_name'"; echo "Здесь ошибка:".$result = mysql_query($query); if (($result)){ $feedback = 'ERROR - Username or email address laready exists'; return $feedback; } else { $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $password = $_POST['password1']; $hash = md5($email.$supersecret_hash_padding); $query = " INSERT INTO user (first_name, last_name, user_name, password, email, confirm_hash, is_confirmed, date_create) VALUES ('$first_name', '$last_name', '$user_name', '$password', '$email', '$hash', '1', NOW());"; $result = mysql_query($query); if (!$result){ mysql_close($db); $feedback = 'ERROR - Database error'; mysql_close($db); return $feedback; } else { $encoded_email = urlencode($_POST['email']); $mail_body = <<<EOMAILBODY Thank you for registering at Example.com. Clock this link to confirm your registration: http://localhost/confirm.php?hash=$hash ... oded_email Once you see a confirmation message, you will be logged into Example.com EOMAILBODY; mail ($email, 'Exaple.com Registration Confirmation', $mail_body, 'From noreply@example.com'); $feedback = '<a href="http://localhost/surreal/confirm.php?hash=$hash&email=$encoded_email">RR</a>!!Дякуємо за реєстрацію! <a href="index.html">На головну сторінку</a>'; return $feedback; } } } else { $feedback = 'ERROR - Username or password invalid '; return $feedback; } } else { $feedback = 'ERROR - Please fill in all fields correctly'; return $feedback; } } function account_namevalid(){ $span_str = "abcdefghijklmnopqrstuvwxyz"."ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"; if (strspn($_POST['user_name'],$span_str) == 0){ return false; } if (strspn($_POST['user_name'],$span_str) != strlen($name)){ return false; } if (strspn($_POST['user_name']) < 5){ return false; } if (strspn($_POST['user_name']) > 25){ return false; } if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)|(uucp)|(operator)|(games)|(mysql)| (httpd)|(nobody)|(dummy)|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))", $_POST['user_name'])){ return false; } if (eregi("^(anoncvs_)", $_POST['user_name'])) { return false; } return true; } function validate_email(){ return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $_POST['email'])); } function user_confirm (){ global $supersecret_hash_padding; $new_hash = md5($_GET['email'].$supersecret_hash_padding); if ($new_hash && ($new_hash == $_GET['hash'])){ $query = "SELECT user_name FROM user WHERE confirm_hash = '$new_hash'"; $result = mysql_query($query); if (!$result || mysql_num_rows($result)<1){ $feedback = 'ERROR - Hash not found'; return $feedback; } else { $email = $_GET['email']; $hash = $_GET['hash']; $query = "UPDATE user SET email='$email', is_confirmed = '1' WHERE confirm_hash = '$hash'"; $result = mysql_query($query); return 1; } } else { $feedback = 'ERROR - Values do not match'; return $feedback; } } if ($submit == 'Mail confirmation'){ $feedback = user_register(); $feedback_str = "<P class\"errormess\">$feedback</P>"; } else { $feedback_str = ''; } $php_self = $_SERVER['PHP_SELF']; $reg_str = <<<EOREGSTR <TABLE CELLPADDING=0 CELLPACING=0 BORDER=0 ALIGN=CENTER WIDTH=621> <TR> <TD ROWSPAN=10><IMG WIDTH=15 HEIGHT=1 SRC=""></TD> <TD WIDTH=606></TD> </TR> <tr> <td> $feedback_str <p class="left"><b>REGISTER</b></p> kjh;lkernqg;oerkn;lkwqmng;lekwnmg;lewkng;lewkrng;oiewn eogiw poginmoirmn ;lgkmwg e gne;wginm;oeigj;lekmng gikjelkw giojnerokjgnrgroinlkrgnmrl;kgtnmltrk <form action="$php_self" method="POST"> <p class="bold">First Name<br> <input type="text" name="first_name" value="first_name" size="20" maxlength="25"></p> <p class="bold">Last Name<br> <input type="text" name="last_name" value="last_name" size="20" maxlength="25"></p> <p class="bold">Username<br> <input type="text" name="user_name" value="user_name" size="20" maxlength="25"></p> <p class="bold">Password<br> <input type="password" name="password1" value="1234567" size="20" maxlength="25"></p> <p class="left">Password(again)<br> <input type="password" name="password2" value="1234567" size="20" maxlength="25"></p> <p class="left">Email<br> <input type="text" name="email" value="we@email.ru" size="30" maxlength="50"></p> <p><input type="submit" name="submit" value="Mail confirmation"></p> </form> </td> </tr> </table> EOREGSTR; echo $reg_str; ?>[css][/css]
извеняюсь за то что код не форматирований!!! времени нет а строк много!!! ничего не помогает!!! пишу в консоле: mysql>SELECT id mysql>FROM user mysql>WHERE user_name = '$user_name'; работает переношу в скрипт не роботает!!!((( возвращает "" а должно 1; <?php $db = mysql_connect("localhost", "root","") or die("Error"); mysql_select_db("mydb",$db); $supersecret_hash_padding = 'A string that is used to pad out short string for md5 encryption.' ; $submit = $_POST['submit']; function user_register(){ global $supersecret_hash_padding; if (strlen($_POST['last_name'])<=25 && strlen($_POST['last_name'])>0 && strlen($_POST['first_name'])<=25 && strlen($_POST['first_name'])>0 && strlen($_POST['user_name'])<=25 && strlen($_POST['user_name'])>0 && strlen($_POST['password1'])>0 && strlen($_POST['password1'])<=25 && ($_POST['password1'])==($_POST['password2']) && strlen($_POST['email'])<=25 && strlen($_POST['email'])>0 && validate_email($_POST['email'])){ if (account_namevalid($_POST['user_name']) || strlen($_POST['password1'])>=6){ $user_name = strtolower($_POST['user_name']); $user_name = trim($user_name); $email = $_POST['email']; echo $guery = "SELECT 'id' FROM 'user' WHERE 'user_name' = '$user_name'"; echo "Здесь ошибка:".$result = mysql_query($query); if (($result)){ $feedback = 'ERROR - Username or email address laready exists'; return $feedback; } else { $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $password = $_POST['password1']; $hash = md5($email.$supersecret_hash_padding); $query = " INSERT INTO user (first_name, last_name, user_name, password, email, confirm_hash, is_confirmed, date_create) VALUES ('$first_name', '$last_name', '$user_name', '$password', '$email', '$hash', '1', NOW());"; $result = mysql_query($query); if (!$result){ mysql_close($db); $feedback = 'ERROR - Database error'; mysql_close($db); return $feedback; } else { $encoded_email = urlencode($_POST['email']); $mail_body = <<<EOMAILBODY Thank you for registering at Example.com. Clock this link to confirm your registration: http://localhost/confirm.php?hash=$hash ... oded_email Once you see a confirmation message, you will be logged into Example.com EOMAILBODY; mail ($email, 'Exaple.com Registration Confirmation', $mail_body, 'From noreply@example.com'); $feedback = '<a href="http://localhost/surreal/confirm.php?hash=$hash&email=$encoded_email">RR</a>!!Дякуємо за реєстрацію! <a href="index.html">На головну сторінку</a>'; return $feedback; } } } else { $feedback = 'ERROR - Username or password invalid '; return $feedback; } } else { $feedback = 'ERROR - Please fill in all fields correctly'; return $feedback; } } function account_namevalid(){ $span_str = "abcdefghijklmnopqrstuvwxyz"."ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"; if (strspn($_POST['user_name'],$span_str) == 0){ return false; } if (strspn($_POST['user_name'],$span_str) != strlen($name)){ return false; } if (strspn($_POST['user_name']) < 5){ return false; } if (strspn($_POST['user_name']) > 25){ return false; } if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)|(uucp)|(operator)|(games)|(mysql)| (httpd)|(nobody)|(dummy)|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))", $_POST['user_name'])){ return false; } if (eregi("^(anoncvs_)", $_POST['user_name'])) { return false; } return true; } function validate_email(){ return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $_POST['email'])); } function user_confirm (){ global $supersecret_hash_padding; $new_hash = md5($_GET['email'].$supersecret_hash_padding); if ($new_hash && ($new_hash == $_GET['hash'])){ $query = "SELECT user_name FROM user WHERE confirm_hash = '$new_hash'"; $result = mysql_query($query); if (!$result || mysql_num_rows($result)<1){ $feedback = 'ERROR - Hash not found'; return $feedback; } else { $email = $_GET['email']; $hash = $_GET['hash']; $query = "UPDATE user SET email='$email', is_confirmed = '1' WHERE confirm_hash = '$hash'"; $result = mysql_query($query); return 1; } } else { $feedback = 'ERROR - Values do not match'; return $feedback; } } if ($submit == 'Mail confirmation'){ $feedback = user_register(); $feedback_str = "<P class\"errormess\">$feedback</P>"; } else { $feedback_str = ''; } $php_self = $_SERVER['PHP_SELF']; $reg_str = <<<EOREGSTR <TABLE CELLPADDING=0 CELLPACING=0 BORDER=0 ALIGN=CENTER WIDTH=621> <TR> <TD ROWSPAN=10><IMG WIDTH=15 HEIGHT=1 SRC=""></TD> <TD WIDTH=606></TD> </TR> <tr> <td> $feedback_str <p class="left"><b>REGISTER</b></p> kjh;lkernqg;oerkn;lkwqmng;lekwnmg;lewkng;lewkrng;oiewn eogiw poginmoirmn ;lgkmwg e gne;wginm;oeigj;lekmng gikjelkw giojnerokjgnrgroinlkrgnmrl;kgtnmltrk <form action="$php_self" method="POST"> <p class="bold">First Name<br> <input type="text" name="first_name" value="first_name" size="20" maxlength="25"></p> <p class="bold">Last Name<br> <input type="text" name="last_name" value="last_name" size="20" maxlength="25"></p> <p class="bold">Username<br> <input type="text" name="user_name" value="user_name" size="20" maxlength="25"></p> <p class="bold">Password<br> <input type="password" name="password1" value="1234567" size="20" maxlength="25"></p> <p class="left">Password(again)<br> <input type="password" name="password2" value="1234567" size="20" maxlength="25"></p> <p class="left">Email<br> <input type="text" name="email" value="we@email.ru" size="30" maxlength="50"></p> <p><input type="submit" name="submit" value="Mail confirmation"></p> </form> </td> </tr> </table> EOREGSTR; echo $reg_str; ?>[css][/css]
1. Kreker уже указал на ошибку... 2. PHP: echo $query = "SELECT 'id' FROM 'user' WHERE 'user_name' = '$user_name'"; echo "G:".$result = mysql_query($query); if (($result)){ $feedback = 'ERROR - Username or email address laready exists'; return $feedback; } else { ... $query = " INSERT INTO user (first_name, last_name, user_name, password, email, confirm_hash, is_confirmed, date_create) VALUES ('$first_name', '$last_name', '$user_name', '$password', '$email', '$hash', '1', NOW());"; Не могу понять логики этого фрагмента... По вашему получается, что добавляем нового пользователя, если запрос PHP: $query = "SELECT `id` FROM `user` WHERE `user_name` = '$user_name'"; выполнен успешно ВНЕ ЗАВИСИМОСТИ ОТ РЕЗУЛЬТАТА...
Так замените же наконец Код (Text): $guery на Код (Text): $query И прочитайте моё предыдущее сообщение!!!!
Большое спасиба! уже все исправил!!! Вот я лол! Еще вопрос!! Ктото работает с денвером! я хочу роботать с include а он мне говорит что надо дерикторию PEAR где ее создать!??