Jump to content

[SOLVED] posting forms to the same page?


andrew_biggart

Recommended Posts

Right at the minute i have all my forms posting to a seperate page instead of the same page but i want them to post ot there self and i only want the php code to run if the submit button has been pressed but im having trouble.

 

This is my form.

 

	<br />
<img alt="" src="../Layout_images/forum_add.gif" /><br />
<form method="post" action="add_topic_submit.php">
<table class="addtopic_p" style=align="center" align="center">
<tr><td class="postinfo" valign="top">
	Have you got something to tell us? Have you had a <strong>EuReKa
	</strong>moment? or do u just want to tell us a <strong>"This one time at.....!"</strong> story? 
	Feel free to use this page to post your latest events so that all users 
	of weloveweed can see them. 1000&#39;s of members to be precise! <br />
<br />
	<strong>Do not</strong> start to <strong>abuse</strong> this page or
	<strong>spam</strong> like fuck, <strong>abuse other members</strong> 
	or just <strong>post general bullshit </strong>or i will pull the fucking plug. Respect 
	your home or your <strong>OUT 2 FUCK</strong>.
</td></tr>
</table>
<table class="addtopic_now" align="center"><tr>
	<td class="addtopic-pad" valign="top">
	<table>
	<tr><td class="post_h1" colspan="3">Title :</td><td class="post_sub">Max 36 characters</td></tr>
	<tr><td  class="title" colspan="4"><input class="post_title" name="Post_subject" maxlength="36" type="text" /></td></tr>
	<tr><td  class="title" colspan="4"></td></tr>
	<tr><td  class="title" colspan="4"></td></tr>
	<tr><td  class="title" colspan="4"></td></tr>
	<tr><td  class="title" colspan="4"></td></tr>
	<tr><td  class="title" colspan="4"></td></tr>
	<tr><td  class="title" colspan="4"></td></tr>
	<tr><td  class="title" colspan="4"></td></tr>
	<tr><td  class="title" colspan="4"></td></tr>


	<tr><td  class="post_h1">Message :</td>
		<td  class="post_sub" colspan="3">
		Max 2,000 characters</td></tr>
	<tr><td  class="title" colspan="4">
		<textarea class="post_message"name="Post_message" maxlength="2000" cols="48"></textarea></td></tr>
	<tr><td  class="post_h1" colspan="2">Tags :</td><td  class="post_sub" colspan="2">
		Max 200 characters</td></tr>
	<tr><td  class="title" colspan="4">
		<input class="post_tags" name="Post_tags" type="text" maxlength="200" style="width: 395px" /></td></tr>
	<tr><td  class="post_commas" colspan="4">(Make sure and separate your 
		keywords with a comma)</td></tr>
		</table>

	</td></tr></table>

<table style="width: 440px" align="center">
<tr>

	<td class="add-80"><img alt="" src="../Forum_images/forum_logo1.jpg" width="40" height="40" /></td>
	<td class="add-80"><img src="../Forum_images/forum_logo2.jpg" width="40" height="40" /></td>
	<td class="add-80"><img alt="" src="../Forum_images/forum_logo3.jpg" width="40" height="40" /></td>
	<td class="add-80"><img alt="" src="../Forum_images/forum_logo4.jpg" width="40" height="40" /></td>
	<td rowspan="3"><br /></td>
	<td rowspan="3"><br /></td>
	<td rowspan="3"><br />
	<input name="add_topic" type="image" src="../Header_images/addyourtopic.gif" value="submit" width="160" height="60" onmouseout="FP_swapImgRestore()" onmouseover="FP_swapImg(1,1,/*id*/'img2',/*url*/'../Header_images/addyourtopic_h.gif')" /></td>
	<td rowspan="3"> </td>


	</tr>
<tr><td>

		<input name="Radio1" type="radio" checked="checked" value="1" />
	</td><td>
	<input name="Radio2" type="radio" value="2" />
	</td><td>
	<input name="Radio3" type="radio" value="3" />
	</td><td>
	<input name="Radio4" type="radio" value="4" />
	</td></tr>
<tr>
<td class="post_logo" valign="top">Weloveweed</td>
<td class="post_logo">Love/Hate</td>
<td class="post_logo">Problems</td>
<td class="post_logo">Whatever</td></tr>
</table>
</form>

 

and the php code i am trying to use...

 

	<?php

include("config.php");

$Post_username=$_SESSION['myusername'];			
$Post_subject=$_POST['Post_subject'];
$Post_message=$_POST['Post_message'];
$Post_tags=$_POST['Post_tags'];
$Post_pp=$_SESSION['myavatar'];

   	if(isset($_POST['add_topic'])){	
$sql="INSERT INTO User_postT (Post_username, Post_pp, Post_date, Post_subject, Post_message, Post_tags)VALUES('$Post_username', '$Post_pp', NOW(), '$Post_subject', '$Post_message', '$Post_tags')";
$result=mysql_query($sql);}

else{
};


if($result){
echo "<h1 class=comment_status1>Your Post has been added successfully</h1>";
}


// close connection
mysql_close();
?>

 

This is working to an extent as when the page loads it doesnt submit any data but it still echos the your post has been submitted. I only want data and the echo to happen if the submit button has been pressed. please can someone point me in the right direction?

Link to comment
Share on other sites

Got it using this code!

 

	<?php

include("config.php");

  	if(isset($_POST['add_topic'])){	
$Post_username=$_SESSION['myusername'];			
$Post_subject=$_POST['Post_subject'];
$Post_message=$_POST['Post_message'];
$Post_tags=$_POST['Post_tags'];
$Post_pp=$_SESSION['myavatar'];


$sql="INSERT INTO User_postT (Post_username, Post_pp, Post_date, Post_subject, Post_message, Post_tags)VALUES('$Post_username', '$Post_pp', NOW(), '$Post_subject', '$Post_message', '$Post_tags')";
$result=mysql_query($sql);


if($result){
echo "<h1 class=comment_status1>Your Post has been added successfully</h1>";
}


// close connection
mysql_close();
}
else{
};
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.