ra2833 Posted January 20, 2007 Share Posted January 20, 2007 Hi (plz let me know if you need more code),what i would like to accomplish is have one button that will send all of my form information to the dbi understand that i can "not" embed <form> tags but how do i go about combining two different forms with one submit button?i have attempt "if" statements but i can't seem to get to work. any help is greatly appreciated:i have this:[code]<form id="form1" name="form1" method="post" action="<?php echo $editFormAction; ?>">[\code]and this:[code]<form id="form3" name="form3" method="post" action="" enctype="multipart/form-data">[\code]here is a bigger snip of my code:[code]if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {$insertSQL = sprintf("INSERT INTO faq (crm_case_num, question, tech, application, client_os, site_type, answer) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['crmcase'], "text"), GetSQLValueString($_POST['question'], "text"), GetSQLValueString($_POST['tech'], "text"), GetSQLValueString($_POST['application'], "text"), GetSQLValueString($_POST['client_os'], "text"), GetSQLValueString($_POST['site_type'], "text"), GetSQLValueString($_POST['answer'], "text"));mysql_select_db($database_faqSQLconn, $faqSQLconn);$Result1 = mysql_query($insertSQL, $faqSQLconn) or die(mysql_error());}<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"><table width="99%" border="0" cellspacing="0" cellpadding="0"><tr><td>CRM Case#</td><td><input type="crmcase" name="crmcase"></td><td width="24%">Client OS</td><td width="27%"><select name="client_os"><?php do { ?><option value="<?php echo $row_faq_client_version['client_version']?>"><?php echo $row_faq_client_version['client_version']?></option><?php } while ($row_faq_client_version = mysql_fetch_assoc($faq_client_version));$rows = mysql_num_rows($faq_client_version);if($rows > 0) {mysql_data_seek($faq_client_version, 0);$row_faq_client_version = mysql_fetch_assoc($faq_client_version);}?></select><input type="submit" name="Submit" value="Submit" /></td><input type="hidden" name="MM_insert" value="form1" />[\code]and[code]<?phpif ($_POST['Submit']) {if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size']));$query = sprintf("INSERT INTO faq_image(image, file_type) VALUES ('%s', '%s')", $photo, $_FILES['file']['type']);mysql_select_db($database_faqSQLconn, $faqSQLconn);$faq_image_result = mysql_query($query, $faqSQLconn) or die("Query failed: " . mysql_error() . " Actual query: " . $query);if ($faq_image_result) {$messages[] = "Your file is successfully stored in database";}else {$messages[] = mysql_error();}}else {$messages[] = "The file is bigger than the allowed size (96k) please reduce your file size";}}?></form></td></tr></table><table width="99%" border="0" cellspacing="0" cellpadding="0"><tr><td><span class="style6"><?if (isset($messages)) {foreach ($messages as $message) {print $message ."<br>";}}?></span><form action="" method="post" enctype="multipart/form-data" name="form3"><input type="file" name="file"><input type="hidden" name="MAX_FILE_SIZE" value="96000"><input type="submit" name="Submit" value="Submit"><span class="style6">Add An Image</span></form>[\code][/code][/code][/code][/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 Sometimes you have to step back and say, this approach is not the right one for reaching my goal.Why do you need two forms?<form method="post" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data"> Quote Link to comment Share on other sites More sharing options...
ra2833 Posted January 20, 2007 Author Share Posted January 20, 2007 well, the only reason i think i need two forms is becasue:i have two different type of "type" itemsmy first form has this: (no enctype)[code]<form id="form1" name="form1" method="post" action="<?php echo $editFormAction; ?>">[/code]and my second form has this: (no action)[code]<form id="form3" name="form3" method="post" action="" enctype="multipart/form-data">[/code]would i be okay in combining this two forms to form this?:[code]<form id="form3" name="form3" method="post" action="" enctype="multipart/form-data" action="<?php echo $editFormAction; ?>">[/code]well, i am going to test this and see if this works... Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 Isn't that what I posted? Why do you have a form with no action? Put all of your processing on one page. As I said, sometimes the approach is not right. Quote Link to comment Share on other sites More sharing options...
ra2833 Posted January 20, 2007 Author Share Posted January 20, 2007 yes it is thank you Quote Link to comment Share on other sites More sharing options...
ra2833 Posted January 20, 2007 Author Share Posted January 20, 2007 okay, well my file goes into my db but my textarea items do not, i guess i'l have to work on this.... is it possible to have multiple forms with the same name? Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 20, 2007 Share Posted January 20, 2007 A form with no 'action' is a form that will not work :)You can have multiple forms with the same name but why would you do that? ???What are the field settings for your textarea data in your mysql database? Quote Link to comment Share on other sites More sharing options...
ra2833 Posted January 20, 2007 Author Share Posted January 20, 2007 well, the form with no action was my file upload, and that was working!here is my new edited code:[code]<div id="content_table" style="position:absolute; left:147px; top:137px; width:471px; height:259px; z-index:102"> <span class="style1">Create Issue:</span> <table width="475" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <form id="form1" name="form1" method="POST" enctype="multipart/form-data" action="<?php echo $editFormAction; ?>"> <table width="99%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>CRM Case#</td> <td><input type="text" name="crmcase"></td> <td width="24%">Client OS</td> <td width="27%"> <select name="client_os"> <?php do { ?> <option value="<?php echo $row_faq_client_version['client_version']?>"><?php echo $row_faq_client_version['client_version']?></option> <?php } while ($row_faq_client_version = mysql_fetch_assoc($faq_client_version)); $rows = mysql_num_rows($faq_client_version); if($rows > 0) { mysql_data_seek($faq_client_version, 0); $row_faq_client_version = mysql_fetch_assoc($faq_client_version); } ?> </select> </td> </tr> <tr> <td width="16%">Site Type</td> <td width="33%"> <select name="site_type"> <?php do { ?> <option value="<?php echo $row_faq_site_type['site_type']?>"><?php echo $row_faq_site_type['site_type']?></option> <?php } while ($row_faq_site_type = mysql_fetch_assoc($faq_site_type)); $rows = mysql_num_rows($faq_site_type); if($rows > 0) { mysql_data_seek($faq_site_type, 0); $row_faq_site_type = mysql_fetch_assoc($faq_site_type); } ?> </select> </td> <td>Application:</td> <td> <select name="application"> <?php do { ?> <option value="<?php echo $row_faq_application['Application']?>"><?php echo $row_faq_application['Application']?></option> <?php } while ($row_faq_application = mysql_fetch_assoc($faq_application)); $rows = mysql_num_rows($faq_application); if($rows > 0) { mysql_data_seek($faq_application, 0); $row_faq_application = mysql_fetch_assoc($faq_application); } ?> </select> </td> </tr> <tr> <td colspan="2"><br /></td> <td>Support/Tech</td> <td> <select name="tech"> <?php do { ?> <option value="<?php echo $row_faq_tech['tech']?>"><?php echo $row_faq_tech['tech']?></option> <?php } while ($row_faq_tech = mysql_fetch_assoc($faq_tech)); $rows = mysql_num_rows($faq_tech); if($rows > 0) { mysql_data_seek($faq_tech, 0); $row_faq_tech = mysql_fetch_assoc($faq_tech); } ?> </select> </td> </tr> <tr> <td colspan="2">Issue/Question <textarea name="question"></textarea> </td> <td colspan="2">Answer/Resolution<br /> <textarea name="answer"></textarea> </td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> <input type="submit" name="Submit" value="Submit" /> </td> </tr> <tr> <td colspan="2"</td> <td colspan="2"> </td> </tr> </table><!-- Begin Php for Photo - when turned on this does not work --><?php if ($_POST['Submit']) { if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) { $photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size'])); $query = sprintf("INSERT INTO faq_image(image, file_type) VALUES ('%s', '%s')", $photo, $_FILES['file']['type']); mysql_select_db($database_faqSQLconn, $faqSQLconn); $faq_image_result = mysql_query($query, $faqSQLconn) or die("Query failed: " . mysql_error() . " Actual query: " . $query); if ($faq_image_result) { $messages[] = "Your file is successfully stored in database"; } else { $messages[] = mysql_error(); } } else { $messages[] = "The file is bigger than the allowed size (96k) please reduce your file size"; } }?><!-- end php for photo --> </td> </tr> </table> <table width="99%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <span class="style6"><? if (isset($messages)) { foreach ($messages as $message) { print $message ."<br>"; } } ?></span> <input type="file" name="file"> <input type="hidden" name="MAX_FILE_SIZE" value="96000"> <span class="style6">Add An Image</span> </td> </tr> </table></form><p> <br></p><!-- Begin Table return top 10 --> <table width="518" border="0" cellspacing="0" cellpadding="0"> <tr> <td background="images/ci_head.jpg"> <br /> <br /> <br /> </td> </tr> <tr> <td background="images/ci_main.jpg"> <br /> <center> <table width="475" border="0" cellpadding="0" cellspacing="0"> <tr class="darktable"> <td><strong>FAQ ID</strong></td> <td><a href="sort.by.crm.case.num.php" >CRM Case #</a></td> <td><a href="sort.by.question.php">Question</a></td> <td><a href="sort.by.answer.php">Answer</a></td> <td><a href="sort.by.tech.php">Technician</a></td> <td><a href="sort.by.site.type.php">Site Type</a></td> <td><a href="sort.by.client_os.php">Client OS</a></td> <td><a href="sort.by.answer.php">Application</a></td> </tr><!-- Alternate row colors --> <tr><?php $style = ""; $rowcolor1 = "#666666"; $rowcolor2 = "#cecece"; $alternatecolorcounter = 0; do { if ($alternatecolorcounter % 2 == 1) { $style = $rowcolor1; } else { $style = $rowcolor2; } echo "\t<tr bgcolor=\"$style\">\n". "\t\t<td>". $row_faq_all['faq_unique_id'] ."</td>\n". "\t\t<td>". $row_faq_all['crm_case_num'] ."</td>\n". "\t\t<td>". $row_faq_all['question'] ."</td>\n". "\t\t<td>". $row_faq_all['answer'] ."</td>\n". "\t\t<td>". $row_faq_all['tech'] ."</td>\n". "\t\t<td>". $row_faq_all['site_type'] ."</td>\n". "\t\t<td>". $row_faq_all['client_os'] ."</td>\n". "\t\t<td>". $row_faq_all['application'] ."</td>\n". "\t</tr>\n"; $alternatecolorcounter++; } while ($row_faq_all = mysql_fetch_assoc($faq_all));?> </tr> </table> </center> </td> </tr> <tr> <td background="images/ci_footer.jpg"> <br /> <br /> </td> </tr> </table> <p> </p> <!-- Begin Search --> <form id="form2" name="form2" method="get" action="faq.search.php?search=true"> <label>Keyword: <input type="text" name="searchfaqkeyword" /> </label> <label> <input type="submit" name="Submit2" value="Search" /> </label> </form></div></body></html><?php[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 20, 2007 Share Posted January 20, 2007 A form with no action, by default, re-invokes the script that displayed it.Ken Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 So move the processing which is on the page with the form, to the page with the REST of the processing. Quote Link to comment Share on other sites More sharing options...
ra2833 Posted January 20, 2007 Author Share Posted January 20, 2007 ok.... i am going to go try and hash it out..... Quote Link to comment Share on other sites More sharing options...
ra2833 Posted January 20, 2007 Author Share Posted January 20, 2007 awesome awesome awesome....... thank you all for the super fast feed back and brainstorming.... my page looks like #@$@#$ but i don't care cuz my data is being sent to the db absolutely correct....thank you all again..one almost last question:what should be the correct format for this line of code? it works but IE tells me there is something wrong with it[code]$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size']));[/code] Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted January 20, 2007 Share Posted January 20, 2007 [quote author=ra2833 link=topic=123227.msg509231#msg509231 date=1169318897][code]$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size']));[/code][/quote]not sure why IE in particular would tell you something is wrong with it, but it's not good either for readability or your sanity to try and squeeze code up into one line like that. this should be more readable, and easier to see if there are any PHP errors:[code]<?php$handle = fopen($_FILES['file']['tmp_name'], "r");$contents = fread($handle, $_FILES['file']['size']);$photo = addslashes($contents);?>[/code] Quote Link to comment Share on other sites More sharing options...
ra2833 Posted January 20, 2007 Author Share Posted January 20, 2007 thanks a million again,i had to add the [ b ] to the [r]this comes from php.net[b][font=Verdana]Warning [/font] [/b] On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter. <?php$filename = "c:\\files\\somepic.gif";$handle = fopen($filename, "rb");$contents = fread($handle, filesize($filename));fclose($handle);?> so my end result is:[code]$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "rb"), $_FILES['file']['size']));[/code]i no longer the error and it still works.... dude its a great morning...thanks a million all 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.