echo after sql query ?

Hey , here is my code and so i was wondering how do i put an echo efter the sql query , i mean if the sql query worked succesfully and and saved all information , i want it to echo “done” instead of showing the form.
how do i do that ??

[php] echo ‘’;
echo ’
write a something

‘.$message.’



';

if (!empty($message)) {
	mysql_query("INSERT INTO `gb` (`sender_id`, `owner_id`, `message`) VALUES('$sender_id', '$owner_id', '$message')") or die(mysql_error());
	
	} [/php]

store the query in a variable and create an if/else statement…

instead of this…

[php] if (!empty($message)) { mysql_query("INSERT INTO `gb` (`sender_id`, `owner_id`, `message`) VALUES('$sender_id', '$owner_id', '$message')") or die(mysql_error());
	} [/php]</blockquote>

do this…
[php]
if (!empty($message)) {
sqlQuery = mysql_query(“INSERT INTO gb (sender_id, owner_id, message) VALUES(’$sender_id’, ‘$owner_id’, ‘$message’)”) or die(mysql_error());
}

if(sqlQuery){
echo “Query was successful!”;
}
else {
echo “Something went wrong”;
}
[/php]

kinda woked when i added $ but it still does not replace the form box

My bad, that was done very poorly. Give me a second and I will get it to do what you need.

sure , thanks your time

Here is the code that I could fix. You need to know that you still have variables in there that are undefined, and will keep it from being added to the database.

[php]<?php
if(isset($_POST[‘submit’])){
$message = $_POST[‘message’];

if (!empty($message)) {
	$sqlQuery = mysql_query("INSERT INTO `gb` (`sender_id`, `owner_id`, `message`) VALUES('$sender_id', '$owner_id', '$message')") or die(mysql_error());
}

if($sqlQuery){
	echo "Done";
}
else {
	echo "Your message: \"$message\", could not be uploaded";
}

}
else {

echo '<form action="#" method="post">';
echo '
	<b>write a something</b> 
	<input type="hidden" value="GBanswer" /> 
	<textarea name="message" style="width: 430px;height: 120px"></textarea>
	<br /><br />
	<input type="submit" name="submit" style="float:right;" value="Skicka" /></form>
';

}

?> [/php]

ah ok thanks :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service