בקשה קטנה

lior066

New member
בקשה קטנה

שלום , יש לי בקשה די קטנה , אני לא מבין כמעט כלום ב php אני יודע קצת vb אני בניתי תוכנה קטנה שפועלת ב vb אני צריך קוד כלשהו ב php כדי שיעזור לי להשלים אותה. אני צריך שיהיה לי מין דף כלשהו שבכותרת אני מכניס ככה נגיד http://www.mysite.com/phpcode.php?Cdod1="code1"?code2=Code2?code3="code3" ומתי שזה יפתח אז זה יוסיף לדף html בתוך טבלה כזאת את הדברים ככה נגיד code1: code1 code2: code2 code3: code3 וזה בלי להיכנס לתוך הדף ולשמור בתוך שדות זה מאוד ישפר את התוכנה שלי. נ.ב אני צריך שזה ישאר על הhtml כיאילו קבוע שכל פעם זה יוסיף לשם את הנתונים בחדש כמו פורום כזה. תודה רבה לכל מי שעושה לי את זה.
 

N i X

New member
כמה שאלות לי אלייך...

איפה בידיוק זה אמור לשמור את זה? הנה קובץ שרק ידפיס את זה בתוך טבלה:
<?php if (isset($code1) && isset($code2) && isset($code3) && isset($code4)) { print("Code1: $code1") print("Code2: $code2") print("Code3: $code3") print("Code4: $code4") } else die("Missing parameter"); ?>​
 

N i X

New member
תיקון קל...

אמרתי בטבלה, וזה לא בטבלה, זה סתם מדפיס, בכל מקרה, הנה משהו שיעבוד טיפה יותר טוב:
<?php if (isset($code1) && isset($code2) && isset($code3) && isset$code4)) { print("Code1: $code1<br>\n"); print("Code2: $code2<br>\n"); print("Code3: $code3<br>\n"); print("Code4: $code4<br>\n"); } else die("Missing parameter"); ?>​
 

lior066

New member
תשובה לשאלתך

זה אמור להוסיך את התכוכן לתוך דף אינטרנט ולשמור אותו שם בתוך הדף כיאילו שישאר בקוד של הדף אינטרנט כמו append לדף שישמר עם התוספת של הקוד הזה
 

lior066

New member
לא עובד לי הקוד

אתה יכול לרשום לי פה פקודת הרצה
 

lior066

New member
לא הבנתי אותך - מישהו?

