kenwvs Posted July 19, 2006 Share Posted July 19, 2006 I have a form that gets filled out, and once it is filled out, it is validated. Once there are no errors I need for it to process to a confirmation page (where it actually writes the data to a database) and then you have the opportunity to either complete another form, or retrieve the form you just saved in a csv format (it emails it to you and you can also save it or open it.)I had it working with an HTML form, but needed to convert to a php form for the validation aspect.The way I vision it working (and beleive it should work) is that you complete the form (uploadform.html) and when you press submit, it runs the validation using the data in the original form, along with the functions that are working (functions.php). Once it has no errors it saves the data to a database (using this form, upload2.php) which automatically takes you to the confirmation page, and you can then either repeat the process or have the results sent back to you in a csv format (uploadresults.php). I hope this makes sense..... the problem I am having is that I can't get it to save the data to the database, and am not sure where I should have the header to have it work properly. I have it where I thought it would work, but it isn't doing anything. I would appreciate any help you may have.Here is the code for the form, I have shortened it due to length, only removing some options available in the categories section.[code]<?php/* uploadform.php */require_once ('functions.php');$categories = array("000" =>'Please Select Category', "150" =>'Antiques', 113 =>"Arts and Crafts", 20 =>"Automobiles - Antique Vehicles", 18 =>"Automobiles - Cars", 21 =>"Automobiles - Hot Rod Vehicles", 19 =>"Automobiles - Trucks", 52 =>"Automotive Parts and Accessories - New Parts", 51 =>"Automotive Parts and Accessories - Used Parts", 134 =>"Automotive Stereos and Radar Detectors", 140 =>"Bicycles - Single Speed", 148 =>"Tools", 138 =>"Toys", 46 =>"Upcoming Events - Coaldale", 47 =>"Upcoming Events - Coalhurst", 49 =>"Upcoming Events - Fort McLeod", 45 =>"Upcoming Events - Lethbridge", 48 =>"Upcoming Events - Taber", 50 =>"Upcoming Events - Surrounding Areas", 128 =>"WANT ADS");$valid = TRUE;$err = array();$err_msg = array();$funcs = array('id'=>'LettersAndDigits', 'item_title' => 'Variable', 'item_category'=>'ItemCategory', 'item_type' => 'Variable', 'quantity_available' => 'isDigits', 'starting_bid' => 'Dollars', 'bid_increment' => 'BidIncrement', 'reserve_price' => 'ReservePrice', 'duration' => 'isDigits', 'end_time' => 'isDigits', 'auto_relist' => 'isLetters', 'city' => 'Variable', 'state' => 'Variable', 'country' => 'Variable', 'item_description' => 'Variable', 'paypal_id' => 'EmailorEmpty', 'hit_counter' => 'Variable');$hc = array(0=> 'No Counter', 1=> 'Style 1', 2=> 'Style 2', 3=> 'Style 3');$itemType = array(1=> 'Auction', 2=> 'Dutch Auction', 3=> 'Fixed Price', 4=> 'Classified Ad');$countries = array(32=>'Canada',210=>'USA');$yesno = array(1=>'Yes',0=>'No');$hours = array(24 =>'12:00 a.m.', 1 =>'1:00 a.m.', 2 =>'2:00 a.m.', 3 =>'3:00 a.m.', 4 =>'4:00 a.m.', 5 =>'5:00 a.m.', 6 =>'6:00 a.m.', 7 =>'7:00 a.m.', 8 =>'8:00 a.m.', 9 =>'9:00 a.m.', 10 =>'10:00 a.m.', 11 =>'11:00 a.m.', 12 =>'12:00 p.m.', 13 =>'1:00 p.m.', 14 =>'2:00 p.m.', 15 =>'3:00 p.m.', 16 =>'4:00 p.m.', 17 =>'5:00 p.m.', 18 =>'6:00 p.m.', 19 =>'7:00 p.m.', 20 =>'8:00 p.m.', 21 =>'9:00 p.m.', 22 =>'10:00 p.m.', 23 =>'11:00 p.m.');if (isset ($_POST['Submit'])) { foreach($_POST as $key=>$val) { if ($key != 'Submit') switch ($funcs[$key]) { case 'LettersAndDigits': if (!LettersAndDigits($val)) $err[] = $key; break; case 'Variable': if (!Variable($val)) $err[] = $key; break; case 'Dollars': if (!Dollars($val)) $err[] = $key; break; case 'ItemCategory': $ic = ItemCategory($val); if (!$ic[0]) { $err[] = $key; $err_msg[$key] = $ic[1]; } break; case 'isDigits': if (!isDigits($val)) $err[] = $key; break; case 'EmailorEmpty': if (!EmailorEmpty($val)) $err[] = stripslashes($key); break; case 'BidIncrement': $bi = BidIncrement($val,$itemType[$_POST['item_type']]); if (!$bi[0]) { $err[] = $key; $err_msg[$key] = $bi[1]; } break; case 'ReservePrice': $rp = ReservePrice($val,$itemType[$_POST['item_type']]); if (!$rp[0]) { $err[] = $key; $err_msg[$key] = $rp[1]; } break; if ($valid) { header ("upload2.php"); exit; } if (!empty($err)) $valid = false; } } }function disp_val($idx) { $retv = ''; if (isset($_POST[$idx])) $retv = stripslashes($_POST[$idx]); return($retv);}function is_selected($it,$val,$def='') { if (isset($_POST[$it])) $ret =($_POST[$it] == $val)?' selected ':''; else $ret = ($val == $def)?' selected':''; return($ret);}function disp_options($opt_array,$fld,$def,$for_type) { $tmp = array(); if ($for_type) foreach ($opt_array as $key=>$val) $tmp[] = '<option value="' . $key . '"' . is_selected($fld,$key,$def) . '>' . $val . '</option>'; else for ($i=0;$i<count($opt_array);$i++) $tmp[] = '<option value="' . $i . '"' . is_selected($fld,$i,$def) . '>' . $opt_array[$i] . '</option>'; echo "\t\t" . implode("\n\t\t",$tmp) . "\n";}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>For Sale 4 U QUICK LISTER</title><style type="text/css">body { background-color: Gainsboro; margin: 0; padding: 0; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 72%; color: black;}table { width: 96%; display: block; margin-left: auto; margin-right: auto;}form { width: 98%; display: block; margin-left: auto; margin-right: auto;}.red { color: Red;}.error {color:#C03; font-weight:bold; }h3 { text-align: center; color: Red; font-weight: bold;}h4 { text-align: center; color: Blue; font-weight: bold;} .center { text-align: center; } .bold { font-weight: bold; }</style></head><body><h3>Quick Lister</h3><p class="center"><span class="red">For Sale 4 U - Canada's Online Auction</span></p><p class="center"><span class="bold">Please note: </span>You maynot use characters such as $, #, ", &, *,/, etc. It is best to use normaltext and numerical characters only. <BR><BR><BR><?php$trace = array();if (!$valid) {?><h4>Please correct the items in <span class="error">red</span> and resubmit.<br /><br /> </h4><?php}?><HR><form method="POST" action="uploadform.php"><table><tr> <td valign="top" <?php if(in_array('id',$err)) echo 'class="error"'; ?>> User ID:</td> <td><input type="text" name="id" size="12" value="<?php echo disp_val('id') ?>"><br> You must use the <span class="bold">same User ID</span> for all items you are uploading during this session.(It does not have to be your regular username.)</td></tr><tr> <td <?php if(in_array('item_title',$err)) echo 'class="error"'; ?>> Item Title:</td> <td><input type="text" name="item_title" size="60" value="<?php echo disp_val('item_title'); ?>"</td></tr><tr> <td <?php if(in_array('item_category',$err)) echo 'class="error"'; ?>>Item Category:</td> <td> <select size="1" name="item_category"> <?php disp_options($categories,'item_category','',true) ?> </select> <? if (isset($err_msg['item_category'])) echo ' <span class="error">' . $err_msg['item_category'] . '</span>'; ?> </td></p></tr><tr> <td <?php if(in_array('item_type',$err)) echo 'class="error"'; ?>>Item Type:</td> <td><select size="1" name="item_type"> <?php $tmp = array(); for ($i=1;$i<count($itemType)+1;$i++) $tmp[] = '<option value="' . $i . '"' . is_selected('item_type',$i,0) . '>' . $itemType[$i] . '</option>'; echo "\t\t" . implode("\n\t\t",$tmp) . "\n"; ?> </td></select></tr><tr><td <?php if(in_array('quantity_available',$err)) echo 'class="error"'; ?>>Quantity:</td> <td><input type="text" name="quantity_available" size="3" value="<?php echo disp_val('quantity_available') ?>"</td></tr></tr><tr> <td <?php if(in_array('starting_bid',$err)) echo 'class="error"'; ?>>Starting Bid:</td> <td> <input type="text" name="starting_bid" size="7" value="<?php echo disp_val('starting_bid') ?>"></td></tr><tr> <td <?php if(in_array('bid_increment',$err)) echo 'class="error"'; ?>>Bid Increment (auction only):</td> <td><input type="text" name="bid_increment" size="7" value="<?php echo disp_val('bid_increment') ?>"><? if (isset($err_msg['bid_increment'])) echo ' <span class="error">' . $err_msg['bid_increment'] . '</span>'; ?></td></tr><tr> <td <?php if(in_array('reserve_price',$err)) echo 'class="error"'; ?>>Reserve Bid (auction only ):</td> <td><input type="text" name="reserve_price" size="7" value="<?php echo disp_val('reserve_price') ?>"><? if (isset($err_msg['reserve_price'])) echo ' <span class="error">' . $err_msg['reserve_price'] . '</span>'; ?></td></tr><tr> <td <?php if(in_array('duration',$err)) echo 'class="error"'; ?>>Ad Duration:</td> <td><select size="1" name="duration"> <?php $tmp = array(); for ($d=1;$d<31;$d++) $tmp[] = '<option value="' . $d . '"' . is_selected('duration',$d,'14') .'>' . $d . '</option>'; echo "\t\t" . implode("\n\t\t",$tmp) . "\n"; ?> </select> </td></tr><tr> <td <?php if(in_array('end_hour',$err)) echo 'class="error"'; ?>>End Time:</td> <td> <select size="1" name="end_hour"> <?php disp_options($hours,'end_hour',20,true); ?> </select> </td></tr> <tr><td <?php if(in_array('auto_relist',$err)) echo 'class="error"'; ?>>Auto Relist:</td> <td><select size="1" name="auto_relist"> <?php disp_options($yesno,'auto_relist',1,true); ?> </select> </td></tr><tr> <td <?php if(in_array('city',$err)) echo 'class="error"'; ?>>City:</td> <td><input type="text" name="city" size="15" value="<?php echo disp_val('city') ?>"> </td></tr><tr> <td <?php if(in_array('state',$err)) echo 'class="error"'; ?>>Province/State:</td> <td><input type="text" name="state" size="10" value="<?php echo disp_val('state') ?>"></td></tr><tr> <td <?php if(in_array('country',$err)) echo 'class="error"'; ?>>Country:</td> <td><select size="1" name="country"> <?php disp_options($countries,'country',32,true) ?> </select> </td></tr><tr> <td valign="top" <?php if(in_array('item_description',$err)) echo 'class="error"'; ?>>Item Description:</td> <td colspan=8><textarea rows="4" name="item_description" cols="116"><?php echo disp_val('item_description') ?></textarea></td></tr><tr> <td <?php if(in_array('paypal_id',$err)) echo 'class="error"'; ?>>Paypal ID (Optional):</td> <td><input type="text" name="paypal_id" size="25" value="<?php echo disp_val('paypal_id') ?>"></tr><tr> <td <?php if(in_array('hit_counter',$err)) echo 'class="error"'; ?>>Hit Counter:</td> <td><select size="1" name="hit_counter"> <?php disp_options($hc,'hit_counter',0,true); ?> </select> </td></tr></tr> <td colspan="2"><hr></td><tr><tr> <td colspan="5" class="center"> <span class="bold"><br>Please verify all details shown for your item before pressing the SAVE button.</span> </td></tr><tr> <td colspan="5" class="center"><br><input type="submit" name="Submit" value="SAVE ITEM"></td></tr><tr> <td colspan="2" class="center"><BR>You will be guided through this Multi Step Process. Please be sure to use the <span class="bold">same User ID</span> when entering your items or they will not all be listed correctly.</font></p> </td></tr></table></form></body></html>[/code]This is the code for the file (upload2.php) that I am trying to get the form to open up to.[code]<?php$flds = array('item_title','item_category','item_type','quantity_available','starting_bid/price','bid_increment','reserve_price','duration','auto_relist','city','state','country','item_description','paypal_id','hit_counter','end_hour');$write_to_csv = 'UploadForm/' . $_POST['id'] . '.csv';if (!file_exists($write_to_csv)) { // only write the header if the file doesn't already exist $fp = fopen($write_to_csv,'a'); fwrite($fp,implode(',',$flds)."\n"); // write the field names separated by commas fclose($fp); }$fp = fopen($write_to_csv,'a');$tmp = array();foreach($flds as $fld) $tmp[] = '"' . $_POST[$fld] . '"'; //these quotes are single-double-singlefwrite($fp,implode(',',$tmp)."\n"); // write to the filefclose($fp);header("Location: http://www.forsale4u.ca/uploadformconfirmation.html");?>[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/ Share on other sites More sharing options...
hitman6003 Posted July 19, 2006 Share Posted July 19, 2006 Change:[code]header ("upload2.php");[/code]to[code]header ("Location: upload2.php");[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60706 Share on other sites More sharing options...
ShogunWarrior Posted July 19, 2006 Share Posted July 19, 2006 Those codes look VERY similar hitman. Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60712 Share on other sites More sharing options...
hitman6003 Posted July 19, 2006 Share Posted July 19, 2006 hehe, good point...edited!! Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60713 Share on other sites More sharing options...
kenwvs Posted July 19, 2006 Author Share Posted July 19, 2006 I made the change you suggested, and here is what it looks like now, but I am still having the same problem with it not processing the page. Any other suggestions what might resolve this.On a totally different topic, can you suggest what would be a good project to start, to learn the real basics of PHP..... I want to learn this, but am having trouble understanding it, so I thought if I did a project (basic) from the start it might start to make more sense. [code]if ($valid) { header ("Location: upload2.php"); exit; } if (!empty($err)) $valid = false; } } }[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60714 Share on other sites More sharing options...
kenwvs Posted July 19, 2006 Author Share Posted July 19, 2006 I was able to figure out what hitman meant.... Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60715 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 [quote]the problem I am having is that I can't get it to save the data to the database[/quote]You realize that at no point in upload2.php are you connecting to, or performing any queries on, a database? That's kind of important for saving data to a db. Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60717 Share on other sites More sharing options...
kenwvs Posted July 20, 2006 Author Share Posted July 20, 2006 My apologies........ it isn't a database. What is actually does is saves the data from the form, to a csv file in a directory called upload and then from another code (page) you call for it to email the csv file back to you. This is done so you can upload multiple items to the auction site (an alternative to EBAY auction) It is easier than creating a csv file from a spreadsheet if you have no idea how to do it.This does work, as I have it set up and working with a file called uploadform.html, but I don't have the validation that I want and this php file does the validation, but I can't get it to go to the upload2.php page.Ken Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60718 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 When the form is submitted, what is happening? Does it progress to uploadformconfirmation.html without writing the csv file? Or does it simply redisplay the form for entry?If it is doing the former, check to make sure that write permissions are set on the directory. Also turn error reporting and display errors on to make sure you are getting any file writing errors returned. I don't see why it would be doing the latter if you fixed the header.At the top of your page:[code]ini_set("error_reporting", "E_ALL");ini_set("display_errors", 1);[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60722 Share on other sites More sharing options...
kenwvs Posted July 20, 2006 Author Share Posted July 20, 2006 If I understand what you are asking, this is what i believe is happening. When you press submit, it creates a file (in upload directory) named whatever user id you have provided on the form. Then it automatically takes you to uploadformconfirmation.html, from where you select to either return to uploadform.php (currently going to uploadform.html) or go to uploadresults.php which is where you provide an email address to receive the csv file and are also provided the choice of opening or saving the file on your own computer. I am including below, the code for the uploadresults.php The only page that has changed throughout this is the uploadform.html to uploadform.php, and I am not sure why I can't get the form to process.[code]<?phpif(!isset($_REQUEST['submit'])){?><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>For Sale 4 U - Canada's Online Auction - Upload Form Results</title></head><p align="center"><font size="5" color="#0000FF"><b>Quick Lister <BR><p align="center"> <font size="4" color="#FF0000"> For Sale 4 U - Canada's Online Auction <BR><p align="center"><font size="3" color="#0000FF"> Request CSV File</b></font> </color></p><p align="center"><font size="3" color="#000000">You are just a few minutes away from having your files uploaded and your listing completed.Once you have received this file, you will need to follow the steps below to complete the listing of your items. </b></font> </color></p><HR><form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"enctype="multipart/form-data"><table><tr><td>Email Address:</td><td><input type="text" name="to" size="40"/> <font size="3" color="#000000"> Please check that this email address is correct as your file will be sent to this address.</td></tr><tr><td></td><td><input type="hidden" name="from" value="For Sale 4 U" size="40" /></td></tr><tr><td></td><td><input type="hidden" name="re" value="Upload Form Results" size="40" /></td></tr><tr><td></td><td><input type="hidden" name="comments" value="Attached to this message is the file you just created to list your multiple items. Please follow the instructions below to complete the listing of your items.1. Go to www.forsale4u.ca and log in using your regular username and password.2. On the left side of the screen, select Post Multiple Items.3. Browse for the file you have just received from this screen and select it.4. Select Insert5. On the left side of the screen, select My Uploaded Items and review them individually for accuracy. Make any required changes.6. Select the items you wish to list, and press Post Items.7. Watch them Sell!! " size="300" /></td></tr><tr><td>User ID:</td><td><input type="text" name="id" size="40" /> <font size="3" color="#000000"> Please insert the same User ID that you used when entering your items.</td></tr><td colspan="2"><input type="submit" name="submit" value="Send Form" /></td></tr></table></form><p align="center"> <font size="3" color="#FF0000"><b>Please be sure to save yourfile as they are deleted from our server on a regular basis. If you use the <font size="3" color="0000FF">Quick Lister <font size="3" color="FF0000"> to add more listings in the next few weeks, it is recommended that you use a different User ID to prevent items from being listed more than once.</font></b></p><hr><p align="center"> <font size="2" color="0000FF">If an error occurs and you do not receive your file, please send an <b> <a href="mailto:[email protected]?subject=Missing Upload File"> <font color="#FF0000">EMAIL</font></a><font color="#FF0000"> </font></b>with your User ID included in the body of the message and we will manually send a copy of the file to you as soon as possible.</p><?php}else{extract($_POST); $filename = "UploadForm/" . $_POST['id'] . ".csv"; $handle = fopen("$filename","r") or die("can't create file"); $content = fread($handle, filesize($filename)); /*The following lines deal with the save feature ofthe file. I am trying to use the $filename $handle and $content locatedon line 61 62 63 and 110 to not duplicate this process*/header("Location:/$filename"); /*Encode The Data For Transition using base64_encode();And get a 32-character hexadecimal number*/ $content = chunk_split(base64_encode($content)); $num = md5( time() ); /*Define the main message headers*/ $hdr = "From:".$_REQUEST['from']."\r\n"; $hdr .= "MIME-Version: 1.0\r\n"; $hdr .= "Content-Type: multipart/mixed; "; $hdr .= "boundary=".$num."\r\n"; $hdr .= "--$num\r\n";/*Define message section*/ $hdr .= "Content-Type: text/plain\r\n"; $hdr .= "Content-Transfer-Encoding: 8bit\r\n\n"; $hdr .= "".$_REQUEST['comments']."\r\n"; $hdr .= "--".$num."\n"; /*Define the attachment section*/ //$hdr .= "Content-Type:". $filename_type." "; //$hdr .= "name=\"".$filename_name."\"r\n"; $hdr .= "Content-Transfer-Encoding: base64\r\n"; $hdr .= "Content-Disposition: attachment; "; $hdr .= "filename=\"".$filename."\"\r\n\n"; $hdr .= "".$content."\r\n"; $hdr .= "--".$num."--"; /*Send the email*/ mail( $_REQUEST['to'], $_REQUEST['re'], $_REQUEST['comments'], $hdr); /*Close the attachment*/ fclose($handle);echo "Mail sent...";}?> [/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60724 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 I think you may be missing the closing curly brace ( } ) for your switch statement:[code]case 'ReservePrice': $rp = ReservePrice($val,$itemType[$_POST['item_type']]); if (!$rp[0]) { $err[] = $key; $err_msg[$key] = $rp[1]; } break; } // <-------- if ($valid) { header ("upload2.php"); exit; }[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60731 Share on other sites More sharing options...
kenwvs Posted July 20, 2006 Author Share Posted July 20, 2006 I hate to argue, but I have checked to make sure that all the brackets are matched up, and they are. I have added it, and when I do, I get an error that tells me Parse error: parse error, unexpected '}' in C:\wamp\www\uploadform.php on line 234 Line 234 is the last line with the bracket, shown below.This is leading me to think the brackets are all there, but is it possible, they aren't in the right spot?[code]if (isset ($_POST['Submit'])) { foreach($_POST as $key=>$val) { if ($key != 'Submit') switch ($funcs[$key]) { case 'LettersAndDigits': if (!LettersAndDigits($val)) $err[] = $key; break; case 'Variable': if (!Variable($val)) $err[] = $key; break; case 'Dollars': if (!Dollars($val)) $err[] = $key; break; case 'ItemCategory': $ic = ItemCategory($val); if (!$ic[0]) { $err[] = $key; $err_msg[$key] = $ic[1]; } break; case 'isDigits': if (!isDigits($val)) $err[] = $key; break; case 'EmailorEmpty': if (!EmailorEmpty($val)) $err[] = stripslashes($key); break; case 'BidIncrement': $bi = BidIncrement($val,$itemType[$_POST['item_type']]); if (!$bi[0]) { $err[] = $key; $err_msg[$key] = $bi[1]; } break; case 'ReservePrice': $rp = ReservePrice($val,$itemType[$_POST['item_type']]); if (!$rp[0]) { $err[] = $key; $err_msg[$key] = $rp[1]; } break; } if ($valid) { header ("Location: upload2.php"); exit; } if (!empty($err)) $valid = false; } } }[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60734 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 I think I see what's happening...of course I've thought that before......The way you have the header positioned and the $valid = false means that $valid is never being set, to true or false, so your if statement is never evaluating.[code]if (isset ($_POST['Submit'])) { $valid = true; foreach($_POST as $key=>$val) { if ($key != 'Submit') { switch ($funcs[$key]) { case 'LettersAndDigits': if (!LettersAndDigits($val)) $err[] = $key; break; case 'Variable': if (!Variable($val)) $err[] = $key; break; case 'Dollars': if (!Dollars($val)) $err[] = $key; break; case 'ItemCategory': $ic = ItemCategory($val); if (!$ic[0]) { $err[] = $key; $err_msg[$key] = $ic[1]; } break; case 'isDigits': if (!isDigits($val)) $err[] = $key; break; case 'EmailorEmpty': if (!EmailorEmpty($val)) $err[] = stripslashes($key); break; case 'BidIncrement': $bi = BidIncrement($val,$itemType[$_POST['item_type']]); if (!$bi[0]) { $err[] = $key; $err_msg[$key] = $bi[1]; } break; case 'ReservePrice': $rp = ReservePrice($val,$itemType[$_POST['item_type']]); if (!$rp[0]) { $err[] = $key; $err_msg[$key] = $rp[1]; } break; } } if (!empty($err)) $valid = false; } if ($valid) { header ("Location: upload2.php"); exit; }}[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60735 Share on other sites More sharing options...
kenwvs Posted July 20, 2006 Author Share Posted July 20, 2006 If I had any hair on my head (well, I have a little but not enough) I would be pulling it out right now. I have had these lines in this position before and got the same error as below......and I am not sure how to deal with it........throwing this project in the garbage may be the answer yet....except I love what this code does......Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\functions.php:155) in C:\wamp\www\uploadform.php on line 231 Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60737 Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 try it in reverse lol...........if (!$valid) {}else{header ("Location: upload2.php");exit;} Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60739 Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 orif ($valid==true) {header ("Location: upload2.php");exit;} Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60740 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 You get the "Cannon modify header information..." error when somethign has been output to the browser before the "header..." line. Make sure that there are no echo statements, print statements, no [code]<?php ... ?> some text or whitespace <?php header ... ?>[/code]statements above the header line.Some people will tell you to use output buffering, however I would not recommend it. It doesn't really solve the problem, just avoids it. Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60742 Share on other sites More sharing options...
kenwvs Posted July 20, 2006 Author Share Posted July 20, 2006 Ok, a little more hair is gone, FYI, neither attempt at changing the order of the header worked, so now I will look for some other type of output. My question is "If there is some output prior to this header, will I be able to get this to work?" Can you please clarify wha whitespace is. I beleive echo is wherever it may say echo, and the print would be the print command, bu need help on what the whitespace or text is ....Thanks,Ken Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60745 Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 <?no whight space?><?with whight space?>whight space is when the end php?> tag has space before a statement Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60747 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 redarrow kind of had it correct...he displayed a correct example but I don't think he realized it:[code]<?no whight space?> -- if this text were not here, this would be the white space I'm referring to<?with whight space//this won't matter, because it's not being sent to the browser, the above is sent...as a new line if it is completely blank?>[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60750 Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 [code]if (isset ($_POST['Submit'])) { $valid = true; foreach($_POST as $key=>$val) { if ($key != 'Submit') { switch ($funcs[$key]) { case 'LettersAndDigits': if (!LettersAndDigits($val)) $err[] = $key; break; case 'Variable': if (!Variable($val)) $err[] = $key; break; case 'Dollars': if (!Dollars($val)) $err[] = $key; break; case 'ItemCategory': $ic = ItemCategory($val); if (!$ic[0]) { $err[] = $key; $err_msg[$key] = $ic[1]; } break; case 'isDigits': if (!isDigits($val)) $err[] = $key; break; case 'EmailorEmpty': if (!EmailorEmpty($val)) $err[] = stripslashes($key); break; case 'BidIncrement': $bi = BidIncrement($val,$itemType[$_POST['item_type']]); if (!$bi[0]) { $err[] = $key; $err_msg[$key] = $bi[1]; } break; case 'ReservePrice': $rp = ReservePrice($val,$itemType[$_POST['item_type']]); if (!$rp[0]) { $err[] = $key; $err_msg[$key] = $rp[1]; } break; } } if (!empty($err)) $valid = false; } if ($valid) {?> <script type="text/javascript"> window.location.href='upload2.php'; </script><? exit; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60755 Share on other sites More sharing options...
kenwvs Posted July 20, 2006 Author Share Posted July 20, 2006 Sorry to sound stupid, but the only line that matters is the line directly above the end php?> statement If there is space in other lines then it is ok. I have tried reading through the PHP manual (or whateveri t is called) and find it confusing. Is there a tutorial where you actually build something that would make it all clearer. Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60756 Share on other sites More sharing options...
kenwvs Posted July 20, 2006 Author Share Posted July 20, 2006 RedArrow - Could you explain for me what you have changed in your last post. I appreciate that you have changed the header info, but can you tell me why and what the difference will be (other than it will work) I am really trying to understand this, not just change it, although I do appreciate the thought of getting it to work. Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60757 Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 did my code work cheers. Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60758 Share on other sites More sharing options...
kenwvs Posted July 20, 2006 Author Share Posted July 20, 2006 this produces the following error.......it is two lines after the last line of </html>Parse error: parse error, unexpected $end in C:\wamp\www\uploadform.php on line 457 Link to comment https://forums.phpfreaks.com/topic/15087-php-form-not-processing/#findComment-60759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.