Gå til innhold

PHP shoutbox;LØST


Anbefalte innlegg

Edit:

Var en liten feil i koden min i shoutbox.php som gjorde at etter shout var trykket så gikk den til index.php nå er det rettet.

 

 

Hei, prøver å få igang shoutbox'en min. Alt funker bra helt til jeg trykker shout, da kommer den tilbake til index.php i stedet for frontpage.php

 

Koden jeg bruker i frontpage.php øverst i php-fila:

------------------------------------------------------------------------------------------------

<?php

require_once("/customers/iamarandomperson.com/iamarandomperson.com/httpd.www/shoutbox.php");

if($submit){

$shoutbox = new shoutbox;

$shoutbox->connect();

$shoutbox->insertshout($shoutname, $shout);

header("Location: $PHP_SELF");

}

?>

------------------------------------------------------------------------------------------------

Tipper det er header("Location: $PHP_SELF"); som gjør at den vil tilbake til index.php??

Er det mulig å få den til å åpne frontpage.php igjen i stedet?

 

 

------------------------------------------------------------------------------------------------

Her er shoutbox.php:

<?php

class shoutbox {

var $listlimit;

var $bgcolor1;

var $bgcolor2;

 

function connect() {

mysql_connect("localhost", "xxx", "pass") OR die ("Connection Error to Server");

mysql_select_db("xxx") OR die("Connection Error to Database");

}

 

function displayform() { //display the shoutbox form

?>

<script type="text/javascript">

<!--

function sjekk(s) {

if (s.shoutname.value.length == 0 || s.shoutname.value == "name"){

alert("Navn er ikke utfylt!")

s.shoutname.focus()

return false

}

if (s.shout.value.length == 0 || s.shout.value == "shout") {

alert("Du må fylle inn et shout!")

s.shout.focus()

return false

}

return true

}

//-->

</script>

 

<TABLE WIDTH="100%" BORDER="0" CELLPADDING="4" CELLSPACING="0">

<FORM NAME="shout" ACTION="index.php" METHOD="post" onsubmit="return sjekk(this)">

<TBODY>

<TR>

<TD ALIGN="center">

<INPUT TYPE="text" VALUE="name" NAME="shoutname" SIZE="15"><BR>

<INPUT TYPE="text" VALUE="shout" NAME="shout" SIZE="15"><BR>

<INPUT TYPE="submit" NAME="submit" VALUE="Shout!"> <INPUT TYPE="reset" VALUE="Reset">

</TD>

</TR>

</TBODY>

</FORM>

</TABLE>

<?php

}

 

function displayshoutbox() { //displays shouts in the table up to the defined limit

echo "<p>

<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"4\" CELLSPACING=\"0\">

";

$shoutboxResult = mysql_query("SELECT * FROM myshout ORDER BY

shoutid DESC LIMIT $this->listlimit;");

 

if ($shoutboxRow = mysql_fetch_array($shoutboxResult)) {

do {

$shoutid = $shoutboxRow[shoutid];

$shoutname = $shoutboxRow[shoutname];

$shoutdate = $shoutboxRow[shoutdate];

$shoutmsg = $shoutboxRow[shoutmsg];

 

$shoutmsg = wordwrap($shoutmsg, 19, "\n", 1);

$bgcolor = ($count++ % 2) ? "$this->bgcolor1" : "$this->bgcolor2";

 

echo "<TR><TD BGCOLOR=\"$bgcolor\"><b>$shoutname</b>: $shoutmsg<DIV ALIGN=\"right\">

<i>$shoutdate</i></DIV></TD></TR>\n";

}

while($shoutboxRow = mysql_fetch_array($shoutboxResult));

}

else {

echo "No shouts yet";

}

echo "</TABLE>";

}

 

function insertshout($shoutname, $shout) { //insert data into table

$shoutname = strip_tags($shoutname);

$shout = strip_tags($shout, '<a><b><i><u>'); //strip html tags allowing only <a><b><i><u>

if (mysql_query ("INSERT INTO myshout (shoutname, shoutmsg, shoutdate) VALUES

('$shoutname', '$shout', NOW())")) {

echo "";

}

else {

echo mysql_error();

}

}

 

} //fra class shoutbox

?>

------------------------------------------------------------------------------------------------

Endret av ken8
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...