runnerjp Posted May 15, 2008 Share Posted May 15, 2008 hey guys... i was just wondering.. i have included i form onto a page and i was wodering how i would go about refreshing the form ones it has been submited but stick with the pages that its included on?? so my include is on profile.php and it points to box.php which is this <?php //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!'; die; } // Date format $date = date("d/m/y"); // http://www.php.net/date // Assign variables of the forms // Connect to the database include('../settings.php'); $user = $_POST['username']; $id = $_SESSION['user_id']; $username = get_username($id); $message = $_POST['message']; $ip = $_SERVER['REMOTE_ADDR']; // Insert the info in the shoutbox table. $query = "INSERT INTO shoutbox (`user`, username, message, date, ip) VALUES ('$user','$username','$message','$date','$ip')"; mysql_query($query); // 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>! <?php // 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%" cellpadding="0" cellspacing="0" border="0"> <? // Run a While loop for the rows while($c = mysql_fetch_array($result)) { ?> <tr> <td> <?php echo $c['username']; ?> says: <div align="justify"><?php echo $c['message']; ?></div> </td> </tr> <tr><td>on <?php echo $c['date']; ?> <hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr> <? } ?> </table> <form method="post" action="box.php"> <?php $user1 = $_GET['username'];?> <input type=hidden name=username value='<?php echo $user1;?>'> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td>Message :</td> <td> <input type="text" name="message" class="input"></td> </tr> <tr> <td colspan="2"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td> </tr> </table> </form> <?php } ?> </body> </html> at the moment it just goes to a blank page saying <div align="center">Thank you for submitting.<br> Return to the <a href="shoutbox.php">shoutbox</a>! but what i would like it to do is just refresh profile.php Link to comment https://forums.phpfreaks.com/topic/105729-refreshing-just-a-form/ Share on other sites More sharing options...
RichardRotterdam Posted May 15, 2008 Share Posted May 15, 2008 why not just put a redirect on box.php to profile.php or am i thinking to simple here? hmmm ??? Link to comment https://forums.phpfreaks.com/topic/105729-refreshing-just-a-form/#findComment-541716 Share on other sites More sharing options...
runnerjp Posted May 15, 2008 Author Share Posted May 15, 2008 yes but then the form does not get submitted... and if i try and do this box.php <?php // If NOT submitted $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%" cellpadding="0" cellspacing="0" border="0"> <? // Run a While loop for the rows while($c = mysql_fetch_array($result)) { ?> <tr> <td> <?php echo $c['username']; ?> says: <div align="justify"><?php echo $c['message']; ?></div> </td> </tr> <tr><td>on <?php echo $c['date']; ?> <hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr> <? } ?> </table> <?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"> <tr> <td>Message :</td> <td> <input type="text" name="message" class="input"></td> </tr> <tr> <td colspan="2"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td> </tr> </table> </form> and then this page is blank profile.php <?php session_start(); //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!'; die; } // Date format $date = date("d/m/y"); // http://www.php.net/date // Assign variables of the forms // Connect to the database include('../settings.php'); $user = $_POST['username']; $id = $_SESSION['user_id']; $username = get_username($id); $message = $_POST['message']; $ip = $_SERVER['REMOTE_ADDR']; // Insert the info in the shoutbox table. $query = "INSERT INTO shoutbox (`user`, username, message, date, ip) VALUES ('$user','$username','$message','$date','$ip')"; mysql_query($query); // close connection // Show message to let them return to the shoutbox ?><?php require_once '../settings.php'; checkLogin ('1 2'); $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)){ if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; $pid = $array['ID']; $pfirst_name = $array['first_name']; $plast_name = $array['last_name']; $pabout_me = $array['about_me']; $pevents = $array['events']; $pgender = $array['gender']; $pdob = $array['dob']; $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1"; ?> <table width="100%" cellpadding="0" cellspacing="0" bordercolor="#E2E2E2"> <tr> <td colspan="4" align="center" valign="top">Welcome to <strong><?php $fontcolor = ($pgender == "Male") ? "0000FF" : "FF77AA"; echo '<font color="#' . $fontcolor .'">' . $puser . '</font>';?></strong>'s profile</td> </tr> <tr> <td width="21%" rowspan="2" align="center" valign="top"><?php $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q && mysql_num_rows($q) > 0) { $row = mysql_fetch_array($q); if(!empty($row)) { echo "<img src='http://www.runningprofiles.com/members/images/thumbs/". $pid . "." . $row['ext'] . "'"; } else { echo 'no image'; } } ?> </td> <td width="4%" valign="middle" bgcolor="#E2E2E2"><pre>Name: Sex: DOB:</pre></td> <td width="11%" valign="middle" bgcolor="#E2E2E2"><pre><?php echo $pfirst_name; ?> <?php echo $plast_name; ?> <?php $fontcolor = ($pgender == "Male") ? "0000FF" : "FF77AA"; echo '<font color="#' . $fontcolor .'">' . $pgender . '</font>';?> <?php echo $pdob; ?></pre></td> <td width="64%" valign="middle"><?php include 'box.php';?></td> </tr> <tr> <td colspan="3" valign="top"><?php echo "<a href='friendrequest.php?user=$username'>Add as Friend</a>"; ?> </td> </tr> </table> <?php } else { echo "<center>Sorry no users with that name can be found within our database </center><br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); }} ?> then i just get a blank page Link to comment https://forums.phpfreaks.com/topic/105729-refreshing-just-a-form/#findComment-541728 Share on other sites More sharing options...
redarrow Posted May 15, 2008 Share Posted May 15, 2008 No dont sent it to the thank you page, then back to the profile page with the users id in the redirect statement.............. that will display the users current profile ok......... Link to comment https://forums.phpfreaks.com/topic/105729-refreshing-just-a-form/#findComment-541732 Share on other sites More sharing options...
runnerjp Posted May 15, 2008 Author Share Posted May 15, 2008 No dont sent it to the thank you page, then back to the profile page with the users id in the redirect statement.............. that will display the users current profile ok......... sorry that confused me a little Link to comment https://forums.phpfreaks.com/topic/105729-refreshing-just-a-form/#findComment-541734 Share on other sites More sharing options...
runnerjp Posted May 15, 2008 Author Share Posted May 15, 2008 bmp Link to comment https://forums.phpfreaks.com/topic/105729-refreshing-just-a-form/#findComment-541804 Share on other sites More sharing options...
runnerjp Posted May 15, 2008 Author Share Posted May 15, 2008 ok this is my code... as you can see its simple <? //echo $user; this displays the user name but anything below it does not if ( isset($_POST['submit']) ) { // Verify if the fields were filled. // Date format $date = date("d/m/y"); // http://www.php.net/date // Assign variables of the forms // Connect to the database include('../settings.php'); $user = $_POST['username']; $id = $_SESSION['user_id']; $username = get_username($id); $message = $_POST['message']; $ip = $_SERVER['REMOTE_ADDR']; // Insert the info in the shoutbox table. $query = "INSERT INTO shoutbox (`user`, username, message, date, ip) VALUES ('$user','$username','$message','$date','$ip')"; mysql_query($query); // close connection } 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%" cellpadding="0" cellspacing="0" border="0"> <? // Run a While loop for the rows while($c = mysql_fetch_array($result)) { ?> <tr> <td> <?php echo $c['username']; ?> says: <div align="justify"><?php echo $c['message']; ?></div> </td> </tr> <tr><td>on <?php echo $c['date']; ?> <hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr> <? } ?> </table> <?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"> <tr> <td>Message :</td> <td> <input type="text" name="message" class="input"></td> </tr> <tr> <td colspan="2"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td> </tr> </table> </form> <?php } ?> but its not inserting the information into the table... should i be setting the action back to my profile page like so action="<?php echo $user1;?>"> or doing something else 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> Link to comment https://forums.phpfreaks.com/topic/105729-refreshing-just-a-form/#findComment-541870 Share on other sites More sharing options...
runnerjp Posted May 15, 2008 Author Share Posted May 15, 2008 bmp Link to comment https://forums.phpfreaks.com/topic/105729-refreshing-just-a-form/#findComment-541974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.