[GELÖST] MySql: mysql_fetch_array():

Hey,

Ich habe versucht auf meiner Seite eine Shoutbox anzulegen, doch es funtioniert nicht da bei Aufruf der Seite immer folgende Fehlermeldung kommt:

mysql_fetch_array(): supplied argument is not a valid MySQL

EDIT!: Das Problem hat sich nun lösen lassen, aber es wird nun keine Message angezeigt nachdem Abschicken!

Die Seite: http://ashley4fans.bplaced.de/shout.php
Der PHP Code ist folgender:

[code]<?
//the host, name, and password for your mysql
mysql_connect(“localhost”,“ashley4fans”,“DASSCHREIBEICHNICHTINSFORUM”);

//select the database
mysql_select_db(“ashley4fans”);

if($submit)
{
//use the PHP date function for the time
$time=date(“h:i d.m.Y”);

// inserting it into the shoutbox table which we made in the mysql statements before
$result=MYSQL_QUERY(“INSERT INTO shoutbox (id,name,message,time)”.
“VALUES (‘NULL’,’$name’, ‘$message’,’$time’)”);
}
?>

<? //returning the last 5 messages $result = mysql_query("select * from shoutbox order by id desc limit 5"); //the while loop while($r=mysql_fetch_array($result)) //dort steht anscheinend der fehler?! { //getting each variable from the table $time=$r["time"]; $id=$r["id"]; $message=$r["message"]; $name=$r["name"]; ?> <? echo $time ?>
<? echo $name ?>
<? echo $message ?>
<? } ?>[/code]

Ich hoffe ihr könnt mir helfen :wink:
lg, Sebi

nimm mal das

//returning the last 5 messages
$result1 = mysql_query("SELECT * FROM `shoutbox ` ODRDER BY `id` DESC LIMIT 5");

