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

הוסטס - פורום אחסון האתרים הגדול בישראל (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=51115)

Ron | CSite.co.il 01-08-07 12:28

שאלה ב php
 
שלום לכולם,
יש לי את הקוד הבא:

PHP קוד:

 <?php

            $errors 
= array();

            if(isset(
$_REQUEST["seen_already"])){

                
validate_data();
                if(
count($errors) != 0){
                    
display_errors();
                    
display_welcome();
                } 
                else {
                    
process_data();
                }
            } 
            else {
                
display_welcome();
            }

            function 
validate_data()
            {
                global 
$errors;
                if(
$_REQUEST["Name"] == "") {
                    
$errors[] = "<FONT COLOR='RED'>Please enter your name</FONT>";
                }

                if(
strcmp($_REQUEST["Number"], strval(intval($_REQUEST["Number"])))) {
                    
$errors[] = "<FONT COLOR='RED'>Please enter an integer</FONT>";
                }
            }

            function 
display_errors()
            {
                global 
$errors;

                foreach (
$errors as $err){
                    echo 
$err"<BR>";
                }

                foreach (
$errors as $err){
                    echo 
$err"<BR>";
            }

            function 
process_data()
            {
                echo 
"Your name is ";
               
                
$ok_text htmlentities ($_REQUEST["Name"]);
                echo 
$ok_text;

                echo 
"Your integer is ";
                echo 
$_REQUEST["Number"];
            }

            function 
display_welcome()
            {
                echo 
"<FORM METHOD='POST' ACTION='index.php'>";
                echo 
"What's your name?";
                echo 
"<BR>";
                echo 
"<INPUT NAME='Name' TYPE='TEXT'>";
                echo 
"<BR>";
                echo 
"<BR>";
                echo 
"<INPUT TYPE=SUBMIT VALUE=Submit>";
                echo 
"<INPUT TYPE=HIDDEN NAME='seen_already' VALUE='hidden_data'>";
                echo 
"</FORM>";
          
             echo 
"<FORM METHOD='POST' ACTION='index.php'>";
                echo 
"Please enter an integer.";
                echo 
"<BR>";
                echo 
"<INPUT NAME='Number' TYPE='TEXT'>";
                echo 
"<BR>";
                echo 
"<BR>";
                echo 
"<INPUT TYPE=SUBMIT VALUE=Submit>";
                echo 
"<INPUT TYPE=HIDDEN NAME='seen_already' VALUE='hidden_data'>";
                echo 
"</FORM>";


      }
        
?>


שאני מריץ את זה זה כותב לי את השגיאה הבאה:
PHP קוד:

Parse errorparse error in c:program fileseasyphp1-8wwwregistarindex.php on line 79 

איך מתקנים את זה?

תודה מראש:).

Daniel 01-08-07 14:58

הבעייה היא כי שכחת }
באמת, אני לא רוצה להעליב, אבל כדאי לך לעדכן את הידע שלך ב-HTML.
בכ"מ, תיקנתי לך את הכל.
PHP קוד:

<?php
$to_print 
null;
$errors = array();
if (isset(
$_REQUEST["seen_already"])) {
    
validate_data();
    if (
count($errors) != 0) {
        
display_errors();
        
display_welcome();
    } else {
        
process_data();
    }
} else {
    
display_welcome();
}

function 
validate_data()
{
    global 
$errors;
    if (
$_REQUEST["Name"] == "") {
        
$errors[] = "<span style='color:red;'>Please enter your name</span>";
    }

    if (
strcmp($_REQUEST["Number"], strval(intval($_REQUEST["Number"])))) {
        
$errors[] = "<span style='color:red;'>Please enter an integer</span>";
    }
}

function 
display_errors()
{
    global 
$errors;

    foreach (
$errors as $err) {
        
$to_print.= $err"<br />";
    }

    foreach (
$errors as $err) {
        
$to_print.= $err"<br />";
    }
}
    function 
