הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   PHP | איך אני עושה בדיקה אם יש ערך מסויים במסד? (https://hosts.co.il/forums/showthread.php?t=59628)

0xfo7d 03-02-08 13:58

PHP | איך אני עושה בדיקה אם יש ערך מסויים במסד?
 
שלום.
אני בונה רשימת תפוצה ב PHP.
אני מעוניין לעשות דבר כזה...אם משתמש מנסה להוסיף כתובת דוא"ל...שתהיה בדיקה אם הדוא"ל כבר קיים במערכת....אם כן...שיוציא הודעה "כתובת זו כבר קיימת במערכת", אם לא...שיוסיף למסד..
זה הקטע קוד הרלוונטי:

PHP קוד:

       mysql_query("INSERT INTO `emails` SET
        `email_address`='"
.$_POST["email_address"]."'
        "
);
       echo 
mysql_error();
       if(
mysql_affected_rows() > 0) {
          echo 
"<font color='red'>האימייל נוסף בהצלחה</font>";
          echo 
"<META HTTP-EQUIV=Refresh CONTENT='1; URL=?action=mail_manager&sa=edit'>";
       } else {
          echo 
"<font color='red'>שגיאה בעת תהליך הוספת האימייל</font>";
       } 

מישהו יכול לעזור לי עם זה?

תודה רבה,
מתן.

Shon12 03-02-08 14:21

נסה את זה:
HTML קוד:

$result = mysql_query("INSERT INTO `emails` (email_address) VALUES ($_POST['email_address'])") or die(mysql_error());
$search = mysql_num_rows($result);
        if ($search == 0)
        {
        echo("<font color=\"red\">האימייל נוסף בהצלחה</font>");
        }
        else {
        echo("<font color=\"red\">אנא בחר אימייל אחר</font>");
        }


0xfo7d 03-02-08 14:55

זה אומר שיש שגיאה בשורה הזו:
PHP קוד:

$result mysql_query("INSERT INTO `emails` (email_address) VALUES ($_POST['email_address'])") or die(mysql_error()); 

זה אומר את זה ברגע שנכנסים לדף...לא כאשר אני מנסה להוסיף.


זו השגיאה:
קוד:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/ventilated/domains/viewp.net/public_html/mysite/admin/admin_mailing.inc.php on line 130

Shon12 03-02-08 15:24

נסה את זה:
HTML קוד:

$email = $_POST['email_address'];

$result = mysql_query("INSERT INTO `emails` (email_address) VALUES ('$email')") or die(mysql_error());
$search = mysql_num_rows($result);
        if ($search == 0)
        {
        echo("<font color=\"red\">האימייל נוסף בהצלחה</font>");
        }
        else {
        echo("<font color=\"red\">אנא בחר אימייל אחר</font>");
        }


WaReZ 03-02-08 15:31

קוד:

$result = mysql_query("INSERT INTO `emails` (`email_address`) VALUES ('".$_POST['email_address']."')") or die(mysql_error());

0xfo7d 03-02-08 15:36

א. זה מוציא שגיאה:

קוד:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ventilated/domains/viewp.net/public_html/mysite/admin/admin_mailing.inc.php on line 133
ב.זה מוסיף את המייל למסד(מייל שכבר קיים).


שורה 133:
PHP קוד:

$search mysql_num_rows($result); 


-roee- 03-02-08 15:38

mysql_num_rows אפשר לעשות רק לשאילתת SELECT
כמו כן, שים לב שאתה קודם שם את האימייל שאתה בודק במסד ורק אז בודק אם הוא קיים - אז בטוח שהוא יהיה קיים.

Ron | CSite.co.il 03-02-08 15:40

PHP קוד:

$email $_POST['email_address'];

$result mysql_query("SELECT * FROM `emails` WHERE `email_address`= '$email')") or die(mysql_error());
$search mysql_num_rows($result);
    if (
$search == 0)
    {
        
mysql_query("INSERT INTO `emails` (`email_address`) VALUES ('$email')") or die(mysql_error());
    echo(
"<font color=\"red\">האימייל נוסף בהצלחה</font>");
    }
    else {
    echo(
"<font color=\"red\">אנא בחר אימייל אחר</font>");
    } 

יש מצב קטן שיש טעויות קטנות אבל לא נראה לי ,כי אני חייב ללכת ועשיתי את זה מהר.
תהנה.

0xfo7d 03-02-08 15:41

ציטוט:

נכתב במקור על ידי roeenoy (פרסם 605901)
mysql_num_rows אפשר לעשות רק לשאילתת SELECT
כמו כן, שים לב שאתה קודם שם את האימייל שאתה בודק במסד ורק אז בודק אם הוא קיים - אז בטוח שהוא יהיה קיים.

תוכל לנסות לעזור לי לשלב את זה נכון בקוד???

וברור שקודם הוספתי את המייל ולאחר מכן ניסיתי שוב...

0xfo7d 03-02-08 15:44

ציטוט:

נכתב במקור על ידי Ron-Pro (פרסם 605902)
PHP קוד:

$email $_POST['email_address'];

$result mysql_query("SELECT * FROM `emails` WHERE `email_address`= '$email')") or die(mysql_error());
$search mysql_num_rows($result);
    if (
$search == 0)
    {
        
mysql_query("INSERT INTO `emails` (`email_address`) VALUES ('$email')") or die(mysql_error());
    echo(
"<font color=\"red\">האימייל נוסף בהצלחה</font>");
    }
    else {
    echo(
"<font color=\"red\">אנא בחר אימייל אחר</font>");
    } 

יש מצב קטן שיש טעויות קטנות אבל לא נראה לי ,כי אני חייב ללכת ועשיתי את זה מהר.
תהנה.




You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1


כל הזמנים הם GMT +2. הזמן כעת הוא 14:25.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