//the while loop
while($r=mysql_fetch_array($result1))  //dort steht anscheinend der fehler?!
{

und sag ob die meldung immernoch kommt.

[quote=“iNaD”]nimm mal das

//returning the last 5 messages
$result1 = mysql_query("SELECT * FROM `shoutbox ` ODRDER BY `id` DESC LIMIT 5");

//the while loop
while($r=mysql_fetch_array($result1))  //dort steht anscheinend der fehler?!
{

und sag ob die meldung immernoch kommt.[/quote]

Aber kopiere nicht den Code von iNaD 1:1. Hier ist ein fehler drin Es muß natürlich ORDER heissen - nicht ODRDER :wink:

Oh sry^^ das kommt wenn man kaum geschlafen hat !coffee

okey, also das problem hat sich beheben lassen xD
aber seltsamerweise bekommt man trotzdem keine nachricht als ECHO!

[code]<?
//the host, name, and password for your mysql
mysql_connect(“localhost”,“ashley4fans”,“DASSCHREIBEICHNICHTINSFORUM”);

//select the database
mysql_select_db(“ashley4fans”);

if($submit)
{
//use the PHP date function for the time
$time=date(“h:i d.m.Y”);

// inserting it into the shoutbox table which we made in the mysql statements before
$result=MYSQL_QUERY(“INSERT INTO shoutbox (id,name,message,time)”.
“VALUES (‘NULL’,’$name’, ‘$message’,’$time’)”);
}
?>

<? //returning the last 5 messages $result1 = mysql_query("SELECT * FROM `shoutbox` ORDER BY `id` DESC LIMIT 5"); //the while loop while($r=mysql_fetch_array($result1)) { //getting each variable from the table $time=$r["time"]; $id=$r["id"]; $message=$r["message"]; $name=$r["name"]; echo $time; echo $name.'
'; echo $message.'
'; } ?>[/code]

damit wird auch keine message ausgegeben >.<
=(

Ersetze mal in iNaD’s Code in Zeile 20$result1 = mysql_query("SELECT * FROM `shoutbox` ORDER BY `id` DESC LIMIT 5");mit$result1 = mysql_query("SELECT * FROM `shoutbox` ORDER BY `id` DESC LIMIT 5") or die(mysql_error());
Das Passwort natürlich auch noch anpassen…

Welches Ergebnis bekommst du, wenn du

im phpmyadmin ausführen lässt?

@uro: das hier:

@scram: passiert nichts (hast du schon meinen edit ganz oben beachtet? das 1. problem wurde behoben :wink:

Ja klar, es kann ja nichts in deine Datenbank geschrieben werden. Hier giltglobals=off, also musst du

if($submit)
{
   //use the PHP date function for the time
   $time=date("h:i d.m.Y");

   // inserting it into the shoutbox table which we made in the mysql statements before
   $result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".
      "VALUES ('NULL','$name', '$message','$time')");
}
?>

entsprechend anpassen. Also $submit usw. durch $_GET[‘submit’] bzw. $_POST[‘submit’] ersetzen.

Oh Gott, da hab ich das Offensichtliche übersehen. :smiley:

@Sebi: $result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)". "VALUES ('NULL','$name', '$message','$time')");
Das wird dank register_globals = Off auch nicht funktionieren.

@uro… kannst du mir das dementsprechend umcoden, so wie du das sagst?!

lg…

Kann ich machen. Brauche ich aber auch die Seite mit dem Formular dazu

dann hier der gesamte code:
schon mal vielen dank!

[code]<?
//the host, name, and password for your mysql
mysql_connect(“localhost”,“ashley4fans”,“SAG ICH NICHT”);

//select the database
mysql_select_db(“ashley4fans”);

if($submit)
{
//use the PHP date function for the time
$time=date(“h:i d.m.Y”);

// inserting it into the shoutbox table which we made in the mysql statements before
$result=MYSQL_QUERY(“INSERT INTO shoutbox (id,name,message,time)”.
“VALUES (‘NULL’,’$name’, ‘$message’,’$time’)”);
}
?>

<? //returning the last 5 messages $result1 = mysql_query("SELECT * FROM `shoutbox` ORDER BY `id` DESC LIMIT 5") or die(mysql_error()); //the while loop while($r=mysql_fetch_array($result1)) { //getting each variable from the table $time=$r["time"]; $id=$r["id"]; $message=$r["message"]; $name=$r["name"]; echo $time; echo $name.'
'; echo $message.'
'; } ?>
[/code]
if($_POST('submit')
{
   //use the PHP date function for the time
   $time=date("h:i d.m.Y");

   // inserting it into the shoutbox table which we made in the mysql statements before
   $result=MYSQL_QUERY("INSERT INTO shoutbox (name,message,time)".
      'VALUES ("' . $_POST('name') . '", "' . $_POST('message') . '", "' . $time . '")');
}
?>

Leider tritt nun folgender Fehler auf:Parse error: syntax error, unexpected ‘{’ in /users/ashley4fans/www/shout.php on line 9

(siehe auch Code)[code]
if($_POST(‘submit’)
{ <<<<<das wird jetzt als UNEXPECTED angesehen
//use the PHP date function for the time
$time=date(“h:i d.m.Y”);

// inserting it into the shoutbox table which we made in the mysql statements before
$result=MYSQL_QUERY(“INSERT INTO shoutbox (name,message,time)”.
‘VALUES ("’ . $_POST(‘name’) . ‘", "’ . $_POST(‘message’) . ‘", "’ . $time . ‘")’);
}
?>
[/code]

Stimmt habe bei
if($_POST(‘submit’) eine Klammer veressen

     if($_POST('submit'))

[code]if($_POST(‘submit’))
{ <<<<<das wird jetzt als UNEXPECTED angesehen
//use the PHP date function for the time
$time=date(“h:i d.m.Y”);

// inserting it into the shoutbox table which we made in the mysql statements before
$result=MYSQL_QUERY(“INSERT INTO shoutbox (name,message,time)”.
‘VALUES ("’ . $_POST(‘name’) . ‘", "’ . $_POST(‘message’) . ‘", "’ . $time . ‘")’);
}
?>[/code]

Nun nicht mehr :wink:

und weiter gehts >.< :unamused:
Fatal error: Function name must be a string in /users/ashley4fans/www/shout.php on line 8

[code]if($_POST(‘submit’)) //das ist line 8!
{
//use the PHP date function for the time
$time=date(“h:i d.m.Y”);

// inserting it into the shoutbox table which we made in the mysql statements before
$result=MYSQL_QUERY(“INSERT INTO shoutbox (name,message,time)”.
‘VALUES ("’ . $_POST(‘name’) . ‘", "’ . $_POST(‘message’) . ‘", "’ . $time . ‘")’);
}
?>[/code]