Jump to content

Telling a php code not to start until the submit button has been pressed?


andrew_biggart

Recommended Posts

I know ive already posted this tonite so sorry but ive been at work and i cant find the post anywere lol

 

But anyway what i want to do is on my form_page.php i dont want the code to run until the submit button has been pressed so that it does not submit empty data into the database as soon as the page loads, im sure theres a simple if statement but my pickled head can think atm lol.

 

Im usuing this code.

 

	<div id="page_content_topic">
<table class="myprofile_change">
<tr><td class="myprofile_changesh">
<tr><td class="reg_status"> 
<?php

   include("config_members_temp.php");
   $recipe_username=$_GET['username'];   
   $recipe_title = ($_POST['recipe_title']);
   $recipe_ingre = ($_POST['recipe_ingre']);
   $recipe_method = ($_POST['recipe_method']);
   $recipe_cat = ($_POST['recipe_cat']);



   $sql = "INSERT INTO User_recipesT ( Recipe_username, Recipe_subject, Recipe_content, Recipe_ingre, Recipe_cat ) VALUES( '$recipe_username', '$recipe_title', '$recipe_method', '$recipe_ingre', '$recipe_cat' )";
   $result=mysql_query($sql) or die(mysql_error().": $sql");
     if($result){
echo "Your recipe has been successfully to our database";
}


// if not found
else {
echo "Ops there has been a problem please go back and try again!";
}

    ?>
    </td></tr>
    </td></tr>
</table>
<form method="post" action="upload_recipe_submit.php?username=<? echo"".$_SESSION["myusername"]."" ?>">
<table class="myprofile_change">
<tr><td class="myprofile_changesh">
<img alt="Cooking cannabis : add a recipe" src="../Header_images/addrecipe.jpg" width="156" height="46" /></td></tr>
<tr><td class="myprofile_subtext2">You are about to add a recipe to the 
	weloveweed mansions achieve. Make sure that your recipe is as sensible 
	as possible without being to dull. Even if its a recipe you have just 
	made up and think that tastes good, add it anyway because other members 
	might like it as well. Once your recipe has been submitted it may take 
	24hrs to show up as it has to be approved by one of our team.</td></tr>
<tr><td></td></tr>
</table>
<br />
<table class="myprofile_change">
<tr><td class="myprofile_subtext">Recipe Title :</td><td class="style3">
	<input name="recipe_title" type="text" /></td><td class="myprofile_max">Max 200 characters</td></tr>
<tr><td class="myprofile_subtext">Recipe cat :</td><td class="style3">
	<select name="recipe_cat" id="Fav"style="width: 126px">
	<option>Choose</option>
	<option>Snack recipes</option>
	<option>Starter recipes</option>
	<option>Main course recipes</option>
	<option>Desert recipes</option>
	<option>Miscellaneous recipes</option>
	</select></td><td class="myprofile_max">Please select one</td></tr>

<tr><td class="myprofile_subtext">Recipe ingredients :</td>
	<td class="style3">
	<textarea name="recipe_ingre" style="width: 355px; height: 76px"></textarea></td><td class="myprofile_max">Max 
	400 characters<br />
	Use <br /> to separate each ingredient.</td></tr>
<tr><td class="myprofile_subtext">Recipe method :</td><td class="style3">
	<textarea name="recipe_method" style="width: 355px; height: 190px" cols="20"></textarea></td><td class="myprofile_max">
	Max 800 characters</td></tr>
<tr><td></td></tr>
<tr><td></td><td></td><td><input name="Reset1" type="reset" value="reset" /><input name="Submit1" type="submit" value="add that shit !" /></td></tr>
<tr><td></td></tr>
</table>
<br />
</form>
</div>

 

Thanks in advance

to find a post check your post history http://www.phpfreaks.com/forums/index.php?action=profile;area=showposts;sa=topics;u=65070

to fix your problem you want a if like this

if(isset($_POST['Sumbit1'])){

around your insert code

 

Scott.

Thanks for your help firstly...

 

ive tried this but i still have the same problem

 

	<?php

   include("config_members_temp.php");
   $recipe_username=$_GET['username'];   
   $recipe_title = ($_POST['recipe_title']);
   $recipe_ingre = ($_POST['recipe_ingre']);
   $recipe_method = ($_POST['recipe_method']);
   $recipe_cat = ($_POST['recipe_cat']);


   if(isset($_POST['Sumbit1'])){
   $sql = "INSERT INTO User_recipesT ( Recipe_username, Recipe_subject, Recipe_content, Recipe_ingre, Recipe_cat ) VALUES( '$recipe_username', '$recipe_title', '$recipe_method', '$recipe_ingre', '$recipe_cat' )";
   $result=mysql_query($sql) or die(mysql_error().": $sql");}
     if($result){
echo "Your recipe has been successfully to our database";
}


// if not found
else {
echo "Ops there has been a problem please go back and try again!";
}

    ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.