הקוד הזה בודק אם יש בתוך הcode רך כלשהוא אבל אני רוצה תוכנית ששמה ערך בפנים? אם זה מה שזה בכלל לא הבנתי אותה ( כמו שאמרתי אין לי רקע ב php( אפשר לדעת איך להפעיל את התוכנית?
 

idansof

New member
לphp יש מדריך די מקיף

לגבי מבנה השפה והפונקציות הזמינות. הקוד שהביא ניקס מיישם את הקונצפט הדרוש, וכעת כל מה שנותר הוא לערוך כמה שינויים, לא דרסטיים למען האמת. ע"ע fopen ו fwrite
 

lior066

New member
בעיה קטנטונת

אני לא יודע איך להריץ את הקוד שהוא שלח לי כלומר לקרוא לו מהכותרת של הדף אינטרנט אחרי זה נראה לי שאני יסתדר רק אם תוכלו לשלוח לי פה איך להפיל אותה וזהו
 

N i X

New member
אני נוסע עכשיו ליום

אני יחזור מחר, ואני מבטיח לכתוב לך את הקוד המלא כמו שרצית כשאחזור. לגבי הקוד שהבאתי, שים אותו בתוך קובץ phpcode.php, תעלה לשרת ואז תגש עליו כמו שתארת בהודעה הראשונה.
 

N i X

New member
הנה הסקריפט...

<?php if (isset($code1) && isset($code2) && isset($code3) && isset($code4)) { print("Code1: $code1 "); print("Code2: $code2 "); print("Code3: $code3 "); print("Code4: $code4<br>\n"); $filename = 'my.txt'; $somecontent = $code1 . " " $code2 . " " $code3 . " " $code4 . "\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { print "Cannot open file ($filename)<br>\n"; exit; } // Write $somecontent to our opened file. if (!fwrite($handle, $somecontent)) { print "Cannot write to file ($filename)<br>\n"; exit; } print "Success, wrote ($somecontent) to file ($filename)<br>\n"; fclose($handle); } else { print "The file $filename is not writable<br>\n"; } } else die("Missing parameter<br>\n"); ?> Old codes in DB:<br> <?php if ($db = file($filename)) { for ($i = 0; $i <= (count($db)-1); $i++) print("$i>> $db[$i]<br>\n"); } else print("Failed to read db!<br>\n"); ?>​
הערה: הקוד לא נבדק. כך אתה אמור לגשת לסקריפט:
http://www.somedomain.com/somedir/somescript.php?code1=423534&code2=235345&code3=FFFx000&code4=bleh​
 

lior066

New member
בעיה

Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\Apache Group\Apache2\htdocs\Php1\1.php on line 11
 

N i X

New member
שכחתי נקודה בשורה 11...

מתוקן:
<?php if (isset($code1) && isset($code2) && isset($code3) && isset($code4)) { print("Code1: $code1 "); print("Code2: $code2 "); print("Code3: $code3 "); print("Code4: $code4<br>\n"); $filename = 'my.txt'; $somecontent = $code1 . " " $code2 . " " $code3 . " " . $code4 . "\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { print "Cannot open file ($filename)<br>\n"; exit; } // Write $somecontent to our opened file. if (!fwrite($handle, $somecontent)) { print "Cannot write to file ($filename)<br>\n"; exit; } print "Success, wrote ($somecontent) to file ($filename)<br>\n"; fclose($handle); } else { print "The file $filename is not writable<br>\n"; } } else die("Missing parameter<br>\n"); ?> Old codes in DB:<br> <?php if ($db = file($filename)) { for ($i = 0; $i <= (count($db)-1); $i++) print("$i>> $db[$i]<br>\n"); } else print("Failed to read db!<br>\n"); ?>​
 

N i X

New member
אופס...

הנה, הגרסה הסופית, המתוקנת, והבדוקה...
<?php $filename = 'my.txt'; // DB filename if (isset($code1) && isset($code2) && isset($code3) && isset($code4)) { print("Code1: $code1 "); print("Code2: $code2 "); print("Code3: $code3 "); print("Code4: $code4<br><br>\n"); $somecontent = $code1 . " " . $code2 . " " . $code3 . " " . $code4 . "\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { print "Error: Cannot open file ($filename)<br>\n"; exit; } // Write $somecontent to our opened file. if (!fwrite($handle, $somecontent)) { print "Error: Cannot write to file ($filename)<br>\n"; exit; } print "Success, wrote ($somecontent) to file ($filename)<br>\n"; fclose($handle); } else { print "Error: The file $filename is not writable<br>\n"; } } else print("Error: Missing parameter, no change to db ($filename)<br>\n"); ?> <br> Old codes in DB:<br><br> <?php if ($db = file($filename)) { for ($i = 0; $i <= (count($db)-1); $i++) print("[" . ($i+1) . "] $db[$i]<br>\n"); } else print("Error: Failed to read db ($filename)!<br>\n"); ?>​
אפשר לראות את זה פועל כאן:
 

orenphp

New member
בקשר לif -> exit שלך.

זוהי שיטה מאוד לא טובה ומאוד לא מומלצת (מבחינת יעילות וכמובן הבנת הקוד לעיניים זרות). תשתמש בif->else
 

N i X

New member
אם תשים לב,

הקוד לא שלי, אלה מהדוגמא מהאתר של PHP.
 

orenphp

New member
זה לא תירוץ מספיק טוב... ../images/Emo3.gif

כנראה שהם פשוט רצו להראות עקרונות לעבודה עם הדברים ולא הקפידו על הסנטקס ומשמעותו. בכל אופן, מאוד לא מומלץ לעבוד עם EXIT בIF במקום להשתמש בIF->ELSE (מהסיבות שכתבתי מקודם)
 

N i X

New member
אני לא אומר שהם צודקים

אני רק אומר שלקחתי את זה מהם כדאי לקצר את זמן כתיבת הסריפט למינימום, ובכל מקרא, כל הסקריפט הוא פשוט מאוד אז, זה לא ממש משנה ;)
 

lior066

New member
שגיאה

Error: Missing parameter, no change to db (my.txt) Old codes in DB: Error: Failed to read db (my.txt)! מצטער שלא היתי הרבה זמן היתי באילת
 

orenphp

New member
לפי השגיאות שעולות פה

בקשר ל"שגיאה"(אני מתייחס אל זה ככה, כי המתכנת מודיע לעצמו בצורה כזו שיש פה טעות בקוד - למרות שזו הודעה רגילה לכל דבר) הראשונה, לדעתי לא העלת את העמוד כמו שNIX כתב לך(עם המשתנים שצריך לשרשר): yourPage.php?code1=FFFxbla&code2=Forum312&code3=PHP_ownz&code4=blaFFF מאחר והקוד:
if (isset($code1) && isset($code2) && isset($code3) && isset($code4))​
מחזיר false משום מה אז הוא כותב לך את השגיאה:
Error: Missing parameter, no change to db (my.txt) --- in the code --- else print("Error: Missing parameter, no change to db ($filename)<br>\n");​
בקשר ל"שגיאה" השנייה, מאחר והוא לא נכנס אף פעם לתנאי הראשון (בדיקת הפרמטרים) הוא לא יצר אף פעם את הקובץ ולכן בתנאי השני הוא אף פעם לא יצליח למצוא את הקובץ (ועל זה ההודעה שהוא לא מוצא את הקובץ). בעיקרון יש לך פה הודעות שגיאה שעוזרות לך להבין מה קורה, תתייחס אליהם (תדבג קצת לבד ותתעמק בקוד, NIX הביא לך דוגמא על מנת שתקרא אותה ותבין ממנה את העקרונות ולא שישר הכל יעבוד בצורה חלקה אבל את העיקרון אתה לא תבין) - מקווה שלא נפגעת ולקחת את דבריי בצורה שהייתי רוצה שתיקח - כביקורת בונה. בהצלחה.
 

lior066

New member
פי שמתם לב בהודעה הראשונה שלי

אני לא מבין כלום ב php רק בסיסי אני יכול להבין אם הקוד כתוב בעצמו אני לא יודע פקודות של php אני יודע רק vb
 
למעלה