green917 Posted December 18, 2009 Share Posted December 18, 2009 Hi all, I'm having some trouble with an issue I've encountered on a page I'm writing. I'm relatively new to php and mysql coding and have set up a simple table and php function that updates my mySql db when the user clicks a submit button in the form. That part of the code is working fine but I would like to add a page redirect on the same button that sends the user to another page which lists the contents of the db table they are updating. I don't want to use an auto redirect for fear that they wont get the information input before the redirect and, when I attempt to place an additional "header: ('Location: ...../...php') call at the end of the function, I get an error that I can't change the header. Any help would be greatly appreciated! Thanks in advance. <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); } ?> Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 18, 2009 Share Posted December 18, 2009 A header should not be sent before any content (ie any PHP tags). If you wish to send a header after the content, which is not 100% correct.. but you must place ob_start after your first opening php tag, without any whitespace beforehand: <?php ob_start(); //Start output buffer for header EDIT: There IS a sticky in this exact forum..... http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
green917 Posted December 18, 2009 Author Share Posted December 18, 2009 Thanks for the help, I realized there was a character before the php tag that was throwing it off but, I wouldn't have even looked for that without your input. Thanks again. Green Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 18, 2009 Share Posted December 18, 2009 Thanks for the help, I realized there was a character before the php tag that was throwing it off but, I wouldn't have even looked for that without your input. Thanks again. Green No problem! Glad I could be of help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.