Jump to content

Recommended Posts

ive just started learning php and mysql ive got most of this script running fine but i cant figure out how to put the poster after the message and then have a line break any help please

 

mysql_select_db("message1") or die(mysql_error());

 

if (isset($_POST['mess'])) {

$message = $_POST['mess'];

$poster = $_POST['poster'];

$sql = "insert into message set

mess='$message',

  poster='$poster',

date=CURDATE()";

if(@mysql_query($sql)) {

 

echo '<p>';

} else {

echo '<font face="verdana" size="1">error adding message: ' .

mysql_error() . '';

}

}

 

 

$result = @mysql_query('SELECT mess FROM message');

if (!$result) {

exit('error performing query:'

. mysql_error(). ' ');

}

while ($row = mysql_fetch_array($result)) {

echo '<font face="verdana" size="1"> ' . $row['mess']  .' - ';

}

 

$result = @mysql_query('SELECT poster FROM message');

if (!$result) {

exit('error performing query:'

. mysql_error(). ' ');

    }

while ($row = mysql_fetch_array($result)) {

echo '<font face="verdana" size="1"> ' . $row['poster']  .' - ';

}

 

echo '<center><a href="'. $_SERVER['PHP_SELF'] . '?addmessage=1">add a message</a>';

 

endif;

?>

Link to comment
https://forums.phpfreaks.com/topic/50702-solved-help-with-a-comment-system/
Share on other sites

$sql = "insert into message set

  mess='$message',

poster='$poster',

  date=CURDATE()";

 

does this work??

 

try this, your probobally not seeing an error because your @ infront of the mysql_query

$sql = "INSERT INTO clan_apps (`mess`, `poster`, `date`)VALUES('$message','$poster', 'CURDATE()')";

you are running two queries from the same table to get two different things, run one query

 

$result = mysql_query("select mess, poster FROM message");

 

then one while loop will work

while ($row = mysql_fetch_array($result)) {
echo '<font face="verdana" size="1"> '' . $row['mess']  .' - ' . $row['poster'];
}

another small problem

 

<?Php

 

$result = @mysql_query("select news, poster, newsdate FROM message ORDER BY date DESC LIMIT 5");

while ($row = mysql_fetch_array($result)) {

echo '<b>' . $row['poster'] .' - '. $row['date']. '<br></b>' .  $row['News'] . '<p>';

}

?>

 

thats using the same code you gave me before but come up with an error on the mysql_fetch_array line

any ideas?

Seriously stop surpressing errors it does no good (the @ sign)

 

$result = mysql_query("select news, poster, newsdate FROM message ORDER BY `newsdate` DESC LIMIT 5") or DIE(mysql_error()); // the or die gives you a helpful error if one occurs.

 

Date is a reservered word that and since you were pulling it out by "newsdate" in the select portion I assumed you mean that. If you did not and you did mean date enclose it in the tick marks ` ` which will override the reserved word portion

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.