Hi zusammen,
ich bin neu hier und hoffe hier kann mir jemand weiterhelfen. Ich bin Neuling in PHP und wollte mal eine schicke shoutbox für meine Website machen.
Ich poste euch mal den Code und vll kann mir jemand sagen wo mein Denkfehler ist.
Vielen Dank schonmal!
Gruß Iphonefreak
ich bin neu hier und hoffe hier kann mir jemand weiterhelfen. Ich bin Neuling in PHP und wollte mal eine schicke shoutbox für meine Website machen.
Ich poste euch mal den Code und vll kann mir jemand sagen wo mein Denkfehler ist.
PHP-Code:
</div>
<div align="left" class="shoutbox_ueberschrift" id="shoutbox_ueberschrift">
<h2>Shoutbox</h2>
</div>
<div id="daddy-shoutbox" class="shoutbox" position:"absolute" frameborder="0">
<?php
$self = $_SERVER['PHP_SELF']; //the $self variable equals this file
$ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP
include ('db.php'); // for db details
// defines a $connect variable
$connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this time.</p>');
// connect to database using details provided
mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>');
// checks the POST to see if something has been submitted
if(isset($_POST['send'])) {
if(empty($_POST['name']) || empty($_POST['post'])) {
echo('<p class="error">You did not fill in a required field.</p>');
} else {
// if there are no empty fields, insert into the database:
$name = htmlspecialchars(mysql_real_escape_string($_POST['name']));
$email = htmlspecialchars(mysql_real_escape_string($_POST['email']));
$post = htmlspecialchars(mysql_real_escape_string($_POST['post']));
// this is our SQL string to insert shouts into db
$sql = "INSERT INTO shouts SET name='$name', email='$email', post='$post', ipaddress='$ipaddress';";
// we run the SQL string now
// if it succeeds, display message
if (@mysql_query($sql)) {
echo('<p class="success"></p>');
} else {
// if it errors, send message
echo('<p class="error">There was an unexpected error when posting your shout.</p>');
}
}
// now we retrieve the 8 latest shouts from the db
$query = "SELECT * FROM shouts ORDER BY `id` DESC LIMIT 8;";
// run the query. if it fails, display error
$result = @mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing shouts from the database.</p>');
?><ul><?
// while we still have rows from the db, display them
while ($row = mysql_fetch_array($result)) {
$ename = stripslashes($row['name']);
$epost = stripslashes($row['post']);
echo('<li><div class="meta"><p>'.$ename.'</p></div><div class="shout"><p>'.$epost.'</p></div></li>'); //Output
}
?></ul><?
?>
<div id="daddy-shoutbox-list"></div>
<br />
<form id="daddy-shoutbox-form" action="<?php $self ?>" method="post">
Name: <input type="text" name="name" />Shout: <input type="text" name="post" />
<input type="submit" value="OK" />
<span id="daddy-shoutbox-response"></span>
</form>
</div>
Gruß Iphonefreak
Kommentar