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

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

forils 22-11-06 17:29

מה לא בסדר בקוד הזה ?!
 
<php>
<?php

mysql_connect('localhost','user','password');
mysql_select_db('news'); // החלף את השם של בסיס הנתונים בשם שאתה קבעת
$result = mysql_query("SELECT * FROM 'news' ORDER BY 'id' DESC");

// הצגת הכתבות
while ($row=mysql_fetch_array($result))
{
echo ("<table width="600" cellpadding="2" cellspacing="2 border=1"> ");
echo ("<tr> ");
echo ("<td bgcolor="gray" width="100%">" . $x['subject'] . "</td> ");
echo ("</tr> ");
echo ("<td bgcolor="white" width="100%">" . $x['content'] . "</td> ");
echo ("</tr> ");
echo ("</table> ");
echo ("<br>");
}

?>
</php>
הוא מכאן
http://www.webmaster.org.il/article.asp?id=193
כל הדפים של המערכת הזאת לא היו טובים וסידרתי הגעתי למצב שאני מצליח להזריק נתונים למסד ועכשיו איך אני מדפיס נתונים מהמסד למשהו יש איזה רעיון ?

-VladK- 22-11-06 17:37

אההההם לא ציינתה שם משתמש וסיסמא נכונים (ככה אני חושב...) בשורה:
mysql_connect('localhost','user','password');

אהההם וגם תיקנתי לך כמה דברים...

PHP קוד:

<?php

mysql_connect
('localhost','user','password');
mysql_select_db('news'); // החלף את השם של בסיס הנתונים בשם שאתה קבעת
$result mysql_query("SELECT * FROM 'news' ORDER BY 'id' DESC");

// הצגת הכתבות
while ($row=mysql_fetch_array($result))
{
echo (
"<table width="600" cellpadding="2" cellspacing="2 border=1"> ");
echo (
"<tr> ");
echo (
"<td bgcolor="gray" width="100%">" $row['subject'] . "</td> ");
echo (
"</tr> ");
echo (
"<td bgcolor="white" width="100%">" $row['content'] . "</td> ");
echo (
"</tr> ");
echo (
"</table> ");
echo (
"<br>");
}

?>


forils 22-11-06 19:13

מראה את השגיאה הזאת לאחר שהכנסתי את נתוני המסד :
Parse error: syntax error, unexpected T_LNUMBER in /usr/home/matrixip/domains/dicw.net/public_html/1/index.php on line 10

(זאת השורה :
PHP קוד:

echo ("<table width="600" cellpadding="2" cellspacing="2 border=1"> "); 

בדף :
PHP קוד:

<?php

mysql_connect
('localhost','dos_m4','111111');
mysql_select_db('news'); // החלף את השם של בסיס הנתונים בשם שאתה קבעת
$result mysql_query("SELECT * FROM 'news' ORDER BY 'id' DESC");

// הצגת הכתבות
while ($row=mysql_fetch_array($result))
{
echo (
"<table width="600" cellpadding="2" cellspacing="2 border=1"> ");
echo (
"<tr> ");
echo (
"<td bgcolor="gray" width="100%">" $row['subject'] . "</td> ");
echo (
"</tr> ");
echo (
"<td bgcolor="white" width="100%">" $row['content'] . "</td> ");
echo (
"</tr> ");
echo (
"</table> ");
echo (
"<br>");
}

?>


Elad-A 22-11-06 19:17

אם כבר אז משהו כזה:

PHP קוד:


<?php 

mysql_connect
('localhost','dos_m4','111111'); 
mysql_select_db('news'); // החלף את השם של בסיס הנתונים בשם שאתה קבעת 
$result mysql_query("SELECT * FROM 'news' ORDER BY 'id' DESC"); 

// הצגת הכתבות 
while ($row=mysql_fetch_array($result)) 

echo 
"<table width=\"600\" cellpadding=\"2\" cellspacing=\"2\" border=\"1\"> "
echo 
"<tr> "
echo 
"<td bgcolor=\"gray\" width=\"100%\">" $row['subject'] . "</td> "
echo 
"</tr> "
echo 
"<td bgcolor=\"white\" width=\"100%\">" $row['content'] . "</td> "
echo 
"</tr> "
echo 
"</table> "
echo 
"<br>"


?>

ותומר העניין להראות לו איך מבריחים תווים ולא להגיד לו את כל הקוד.

forils 22-11-06 19:28

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

while ($row=mysql_fetch_array($result)) 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/home/matrixip/domains/dicw.net/public_html/1/index.php on line 8

Elad-A 22-11-06 19:36

תחליף את השורה הזאת:

PHP קוד:

$result mysql_query("SELECT * FROM 'news' ORDER BY 'id' DESC"); 

בזאת:

PHP קוד:

$result mysql_query("SELECT * FROM 'news' ORDER BY id DESC") OR die ("Error: ".mysql_error()); 

ותרשום פה מה השגיאה שזה מחזיר. (אם בכלל זה מחזיר)

forils 22-11-06 19:41

מראה את השגיאה :
Error: 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 ''news' ORDER BY id DESC' at line 1

Elad-A 22-11-06 19:43

תנסה ככה:

PHP קוד:

$result mysql_query("SELECT * FROM news ORDER BY id DESC") OR die ("Error: ".mysql_error()); 


forils 22-11-06 19:44

מראה :
Error: No database selected

Elad-A 22-11-06 19:45

תבחר את המסד שלך..


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

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