script will net x_X

daedalus_dr

Grünschnabel
Hallo zusammen!
Ich habe mal im Schweiße meines Angesichts versucht ein Script zu scripten (Newsscript), aber es will nicht.
Kann mir vielleicht einer sagen warum? Hier das Script:

Code:
<? 
$dbms = 'mysql4'; 

$dbhost = 'localhost'; 
$dbname = 'usr_web8_4'; 
$dbuser = 'web8'; 
$dbpasswd = ''; 

$db = @mysql_connect($dbhost,$dbuser,$dbpasswd) or die(mysql_error()); 
mysql_select_db($dbname) or die(mysql_error()); 

if ( $_GET['type'] == "post" ) 
{ 
?>
<form method="POST" name="newspost">
<input type="text" name="post_title">
<input type="text" name="post_date">
<textarea name="post_text"></textarea>
<?

if ( $_POST['text'] != "" ) 
{ 
$query = "INSERT INTO news (news_title, news_date, news_msg) VALUES ('" .  $_POST['post_title'] . "', '" . $_POST['post_date'] . "', '" . $_POST['post_text'] . "')"; 
mysql_query($query); 

} else {

?>
<table width=\"563\" border=\"1\" bordercolor=\"#000000\" bgcolor=\"#CCCCCC\"> 
<tr> 
<td width=\"553\" height=\"23\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\">News</td>
<? 

for ( $i = 0; $i != 100 ; $i++ ) 
{ 
$sql = "SELECT * FROM news WHERE ID='" . $i . "'"; 
$sql = MYSQL_QUERY($sql); 
$sql = MYSQL_FETCH_ARRAY($sql);
if ( $sql['news'] != "" ) 
{ 
  
    echo "<td width=\"443\" height=\"23\" align=\"left\" valign=\"middle\" bgcolor=\"#FFFFFF\">" . $sql['news_title'] . "</td> 
  <td width=\"104\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\">" . $sql['news_date'] . "</td> 
  </tr> 
   <td height=\"23\" colspan=\"2\" align=\"left\" bgcolor=\"#FFFFFF\">" . $sql['news_text'] . "</td> 
  </tr> 
<tr> 
   <td height=\"23\" colspan=\"2\" valign=\"middle\" bgcolor=\"#FFFFFF\"><hr></td>"; 
 }
} 
?> 
</table> 
<?
}
?>
 
PHP:
<?php

	$dbms = 'mysql4';
	$dbhost = 'localhost';
	$dbname = 'usr_web8_4';
	$dbuser = 'web8';
	$dbpasswd = '';

	$db = @mysql_connect($dbhost,$dbuser,$dbpasswd) or die(mysql_error());
	mysql_select_db($dbname) or die(mysql_error());

	if( $_GET['type'] == 'post' ) {
?>
<form action="<php echo $_SERVER['REQUEST_URI']; ?>" method="post">
	<input type="text" name="title">
	<input type="text" name="date">
	<textarea name="text"></textarea>
</form>
<?php

		if( $_POST['text'] != '' ) {

			$query = "
				INSERT INTO
				        `news`
				  SET
				        `news_title` = '".mysql_real_escape_string($_POST['title'])."',
				        `news_date`  = '".mysql_real_escape_string($_POST['date'])."',
				        `news_msg`   = '".mysql_real_escape_string($_POST['text'])."'
				";
			mysql_query($query);

		} else {

?>
<h2>News</h2>
<?php
			$query = "
				SELECT
				        `news_title`,
				        `news_date`,
				        `news_msg`
				  FROM
				        `news`
				";
			$result = mysql_query($query);
			while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {
				echo '<div class="item">';
				echo '<h3>'.$row['news_title'].'</h3>';
				echo '<div class="date">'.$row['news_date'].'</div>';
				echo '<p>'.$row['news_msg'].'</p>';
				echo '</div>';
			}
		}

	}

?>
HTML ist übrigens eine Auszeichnungssprache und sollte nicht zu darstellerischen Zwecken missbraucht werden. Zur Formatierung ist CSS gedacht.
 
Hm ?
Ich verstehs net^^
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /srv/www/htdocs/web8/html/die.php on line 47
 
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /srv/www/htdocs/web8/html/die.php on line 47

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /srv/www/htdocs/web8/html/die.php on line 48

Bringen tuts irgendwie nichts. :( Vielleicht kommt ja noch einer darauf, woran es liegt.
 
2 Sachen:
a) mach das @ vor mysql_connect mal weg.
b) mach statt
PHP:
  mysql_query($query);
mal
PHP:
  mysql_query($query) or die(mysql_error());

dann siehste ma, was da schon bei der abfrage net richtig läuft!
 
Hm,ja. Der MYSQL_Bug ist jetzt weg, aber er zeigt die News nur unter news.php?type=post an. x_X Ich versteh nur nicht warum, hab schon alles mögliche probiert.

EDIT: HABS GESCHAFFT! xD

Code:
<?php 

    $dbms = 'mysql4'; 
    $dbhost = 'localhost'; 
    $dbname = 'usr_web8_4'; 
    $dbuser = 'web8'; 
    $dbpasswd = ''; 

    $db = @mysql_connect($dbhost,$dbuser,$dbpasswd) or die(mysql_error()); 
    mysql_select_db($dbname) or die(mysql_error()); 

    if( $_GET['type'] == 'post' ) { 
?> 
<form method="POST" name="newspost"> 
<input type="text" name="title"> 
<input type="text" name="date"> 
<textarea name="text"></textarea>
<input type="Submit">
</form> 
<?php 

        if( $_POST['text'] != '' ) { 

            $query = " 
                INSERT INTO 
                        `news` 
                  SET 
                        `news_title` = '".mysql_real_escape_string($_POST['title'])."', 
                        `news_date`  = '".mysql_real_escape_string($_POST['date'])."', 
                        `news_msg`   = '".mysql_real_escape_string($_POST['text'])."' 
                "; 
            mysql_query($query); 

        }
		} else { 

?> 
<h2>News</h2> 
<?php 
            $query = " 
                SELECT 
                        `news_title`, 
                        `news_date`, 
                        `news_msg` 
                  FROM 
                        `news` 
                "; 
            $result = mysql_query($query); 
            while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) { 
                echo '<div class="item">'; 
                echo '<h3>'.$row['news_title'].'</h3>'; 
                echo '<div class="date">'.$row['news_date'].'</div>'; 
                echo '<p>'.$row['news_msg'].'</p>'; 
                echo '</div>';             
        } 

    } 

?>
 
Zuletzt bearbeitet:
Zurück