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

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

pcnet 27-04-17 17:56

אני מנסה להזין נתונים למסד
 
אבל זה מזין לי בשדה string את המילה .php ולא משנה מה אני מזין בשדה q לא נקלט

אני יציין שאם אני משנה את ה method ל post אז הנתונים נקלטים

אבל אני חייב להשתמש ב get

הנה הקוד

PHP קוד:

            if(trim($_GET['q'])) {
    
$chstring trim($_GET['q']);
    
$chstring urldecode($chstring);
    
$chstring str_replace(array("%"",""'"'"''>''<''/'), ''$chstring);
    
$chstring substr($chstring080); // limit search phrase
    
$chstring htmlspecialchars($chstringENT_NOQUOTES);
    
                
$sql "SELECT COUNT(*) as total 
                        FROM pm_ches 
                        WHERE string = '"
$chstring ."'";
                
$result = @mysql_query($sql);
                
$row = @mysql_fetch_assoc($result);
                @
mysql_free_result($sql_string_check);
                
                    
$chstring trim($_GET['q']);

                if (
$row['total'] > 0)
                {
                    @
mysql_query("UPDATE pm_ches SET hits=hits+1 WHERE string = '".$chstring."'");
                }
                else
                {
                    @
mysql_query("INSERT INTO pm_ches SET string = '".$chstring."', hits = '1'");
                }
            } 


pcnet 27-04-17 21:25

ציטוט:

נכתב במקור על ידי pcnet (פרסם 901984)
אבל זה מזין לי בשדה string את המילה .php ולא משנה מה אני מזין בשדה q לא נקלט

אני יציין שאם אני משנה את ה method ל post אז הנתונים נקלטים

אבל אני חייב להשתמש ב get

הנה הקוד

PHP קוד:

            if(trim($_GET['q'])) {
    
$chstring trim($_GET['q']);
    
$chstring urldecode($chstring);
    
$chstring str_replace(array("%"",""'"'"''>''<''/'), ''$chstring);
    
$chstring substr($chstring080); // limit search phrase
    
$chstring htmlspecialchars($chstringENT_NOQUOTES);
    
                
$sql "SELECT COUNT(*) as total 
                        FROM pm_ches 
                        WHERE string = '"
$chstring ."'";
                
$result = @mysql_query($sql);
                
$row = @mysql_fetch_assoc($result);
                @
mysql_free_result($sql_string_check);
                
                    
$chstring trim($_GET['q']);

                if (
$row['total'] > 0)
                {
                    @
mysql_query("UPDATE pm_ches SET hits=hits+1 WHERE string = '".$chstring."'");
                }
                else
                {
                    @
mysql_query("INSERT INTO pm_ches SET string = '".$chstring."', hits = '1'");
                }
            } 


הסתדרתי

leadplus 18-05-17 15:28

מציע לך להשתמש ב-PDO או יותר טוב להשתמש באיזה CLASS רלוונטי לניהול DB.

123AIE 21-05-17 10:03

תחשוב שוב
 
לא שאלה שהייתי שם בראיון עבודה לחברת הייטק או דרך חברת השמה הייטק אבל בכל זאת תחפש מה ה- best practice במקרה הזה.. איך פתרת את זה?


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

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