PHP halp!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Yanayaya
Forum Commoner
Posts: 42
Joined: Tue Dec 02, 2008 7:49 am

PHP halp!

Post 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:
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: PHP halp!

Post by papa »

Show us your code.
Yanayaya
Forum Commoner
Posts: 42
Joined: Tue Dec 02, 2008 7:49 am

Re: PHP halp!

Post 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';
?>
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: PHP halp!

Post 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?
Yanayaya
Forum Commoner
Posts: 42
Joined: Tue Dec 02, 2008 7:49 am

Re: PHP halp!

Post 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?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: PHP halp!

Post 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 -->
Post Reply