process_data()
    {
        global 
$to_print;
        
$to_print.= "Your name is ";

        
$ok_text htmlentities ($_REQUEST["Name"]);
        
$to_print.= $ok_text;

        
$to_print.= "Your integer is ";
        
$to_print.= $_REQUEST["Number"];
    }

    function 
display_welcome()
    {
        global 
$to_print;
        
$to_print.= <<<EOF
        <form method='POST' action='index.php'>
        What's your name?
        <br />
        <input type="text" name='Name'>
        <br />
        <br />
        <input type="submit" VALUE="Submit">
        <input type="hidden" name='seen_already' value='hidden_data'>
        </form>

        <form method='POST' action='index.php'>
        Please enter an integer.
        <br />
        <input type="text" name='Number'>
        <br />
        <br />
        <input type="hidden" name='seen_already' value='hidden_data'>
        <input type="submit" VALUE="Submit">
        </FORM>
EOF;
    }
echo 
$to_print;
    
?>


Ron | CSite.co.il 01-08-07 15:15

תודה אחי,ובכל מקרה אין מה להעליב,זה פשוט עניין של תקניות מה שכתבתי היה נכון.(ב html).

אממ זה הסתדר הכל עובד אבל עדיין מציג לי שגיאה למעלה:
Notice: Undefined variable: to_print in c:\program files\easyphp1-8\www\registar\index.php on line 33

Daniel 01-08-07 15:47

תוקן.
ותקינות וכל הדברים האלה זה דבר מאוד חשוב.
PHP קוד:

<?php
$to_print 
null;
$errors = array();
if (isset(
$_REQUEST["seen_already"])) {
    
validate_data();
    if (
count($errors) != 0) {
        
display_errors();
        
display_welcome();
    } else {
        
process_data();
    }
} else {
    
display_welcome();
}

function 
validate_data()
{
    global 
$errors$to_print;
    if (
$_REQUEST["Name"] == "") {
        
$errors[] = "<span style='color:red;'>Please enter your name</span>";
    }

    if (
strcmp($_REQUEST["Number"], strval(intval($_REQUEST["Number"])))) {
        
$errors[] = "<span style='color:red;'>Please enter an integer</span>";
    }
}

function 
display_errors()
{
    global 
$errors$to_print;

    foreach (
$errors as $err) {
        
$to_print.= $err"<br />";
    }

    foreach (
$errors as $err) {
        
$to_print.= $err"<br />";
    }
}
    function 
process_data()
    {
        global 
$to_print;
        
$to_print.= "Your name is ";

        
$ok_text htmlentities ($_REQUEST["Name"]);
        
$to_print.= $ok_text;

        
$to_print.= "Your integer is ";
        
$to_print.= $_REQUEST["Number"];
    }

    function 
display_welcome()
    {
        global 
$to_print;
        
$to_print.= <<<EOF
        <form method='POST' action='index.php'>
        What's your name?
        <br />
        <input type="text" name='Name'>
        <br />
        <br />
        <input type="submit" VALUE="Submit">
        <input type="hidden" name='seen_already' value='hidden_data'>
        </form>

        <form method='POST' action='index.php'>
        Please enter an integer.
        <br />
        <input type="text" name='Number'>
        <br />
        <br />
        <input type="hidden" name='seen_already' value='hidden_data'>
        <input type="submit" VALUE="Submit">
        </FORM>
EOF;
    }
echo 
$to_print;
    
?>


hod206 01-08-07 15:57

ציטוט:

נכתב במקור על ידי MasterT (פרסם 533842)
תוקן.
ותקינות וכל הדברים האלה זה דבר מאוד חשוב.

תקינות קוד זה לא כזה דבר חשוב, אתר יכול להראות מעולה בכל הדפדפנים גם בלי שהוא תקין (ע"ע google).

Ron | CSite.co.il 01-08-07 15:58

תודה רבה .אפשר לנעול.


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

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