page=news&id=... WEL / page=news&subject=... NIET
Ik heb een nieuws-systeem.
Dit nieuwssysteem laat de berichten via ID zien.
Dus een bericht heeft het id 1, en je klikt op read more, dan gaat hij naar. Index.php?page=news&id=1.
Nu wil ik dit veranderen naar, index.php?page=news&subject=HET SUBJECT VAN HET BERICH HIER..
De code is dit;
PS: Let niet op de beveiliging, die moet nog komen. Dit is enkel het tijdelijke opset.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<table border="0" cellspacing="5">
<tr>
<td width="400" valign="top" class="content">
<strong>HOME:</strong>
<hr class="content_hr" />
<?php
$sql_news = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 2");
$count = mysql_num_rows($sql_news);
while($row_news = mysql_fetch_array($sql_news)) {
$text = $row_news['content'];
$text = nl2br($text);
$subject = $row_news['subject'];
$subject = eregi_replace(" ", "+", $subject);
$text = substr($text, 0, 175) . "...";
echo $row_news['date'] . " <img src='images/stripes.gif' />
<a href='index.php?page=news&category=".$subject."'>" . $row_news['subject'] . "</a> <img src='images/stripes.gif' />
<a href='index.php?page=news&id=".$row_news['id']."'>Reactions (" .
mysql_num_rows(mysql_query("SELECT id_news FROM news_reactions WHERE id_news = " . $row_news['id'] . "")) . ")</a><br />";
if($row_news['uDate'] != '0000-00-00' && $row_news['uTime'] != '00:00:00') {
echo "<span class='message_update'>(News updated on: " . $row_news['uDate'] ." at ". $row_news['uTime'] .")</span><br />";
} else {
echo "";
}
echo "<br />";
echo $text;
echo "<br />";
echo "<br />";
echo "<div align='right'><a href='index.php?page=news&id=" . $row_news['id'] . "'>Read more</a>...</div>";
echo "<hr class='content_hr' />";
}
?>
</td>
<td width="150"></td>
<td width="160" valign="top">
<strong>Updates:</strong>
<hr class="content_hr" />
</td>
</tr>
</table>
<tr>
<td width="400" valign="top" class="content">
<strong>HOME:</strong>
<hr class="content_hr" />
<?php
$sql_news = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 2");
$count = mysql_num_rows($sql_news);
while($row_news = mysql_fetch_array($sql_news)) {
$text = $row_news['content'];
$text = nl2br($text);
$subject = $row_news['subject'];
$subject = eregi_replace(" ", "+", $subject);
$text = substr($text, 0, 175) . "...";
echo $row_news['date'] . " <img src='images/stripes.gif' />
<a href='index.php?page=news&category=".$subject."'>" . $row_news['subject'] . "</a> <img src='images/stripes.gif' />
<a href='index.php?page=news&id=".$row_news['id']."'>Reactions (" .
mysql_num_rows(mysql_query("SELECT id_news FROM news_reactions WHERE id_news = " . $row_news['id'] . "")) . ")</a><br />";
if($row_news['uDate'] != '0000-00-00' && $row_news['uTime'] != '00:00:00') {
echo "<span class='message_update'>(News updated on: " . $row_news['uDate'] ." at ". $row_news['uTime'] .")</span><br />";
} else {
echo "";
}
echo "<br />";
echo $text;
echo "<br />";
echo "<br />";
echo "<div align='right'><a href='index.php?page=news&id=" . $row_news['id'] . "'>Read more</a>...</div>";
echo "<hr class='content_hr' />";
}
?>
</td>
<td width="150"></td>
<td width="160" valign="top">
<strong>Updates:</strong>
<hr class="content_hr" />
</td>
</tr>
</table>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
if (isset($_GET["id"])){
$news_id = $_GET["id"];
$result = mysql_query("SELECT * FROM news WHERE id = $news_id ");
while (list($id, $upDate, $upTime, $subject, $creator, $time, $date, $content, $reactions) =
mysql_fetch_row($result)){
$uContent = $content;
?>
<table border="0" cellspacing="5">
<tr>
<td width="400" valign="top" class="content">
<strong>NEWS: <?php echo "//" . $subject; ?></strong>
<hr class="content_hr" />
<table>
<tr>
<td width="57" class="user_text"><strong>Date</strong>:</td>
<td width="408" align="left" class="user_text"><?php echo $date; ?></td>
</tr>
<tr>
<td class="user_text"><strong>Creator:</strong></td>
<td class="user_text" align="left"><?php echo $creator ?></td>
</tr>
<tr>
<td align="left" class="user_text" valign="top" colspan="2"><strong>Message</strong>:</td>
</tr>
<tr>
<td class="user_text" align="left" colspan="2"><textarea disabled="disabled" rows="15" cols="64" class="default_input_field" ><?php echo $uContent; }}?></textarea></td>
</tr>
<tr>
<td colspan="2"><strong>REACTIONS:</strong>
<hr class="content_hr" /></td>
</tr>
<tr>
<td colspan="2">
<?php
$uContent = $content;
$result_count = mysql_query("SELECT * FROM news_reactions WHERE id_news = $news_id ORDER BY id DESC LIMIT 0, 5 ");
while (list($id, $id_news, $subject, $user, $time, $date, $content) =
mysql_fetch_row($result_count)){
if($content != NULL) {
echo "<table width='500' border='0' cellspacing='0'>";
echo "<tr>";
echo "<td align='left' width='350' class='user'>" . $user . "<br /><br /></td>";
echo "<td align='right' width='150'>#" . $id ."<br /><br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='left' width='350' colspan='2'>" . $date . "<br>" . $time . "<br /><br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='left' width='350' class='text' colspan='2'>" . $content . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center' width='350' colspan='2'><br><hr color='#222222' width='500px' size='1'></td>";
echo "<tr>";
echo "</table>";
}
}
echo "<strong>YOUR REACTION:</strong>
<hr class='content_hr' />";
?>
<form method="post" name="reaction"><br />
Fields with an * are required!
<table>
<tr>
<td>Name: *</td>
<td><input name="your_name" type="text" value="Your name" class="default_input_field" onFocus="if(this.value=='Your name') this.value='';" onBlur="if(this.value=='') this.value='Your name'" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="your_email" type="text" value="Your E-Mail" class="default_input_field" onFocus="if(this.value=='Your E-Mail') this.value='';" onBlur="if(this.value=='') this.value='Your E-Mail'" /></td>
</tr>
<tr>
<td valign="top">Reaction: *</td>
<td><textarea name="your_reaction" rows="8" cols="64" class="default_input_field"></textarea></td>
</tr>
<tr>
<td valign="top"><input type="submit" name="submit" value="Submit" class="default_input_button"></td>
<td></td>
</tr>
</table>
</form>
<?php
$date = date("F jS, Y");
$creator = $_POST['creator'];
$subject = "Tijdelijk subject";
$user = $_POST['your_name'];
$email = $_POST['your_email'];
$message = $_POST['your_reaction'];
$message = htmlentities($message);
$message = nl2br($message);
$message = stripslashes($message);
$melding = "Reactie: ". $_POST['reaction'] ." is met succes geplaats!";
if($_SERVER['REQUEST_METHOD'] == "POST") {
$sql = 'INSERT INTO news_reactions
(id_news, subject, user, time, date, content)
VALUES
("' . $_GET['id'] . '",
"' . mysql_real_escape_string( $subject ) . '",
"' . mysql_real_escape_string( $user ) . '",
NOW(),
"' . mysql_real_escape_string( $date ) . '",
"' . mysql_real_escape_string( $message ) . '")';
$query = mysql_query($sql) or die (mysql_error());
echo $melding;
}
?>
</table>
</form>
</td>
<td width="150"></td>
<td width="160" valign="top">
<strong>Updates:</strong>
<hr class="content_hr" />
</td>
</tr>
</table>
if (isset($_GET["id"])){
$news_id = $_GET["id"];
$result = mysql_query("SELECT * FROM news WHERE id = $news_id ");
while (list($id, $upDate, $upTime, $subject, $creator, $time, $date, $content, $reactions) =
mysql_fetch_row($result)){
$uContent = $content;
?>
<table border="0" cellspacing="5">
<tr>
<td width="400" valign="top" class="content">
<strong>NEWS: <?php echo "//" . $subject; ?></strong>
<hr class="content_hr" />
<table>
<tr>
<td width="57" class="user_text"><strong>Date</strong>:</td>
<td width="408" align="left" class="user_text"><?php echo $date; ?></td>
</tr>
<tr>
<td class="user_text"><strong>Creator:</strong></td>
<td class="user_text" align="left"><?php echo $creator ?></td>
</tr>
<tr>
<td align="left" class="user_text" valign="top" colspan="2"><strong>Message</strong>:</td>
</tr>
<tr>
<td class="user_text" align="left" colspan="2"><textarea disabled="disabled" rows="15" cols="64" class="default_input_field" ><?php echo $uContent; }}?></textarea></td>
</tr>
<tr>
<td colspan="2"><strong>REACTIONS:</strong>
<hr class="content_hr" /></td>
</tr>
<tr>
<td colspan="2">
<?php
$uContent = $content;
$result_count = mysql_query("SELECT * FROM news_reactions WHERE id_news = $news_id ORDER BY id DESC LIMIT 0, 5 ");
while (list($id, $id_news, $subject, $user, $time, $date, $content) =
mysql_fetch_row($result_count)){
if($content != NULL) {
echo "<table width='500' border='0' cellspacing='0'>";
echo "<tr>";
echo "<td align='left' width='350' class='user'>" . $user . "<br /><br /></td>";
echo "<td align='right' width='150'>#" . $id ."<br /><br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='left' width='350' colspan='2'>" . $date . "<br>" . $time . "<br /><br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='left' width='350' class='text' colspan='2'>" . $content . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center' width='350' colspan='2'><br><hr color='#222222' width='500px' size='1'></td>";
echo "<tr>";
echo "</table>";
}
}
echo "<strong>YOUR REACTION:</strong>
<hr class='content_hr' />";
?>
<form method="post" name="reaction"><br />
Fields with an * are required!
<table>
<tr>
<td>Name: *</td>
<td><input name="your_name" type="text" value="Your name" class="default_input_field" onFocus="if(this.value=='Your name') this.value='';" onBlur="if(this.value=='') this.value='Your name'" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="your_email" type="text" value="Your E-Mail" class="default_input_field" onFocus="if(this.value=='Your E-Mail') this.value='';" onBlur="if(this.value=='') this.value='Your E-Mail'" /></td>
</tr>
<tr>
<td valign="top">Reaction: *</td>
<td><textarea name="your_reaction" rows="8" cols="64" class="default_input_field"></textarea></td>
</tr>
<tr>
<td valign="top"><input type="submit" name="submit" value="Submit" class="default_input_button"></td>
<td></td>
</tr>
</table>
</form>
<?php
$date = date("F jS, Y");
$creator = $_POST['creator'];
$subject = "Tijdelijk subject";
$user = $_POST['your_name'];
$email = $_POST['your_email'];
$message = $_POST['your_reaction'];
$message = htmlentities($message);
$message = nl2br($message);
$message = stripslashes($message);
$melding = "Reactie: ". $_POST['reaction'] ." is met succes geplaats!";
if($_SERVER['REQUEST_METHOD'] == "POST") {
$sql = 'INSERT INTO news_reactions
(id_news, subject, user, time, date, content)
VALUES
("' . $_GET['id'] . '",
"' . mysql_real_escape_string( $subject ) . '",
"' . mysql_real_escape_string( $user ) . '",
NOW(),
"' . mysql_real_escape_string( $date ) . '",
"' . mysql_real_escape_string( $message ) . '")';
$query = mysql_query($sql) or die (mysql_error());
echo $melding;
}
?>
</table>
</form>
</td>
<td width="150"></td>
<td width="160" valign="top">
<strong>Updates:</strong>
<hr class="content_hr" />
</td>
</tr>
</table>
Het meest logische lijkt mij dat als ik in code 1: dit verander;
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<a href='index.php?page=news&id=".$row_news['id']."'>Reactions (" .
mysql_num_rows(mysql_query("SELECT id_news FROM news_reactions WHERE id_news = " . $row_news['id'] . "")) . ")</a>
en
<a href='index.php?page=news&id=" . $row_news['id'] . "'>Read more</a>
mysql_num_rows(mysql_query("SELECT id_news FROM news_reactions WHERE id_news = " . $row_news['id'] . "")) . ")</a>
en
<a href='index.php?page=news&id=" . $row_news['id'] . "'>Read more</a>
in:
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<a href='index.php?page=news&subject=".$row_news['subject']."'>Reactions (" .
mysql_num_rows(mysql_query("SELECT id_news FROM news_reactions WHERE subject = " . $row_news['subject'] . "")) . ")</a<
en
<a href='index.php?page=news&subject=" . $row_news['subject'] . "'>Read more</a>
mysql_num_rows(mysql_query("SELECT id_news FROM news_reactions WHERE subject = " . $row_news['subject'] . "")) . ")</a<
en
<a href='index.php?page=news&subject=" . $row_news['subject'] . "'>Read more</a>
De linken worden dan;
index.php?page=news&subject=bijvoorbeeldsubject1.
Het lijkt mij ook dat;
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
if (isset($_GET["id"])){
$news_id = $_GET["id"];
$result = mysql_query("SELECT * FROM news WHERE id = $news_id ");
en
$result_count = mysql_query("SELECT * FROM news_reactions WHERE subject = $subject_id ORDER BY id DESC LIMIT 0, 5 ");
$news_id = $_GET["id"];
$result = mysql_query("SELECT * FROM news WHERE id = $news_id ");
en
$result_count = mysql_query("SELECT * FROM news_reactions WHERE subject = $subject_id ORDER BY id DESC LIMIT 0, 5 ");
verandert moet worden in;
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
if (isset($_GET["subject"])){
$subject_id = $_GET["subject"];
$result = mysql_query("SELECT * FROM news WHERE subject = $subject_id ");
en
$result_count = mysql_query("SELECT * FROM news_reactions WHERE subject = $subject_id ORDER BY id DESC LIMIT 0, 5 ");
$subject_id = $_GET["subject"];
$result = mysql_query("SELECT * FROM news WHERE subject = $subject_id ");
en
$result_count = mysql_query("SELECT * FROM news_reactions WHERE subject = $subject_id ORDER BY id DESC LIMIT 0, 5 ");
Echter als ik dit doe krijg ik;
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ...pages\news.php on line 6
_
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ..pages\news.php on line 39
Regel 6: $result = mysql_query("SELECT * FROM news WHERE subject = $uSubject ");
while (list($id, $upDate, $upTime, $subject, $creator, $time, $date, $content, $reactions) =
mysql_fetch_row($result)){
Regel 39: $result_count = mysql_query("SELECT * FROM news_reactions WHERE subject = $uSubject ORDER BY id DESC LIMIT 0, 5 ");
while (list($id, $id_news, $subject, $user, $time, $date, $content) =
mysql_fetch_row($result_count)){
Waarom krijg ik deze error?
Het lijkt me niet logisch, wel toch?
Iemand een idee?
Gewijzigd op 01/01/1970 01:00:00 door [email protected]
www.mijnwebsite.nl/nieuws/titel-van-het-bericht/ van te maken ipv www.mijnwebsite.nl/index.php?page=news&subject=bericht.
Kijk eens of je wat kunt vinden over .htaccess bestanden, pas jouw urls daar op aan, dan heb je het meteen in een keer helemaal goed.
Wellicht is het idee om de urls direct maar helemaal te 'cleanen' en er Kijk eens of je wat kunt vinden over .htaccess bestanden, pas jouw urls daar op aan, dan heb je het meteen in een keer helemaal goed.
Dit werk wel fijn echter is het gewoon raar dat ik een error krijg, hij zou het te horen doen!
[email protected] schreef op 13.03.2009 18:34:
Raar? Beveiliging en foutafhandeling ontbreken, dan is het vrij logisch dat het fout gaat. Ga die onderdelen dan ook eerst maar eens inbouwen/aanvullen, dan is het probleem waarschijnlijk ook vrij snel opgelost.echter is het gewoon raar dat ik een error krijg, hij zou het te horen doen!
Zoiezo.
Waarom zou het wel werken met id, maar niet met subject, bij id had ik ook geen fout af-handeling..
Dus tja.
1) Foutafhandeling mag alleen ontbreken wanneer je veel tijd wilt besteden aan debuggen
2) beveiliging mag alleen ontbreken wanneer SQL injection een gewenste functionaliteit is.
Wanneer jij denkt dat e.e.a. niet nodig is, veel succes met debuggen en het herstellen van je database.
[email protected] schreef op 13.03.2009 18:40:
Zoiezo.
sowieso ;]
[email protected] schreef op 13.03.2009 18:34:
Ja, maar .htacces vind ik te moelijk werken.
Dit werk wel fijn echter is het gewoon raar dat ik een error krijg, hij zou het te horen doen!
Dit werk wel fijn echter is het gewoon raar dat ik een error krijg, hij zou het te horen doen!
Tja, dan weet ik het ook niet meer..... .htaccess is namelijk redelijk eenvoudig.
Gevonden op website www.dw-designs.nl::
LOL, Welcome!
lol to, lol, i love porn
Do you to?
lol to, lol, i love porn
Do you to?
Gewijzigd op 01/01/1970 01:00:00 door The Ultimate
Tekst is gewoon nogal foutgevoelig als je dat dat gaat vergelijken. Anders zet je zowel het ID als de tekst in de URL. Dus index.php?page=news&id=4&Dit-is-je-onderwerp, dan heb je alsnog wat je wilt, aleen doet Google er niet zoveel meer mee.
Maar dat Google niks vindt vind ik niet erg.