Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][MySQL] function.mysql-result - błąd
Forum PHP.pl > Forum > Przedszkole
kacpereczek
Witam, mam problem z moim kodem i nie wiem co jest źle.

To jest błąd:

  1. Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in subscribe.php on line 54


Kod:

  1. if($mail == NULL){
  2.  
  3. }
  4. else{
  5. $token = sha1(time());
  6. $result1 = @mysql_query("INSERT INTO newsletter (Address,Token) VALUES (\"".$mail."\", \"".$token."\") ");
  7. if ($result1) {
  8. sendmail($mail);
  9. }
  10. else{ /*This else */
  11. $result2 = mysql_query("SELECT Confirmed FROM newsletter where Address = \"".$mail."\" ");
  12. $confirm = mysql_result($result2,0); /* tu jest błąd */
  13. if($confirm == "y"){
  14. }
  15. else if($confirm == "n"){
  16. }
  17. }
  18. }
  19. ?>


Proszę o pomoc
kartin
Pewnie zapytanie zwraca 0 wierszy.
  1. SELECT Confirmed FROM newsletter WHERE Address = ...
kacpereczek
To jest cały kod:

  1. <?
  2. include "config.php";
  3. require_once ('../header.php');
  4. ?>
  5.  
  6. <!-- thank-you -->
  7. <section id="media" class="content-section text-center">
  8. <div class="media-pg">
  9. <div class="container">
  10. <div class="row">
  11. <div class="col-md-12">
  12. <h2>Newsletter</h2>
  13. <?
  14. function sendmail($mail) {
  15. $res = mysql_query("SELECT Token FROM newsletter where address = \"".$mail."\" ");
  16. $token = mysql_result($res,0);
  17.  
  18. $message='<p>Welcome to domain.com newsletter system. To confirm your e-mail, click the link below:<br />
  19. <a href="http://annoncube.com/newsletter/confirm.php?address='.$mail.'&token='.$token.'">http://domain.com/newsletter/confirm.php?address='.$mail.'&token='.$token.'</a><br /><br />
  20. If you do not want to join this newsletter, ignore this message.<br /><br />
  21. Please do not reply to this message was generated automatically</p>';
  22. $subject = 'Newsletter - Domain.com';
  23. $headers = 'MIME-Version: 1.0' . "\r\n";
  24. $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
  25. $headers .= 'From:' . "noreply@domain.com\r\n";
  26. mail($mail,$subject,$message,$headers);
  27.  
  28. }
  29. $mail=$_POST['newsletter'];
  30.  
  31. if($mail == NULL){
  32. ?>
  33. <p style="padding-bottom:250px;">
  34. Not entered an email address!
  35. </p>
  36. <?
  37. }
  38. else{
  39.  
  40. $token = sha1(time());
  41. $result1 = @mysql_query("INSERT INTO newsletter (Address,Token) VALUES (\"".$mail."\", \"".$token."\") ");
  42.  
  43. if ($result1) {
  44. ?>
  45. <p style="padding-bottom:250px;">
  46. Thank you for your subscribe!
  47. </p>
  48. <?
  49. sendmail($mail);
  50. }
  51. else{
  52. $result2 = mysql_query("SELECT Confirmed FROM newsletter where Address = \"".$mail."\" ");
  53. $confirm = mysql_result($result2,0);
  54. if($confirm == "y"){
  55. ?>
  56. <p style="padding-bottom:250px;">
  57. E-mail address already exists in the database and is confirmed
  58. </p>
  59. <?
  60. }
  61. else if($confirm == "n"){
  62. ?>
  63. <p style="padding-bottom:250px;">
  64. E-mail address already exists in the database but isn't confirmed
  65. </p>
  66. <?
  67. }
  68. }
  69. }
  70. ?>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </section>
  76.  
  77. <?
  78. require_once ('../footer.php');
  79. ?>


MySQL:
  1. CREATE TABLE `newsletter` (
  2. `ID` smallint(5) UNSIGNED NOT NULL,
  3. `Address` varchar(200) NOT NULL,
  4. `Confirmed` enum('y','n') NOT NULL DEFAULT 'n',
  5. `Token` varchar(40) NOT NULL,
  6. PRIMARY KEY (`ID`),
  7. UNIQUE KEY `Address` (`Address`)
  8. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Dodam, że kod działa tylko dla pierwszego użytkownika, Później wywala błąd sad.gif
nospor
Napisano ci: zapytanie nie zwraca rekordu a co za tym idzie nie moze wskoczyc do rekordu ktory mu zadajesz. Pewnie nie ma takiego adresu email w bazie lub masz z bledem napisany. Sprawdz.
kacpereczek
Wpisując adres, który mam w bazie, ale jest niepotwierdzony (Confirmed=n) wyświetla poprawny komunkiat, czyli "E-mail address already exists in the database but isn't confirmed".
Jeśli wpiszę adres który jest potwierdzony, (Confirmed=y) też wyświetla poprawny komunikat.

Błąd występuje tylko, gdy chcę dodać zupełnie nowy adres, którego nie mam w bazie, nie jest ani potwierdzony, ani niepotwierdzony.
nospor
Raz uzywasz kolumny Address a raz address ....

Zapoznaj sie z tym tematem
Temat: Jak poprawnie zada pytanie
i zastosuj do podanych tam porad by nie latac z takimi literowkami po forum :/

przenosze
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.