Jump to content

Having trouble appending a page redirect to a php function


Recommended Posts

Hi there,

I am relatively new to php and mysql and am attempting to create a database update script for my website. I have a table with a php function to update the database with a new recipe. I would like, however, to redirect the page to another page containing a list of what's in the database when the user clicks "submit" to upload the new recipe. I don't want to use an automatic redirect (meta tag) but, I can't make header: ('.../...php'); work. Code follows and any help would be greatly appreciated. Please feel free to contact me at my email listed on my profile here. Thanks again!

 

Green

 

Code:

<form method="post">
<table cellpadding="2" cellspacing="1" align="center" width="960">
<th colspan="8">Add Recipe:</th>
<tr>
<td width="100">Title</td><td><input name="title" type="text" /></td>
</tr>
<tr>
<td width="100">description</td><td colspan="4"><textarea name="desc" cols="50" rows="5"></textarea></td>
</tr>
<tr>
<td width="100">Ingr. 1</td><td><input name="ingr1" type="text" /></td>
    <td width="100">Ingr. 2</td><td><input name="ingr2" type="text" /></td>
    <td width="100">Ingr. 3</td><td><input name="ingr3" type="text" /></td>
    <td width="100">Ingr. 4</td><td><input name="ingr4" type="text" /></td>
</tr>
<tr>
<td width="100">Ingr. 5</td><td><input name="ingr5" type="text" /></td>
    <td width="100">Ingr. 6</td><td><input name="ingr6" type="text" /></td>
    <td width="100">Ingr. 7</td><td><input name="ingr7" type="text" /></td>
    <td width="100">Ingr. 8</td><td><input name="ingr8" type="text" /></td>
</tr>
<tr>
<td width="100">Ingr. 9</td><td><input name="ingr9" type="text" /></td>
    <td width="100">Ingr. 10</td><td><input name="ingr10" type="text" /></td>
    <td width="100">Ingr. 11</td><td><input name="ingr11" type="text" /></td>
    <td width="100">Ingr. 12</td><td><input name="ingr12" type="text" /></td>
</tr>
<tr>
<td width="100">Ingr. 13</td><td><input name="ingr13" type="text" /></td>
    <td width="100">Ingr. 14</td><td><input name="ingr14" type="text" /></td>
    <td width="100">Ingr. 15</td><td><input name="ingr15" type="text" /></td>
    <td width="100">Ingr. 16</td><td><input name="ingr16" type="text" /></td>
</tr>
<tr>
<td width="100">Ingr. 17</td><td><input name="ingr17" type="text" /></td>
    <td width="100">Ingr. 18</td><td><input name="ingr18" type="text" /></td>
    <td width="100">Ingr. 19</td><td><input name="ingr19" type="text" /></td>
    <td width="100">Ingr. 20</td><td><input name="ingr20" type="text" /></td>
</tr>
<tr>
<td width="100">Ingr. 21</td><td><input name="ingr21" type="text" /></td>
    <td width="100">Ingr. 22</td><td><input name="ingr22" type="text" /></td>
    <td width="100">Ingr. 23</td><td><input name="ingr23" type="text" /></td>
    <td width="100">Ingr. 24</td><td><input name="ingr24" type="text" /></td>
</tr>
<tr>
<td width="100">Ingr. 25</td><td><input name="ingr25" type="text" /></td>
</tr>
<tr>
<td width="100">Instructions</td>
<td colspan="8"><textarea name="instructions" cols="104" rows="10"></textarea></td>
</tr>
<tr>
<td width="100">Cals/serving</td><td><input name="cps" type="text" /></td>
    <td width="100">serving size</td><td><input name="ss" type="text" /></td>
    <td width="100">Calories</td><td><input name="cal" type="text" /></td>
    <td width="100">Total fat</td><td><input name="fat" type="text" /></td>
</tr>
<tr>
<td width="100">Saturated fat</td><td><input name="satfat" type="text" /></td>
    <td width="100">Carbohydrates</td><td><input name="carbs" type="text" /></td>
    <td width="100">Sugar</td><td><input name="sugar" type="text" /></td>
    <td width="100">Sodium</td><td><input name="sodium" type="text" /></td>
</tr>
<tr>
<td width="100">protein</td><td><input name="protein" type="text" /></td>
    <td width="100">fiber</td><td><input name="fiber" type="text" /></td>
</tr>
<tr>
<td colspan="8" align="center"><input name="update" type="submit" value="add recipe" onclick="Javascript:move();" /></td>
</tr>
</table>
</form>

