Jump to content

Ajuda php


andreis88
 Share

Recommended Posts

<?php
/* 
*/
//  IMPORTANT!!!! Connect to MySQL database here(put your connection data here)
mysql_connect("localhost","root","123") or die (mysql_error());
mysql_select_db("db_sara") or die (mysql_error());

if ($_POST['comType'] == "parseComment") {

    $name = $_POST['userName'];
$location = $_POST['userLocation'];
    $comment = $_POST['userMsg'];
    // Filter user input a little bit further using PHP if you allow more characters than I do in the Flash input text field
    //$name = mysql_real_escape_string($name);
    //$location = mysql_real_escape_string($location);
    //$post = mysql_real_escape_string($comment);
// uncomment this line below to preserve line breaks, paragraphs and such in the comment text
    //$post = nl2br(htmlspecialchars($comment));
    // Add to DB
    $sql = mysql_query("INSERT INTO livro (name, post_date, comment, location) 
        VALUES('$name', now(),'$comment','$location')")  
        or die (mysql_error());
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Assemble body and send back to flash showing their new comment or entry
$body = "";
    $sql = mysql_query("SELECT * FROM livro ORDER BY post_date DESC"); 
    while($row = mysql_fetch_array($sql)) {
	$id = $row["id"];
	$name = $row["name"];
	$post_date = $row["post_date"];
	$comment = $row["comment"];
	$location = $row["location"];
	//$n_post_body = str_replace("<br />", "", $n_post_body); // Use in case you get too many line breaks when preserving breaks
	$comment = stripslashes($comment);
	$name = eregi_replace("&#39;", "'",  $name);
	$location = eregi_replace("&#39;", "'",  $location);
	$comment = eregi_replace("&#39;", "'", $comment);
	// Decode HTML entities if storing comments that preserve line breaks and such
	//$n_post_body = html_entity_decode($n_post_body); // Uncomment to use
	$post_date = strftime("%b %d, %y", strtotime($post_date));

	$body .= '<u><b><font color="#790000">' . $name . '</font>    |    <font color="#9B9B9B">' . $location . '</font>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
	<br />
	'.$comment.'
	<br />
	<br />
	';
}
    mysql_free_result($sql);
    mysql_close();

 // Echo into flash
     echo "return_msg=Entry has been added successfully $name, thanks!&returnBody=$body";
     exit();

} // close first if for post
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*/
// Second part of the script is below, it simply requests all entries for initial display of the guestbook entries
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ($_POST['comType'] == "requestEntries") {

    $body = "";
    $sql = mysql_query("SELECT * FROM livro ORDER BY post_date DESC"); 
    while($row = mysql_fetch_array($sql)) { 
	$id = $row["id"];
	$name = $row["name"];
	$post_date = $row["post_date"];
	$comment = $row["comment"];
	$location = $row["location"];
	$comment = stripslashes($comment);
	// Decode HTML entities if storing comments that preserve line breaks and such
	//$n_post_body = html_entity_decode($n_post_body); // Uncomment to use
	$post_date = strftime("%b %d, %y", strtotime($post_date));

	$body .= '<u><b><font color="#790000">' . $name . '</font>    |    <font color="#9B9B9B">' . $location . '</font>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
	<br />
	'.$comment.'
	<br />
	<br />
	';
}
    mysql_free_result($sql);
    mysql_close();
    echo "returnBody=$body";
    exit();
} // close first if for post
?>

isto tem erros alguem pode me dizer aonde  e qe esta o erro obrigado

Link to comment
Share on other sites

isto e um tipo guestbook e dame este erro

$body"; exit(); } // close first if for post /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ // Second part of the script is below, it simply requests all entries for initial display of the guestbook entries /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if ($_POST['comType'] == "requestEntries") { $body = ""; $sql = mysql_query("SELECT * FROM livro ORDER BY post_date DESC"); while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $name = $row["name"]; $post_date = $row["post_date"]; $comment = $row["comment"]; $location = $row["location"]; $comment = stripslashes($comment); // Decode HTML entities if storing comments that preserve line breaks and such //$n_post_body = html_entity_decode($n_post_body); // Uncomment to use $post_date = strftime(" ", strtotime($post_date)); $body .= '' . $name . ' | ' . $location . ' | ' . $post_date . '

'.$comment.'

'; } mysql_free_result($sql); mysql_close(); echo "returnBody=$body"; exit(); } // close first if for post ?>

Link to comment
Share on other sites

q erro?

Ainda n percebi qual é o problema. Já percebi q já erro mas isso n ajuda!

Que erro dá?

Em que linha?

É um erro de sintaxe ou de execução?

Mostra o código relevante aonde ele dá erro.

"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Link to comment
Share on other sites

Este echo é... é... "wierd"

echo "return_msg=Entry has been added successfully $name, thanks!&returnBody=$body";

N faz sentido ter um echo assim. O que é que é suposto ser feito aqui?

"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Link to comment
Share on other sites

Nos comentários diz que isto é algo para flash, por isso devem ser parâmetros para o flash ou algo assim.

Que dados experimentaste colocar para isso dar erro? OU experimentaste aceder directamente ao ficheiro e deu esse erro?

Nick antigo: softclean | Tens um projeto? | Wiki P@P

Ajuda a comunidade! Se encontrares algo de errado, usa a opção "Denunciar" por baixo de cada post.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.