Page 1 of 1

PHP halp!

Posted: Tue Dec 02, 2008 7:54 am
by Yanayaya
Hello Everyone,

I have just found the forums and of course, just registered. So a big hello to everyone in this community and I hope that I can be of some help to people and in turn be helped out.

To kick things off I have a php question no less. I have been developing web forms for my company, forms that collect and submit data to a sql database. All that is fine, what I am looking to do is, create echo messages that would display when the form was submitted. However I want these messages to be displayed where I tell them to be, whether it be in a table cell or at the bottom of the page or whever. How can I make a message be displayed on submission of a form?

I have also developed PHP scripts that allow updating of previously submitted data, these too would require an echo message to be displayed in a specfic place to say that the entry had been amended etc etc.

At the moment I am using echo commands after the script has run using IF statements, however this means that the echo message always gets shoved at the top of the page.

Any advise on this? :banghead:

Re: PHP halp!

Posted: Tue Dec 02, 2008 7:59 am
by papa
Show us your code.

Re: PHP halp!

Posted: Tue Dec 02, 2008 8:07 am
by Yanayaya

Code: Select all

<?php
include 'configuration.php';
include 'opendatab.php';
 
if(isset($_GET['id']))
{
    $query = "SELECT id, title, content ".
        "FROM news ".
        "WHERE id = '{$_GET['id']}'";
    $result = mysql_query($query) or die('Error : ' . mysql_error());
    list($id, $title, $content) = mysql_fetch_array($result, MYSQL_NUM);
    
    $content = htmlspecialchars($content);
} 
else if(isset($_POST['title']))
{
$id      = $_POST['id'];
$title   = $_POST['title'];
$content = $_POST['content'];
    
if(!get_magic_quotes_gpc())
    {
        $title   = addslashes($title);
        $content = addslashes($content);
    }
    
$query = "UPDATE news ".
"SET title = '$title', content = '$content' ".
"WHERE id = '$id'";
mysql_query($query) or die('Error : ' . mysql_error());
 
 
$cacheDir  = dirname(__FILE__) . '/cache/';
$cacheFile = $cacheDir . '_' . $_GET['id'] . '.html';
    
@unlink($cacheFile);
    
@unlink($cacheDir . 'index.html');
        
echo "<p align='center'>Article updated</p>";
 
$title   = stripslashes($title);
$content = stripslashes($content);
}
include 'closedatab.php';
?>

Re: PHP halp!

Posted: Tue Dec 02, 2008 8:20 am
by papa
I don't understand. Why not run the scripts and if(success) $msg = x

display $msg where you want it in your page?

Re: PHP halp!

Posted: Tue Dec 02, 2008 8:23 am
by Yanayaya
papa wrote:I don't understand. Why not run the scripts and if(success) $msg = x

display $msg where you want it in your page?

Thank you for the response. Can show me how to intergrate that into the script I have there?

Re: PHP halp!

Posted: Tue Dec 02, 2008 8:26 am
by papa
You sure it's your script? ;)

$msg = "<p align='center'>Article updated</p>";
or
$msg ="<p class="message">Article updated</p>\n";

Something like that.

<!-- article updated message -->
<?php echo $msg; ?>
<!-- //article updated message -->