<?php
if(isset($_POST['update']))
{
$title=$_POST['title'];
$desc=$_POST['desc'];
$ingr1=$_POST['ingr1'];
$ingr2=$_POST['ingr2'];
$ingr3=$_POST['ingr3'];
$ingr4=$_POST['ingr4'];
$ingr5=$_POST['ingr5'];
$ingr6=$_POST['ingr6'];
$ingr7=$_POST['ingr7'];
$ingr8=$_POST['ingr8'];
$ingr9=$_POST['ingr9'];
$ingr10=$_POST['ingr10'];
$ingr11=$_POST['ingr11'];
$ingr12=$_POST['ingr12'];
$ingr13=$_POST['ingr13'];
$ingr14=$_POST['ingr14'];
$ingr15=$_POST['ingr15'];
$ingr16=$_POST['ingr16'];
$ingr17=$_POST['ingr17'];
$ingr18=$_POST['ingr18'];
$ingr19=$_POST['ingr19'];
$ingr20=$_POST['ingr20'];
$ingr21=$_POST['ingr21'];
$ingr22=$_POST['ingr22'];
$ingr23=$_POST['ingr23'];
$ingr24=$_POST['ingr24'];
$ingr25=$_POST['ingr25'];
$instructions=$_POST['instructions'];
$cps=$_POST['cps'];
$ss=$_POST['ss'];
$cal=$_POST['cal'];
$fat=$_POST['fat'];
$satfat=$_POST['satfat'];
$carbs=$_POST['carbs'];
$sugar=$_POST['sugar'];
$sodium=$_POST['sodium'];
$protein=$_POST['protein'];
$fiber=$_POST['fiber'];

if(!get_magic_quotes_gpc())
{
$title=addslashes($title);
$desc=addslashes($desc);
$ingr1=addslashes($ingr1);
$ingr2=addslashes($ingr2);
$ingr3=addslashes($ingr3);
$ingr4=addslashes($ingr4);
$ingr5=addslashes($ingr5);
$ingr6=addslashes($ingr6);
$ingr7=addslashes($ingr7);
$ingr8=addslashes($ingr8);
$ingr9=addslashes($ingr9);
$ingr10=addslashes($ingr10);
$ingr11=addslashes($ingr11);
$ingr12=addslashes($ingr12);
$ingr13=addslashes($ingr13);
$ingr14=addslashes($ingr14);
$ingr15=addslashes($ingr15);
$ingr16=addslashes($ingr16);
$ingr17=addslashes($ingr17);
$ingr18=addslashes($ingr18);
$ingr19=addslashes($ingr19);
$ingr20=addslashes($ingr20);
$ingr21=addslashes($ingr21);
$ingr22=addslashes($ingr22);
$ingr23=addslashes($ingr23);
$ingr24=addslashes($ingr24);
$ingr25=addslashes($ingr25);
$instructions=addslashes($instructions);
$cps=addslashes($cps);
$ss=addslashes($ss);
$cal=addslashes($cal);
$fat=addslashes($fat);
$satfat=addslashes($satfat);
$carbs=addslashes($carbs);
$sugar=addslashes($sugar);
$sodium=addslashes($sodium);
$protein=addslashes($protein);
$fiber=addslashes($fiber);
}
include 'config.php';

$query= "INSERT INTO recipes (title, description, ingr_1, ingr_2, ingr_3, ingr_4, ingr_5, ingr_6, ingr_7, ingr_8, ingr_9, ingr_10, ingr_11, ingr_12, ingr_13, ingr_14, ingr_15, ingr_16, ingr_17, ingr_18, ingr_19, ingr_20, ingr_21, ingr_22, ingr_23, ingr_24, ingr_25, instructions, cps, ss, cal, fat, satfat, carbs, sugar, sodium, protein, fiber)"."VALUES ('$title', '$description', '$ingr_1', '$ingr_2', '$ingr_3', '$ingr_4', '$ingr_5', '$ingr_6', '$ingr_7', '$ingr_8', '$ingr_9', '$ingr_10', '$ingr_11', '$ingr_12', '$ingr_13', '$ingr_14', '$ingr_15', '$ingr_16', '$ingr_17', '$ingr_18', '$ingr_19', '$ingr_20', '$ingr_21', '$ingr_22', '$ingr_23', '$ingr_24', '$ingr_25', '$instructions', '$cps', '$ss', '$cal', '$fat', '$satfat', '$carbs', '$sugar', '$sodium', '$protein', '$fiber')";
mysql_query($query) or die('Error ,query failed');

mysql_close($link);

}

?>

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.