View Full Version : refreshing page

05-15-2008, 04:09 PM
hey guys... ok i want to refresh my page so when the form is submited it just refreshes the page... i thought about doing this

<link rel="stylesheet" type="text/css" href="http://www.runningprofiles.com/css/login.css"><?php session_start();

<style type="text/css">
.message {
color: #000000;
font-family: Verdana;
font-size: 10px;}

.username {
color: #FF9900
font-family: Verdana;
font-size: 4px;
font-weight: bold}

.date {
color: #707070;
font-family: Verdana;
font-size: 2px;}
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="padding: 2px">

//echo $user; this displays the user name but anything below it does not
if($_POST['submit']) {

// Verify if the fields were filled.
if(!$_POST['message']) {
echo 'Error, You need to post a Message!';

// Date format

$date = date("d/m/y"); // http://www.php.net/date

// Assign variables of the forms
// Connect to the database

$user = $_POST['username'];
$id = $_SESSION['user_id'];
$username = get_username($id);
$message = $_POST['message'];

// Insert the info in the shoutbox table.
$query = "INSERT INTO shoutbox (`user`, username, message, date, ip)
VALUES ('$user','$username','$message','$date','$ip')";
// close connection

// Show message to let them return to the shoutbox
<div align="center">Thank you for submitting.<br>
Return to the <a href="shoutbox.php">shoutbox</a>!
// If NOT submitted
} else {

$user2 = $_GET['username'];
$query = "SELECT * FROM shoutbox WHERE user = '$user2' ORDER BY id DESC LIMIT 3";
$result = mysql_query($query);
// Create a table

<table width="100&#37;" cellpadding="0" cellspacing="0" border="0">

// Run a While loop for the rows
while($c = mysql_fetch_array($result))
<?php echo $c['username']; ?> says:
<div align="justify"><?php echo $c['message']; ?></div>
<tr><td>on <?php echo $c['date']; ?>
<hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr>
<? } ?>

<?php $user1 = $_GET['username'];?>
<form method="post" action="<?php echo $user1;?>">

<input type=hidden name=username value='<?php echo $user1;?>'>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<td>Message :</td>
<td> <input type="text" name="message" class="input"></td>
<td colspan="2"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>

<?php } ?>


but the problem is as its included on my profile.php it then does not insert the data into the database... so has any1 got any better ideas on how to do this it would be good to have it like facebook where it says posting then posted and refreshes the message are...is this done by iframes>

05-15-2008, 04:48 PM
I read your post several times and I still can't figure out what you're asking. I really hate to say it, but could you repost your problem in more detail... using punctuation? I'm more than sure I could fix the problem, I just don't really know what results you're looking for. What I understand is:

You want to click submit, it submits the data, then it brings you back to the same page except without resubmitting the data? What's this about it being included by another file?

Also, this is really dangerous:

$user2 = $_GET['username'];
$query = "SELECT * FROM shoutbox WHERE user = '$user2' ORDER BY id DESC LIMIT 3";

I suggest using mysql_real_string_escape on $_GET['username'] to prevent any SQL injection.

05-15-2008, 05:01 PM
ok so i have profile.php

which has users image name ect... and on this i have included box.php

box.php is the script you see above... what i want to do is refresh box.php on the profile.php page so when a message is posted it is shown instantly on profile.php... does that makes sence??

and ty on heads up on mysql_real_string_escape