RichardRotterdam Posted May 15, 2008 Share Posted May 15, 2008 dude it is js <script scr="mootools.js"></script> this means you include the mootools javascript into your page. its some extra javascript library to make javascript coding a lot easier. and no you dont install a thing since you dont have to install a thing to run javascript Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542140 Share on other sites More sharing options...
947740 Posted May 15, 2008 Share Posted May 15, 2008 Dj Kat-what browser are you using? I am using IE6 and it does not erase values when a form field is added. Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542182 Share on other sites More sharing options...
kevgais Posted May 15, 2008 Author Share Posted May 15, 2008 running ie6 & 7 and it's fine. just firefox it erases the text Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542236 Share on other sites More sharing options...
kevgais Posted May 15, 2008 Author Share Posted May 15, 2008 got it, works great thanks Dj Kat. I've put this code into the form.php <?php $con = mysql_connect("xxx","xx","xx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(xxx", $con); $sql="INSERT INTO guests (guest_name, guest_email) VALUES ('$_POST[username]','$_POST[email]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "record added"; mysql_close($con) ?> but it doesn't quite work, all it does is enter the words Array into the database and in only 1 row despite how many people i enter data for. any idea? Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542343 Share on other sites More sharing options...
RichardRotterdam Posted May 15, 2008 Share Posted May 15, 2008 @947740 i always use firefox i dont like ie much and firefox has better js debugging tools @kevgais yeah the post values are a array so you need to treat them as such you will need a loop create a query Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542388 Share on other sites More sharing options...
RichardRotterdam Posted May 15, 2008 Share Posted May 15, 2008 hmmm the modify button dissapeared oh well anyway try this havent tested it <?php $con = mysql_connect("xxx","xx","xx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxx", $con); $sql="INSERT INTO guests (guest_name, guest_email) VALUES"; for($i=0;$i<sizeof($_POST['username']);$i++){ $sql.="('".mysql_real_escape_string($_POST['username'][$i])."','".mysql_real_escape_string($_POST['email'][$i])."')"; if(!$i==sizeof($_POST['username'])){ $sql.=","; } } // if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "record added"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542422 Share on other sites More sharing options...
kevgais Posted May 16, 2008 Author Share Posted May 16, 2008 thanks again, using that revised code returns this error Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('3','3')('4','4')' at line 1 not sure where to look for this error. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542671 Share on other sites More sharing options...
networkthis Posted May 16, 2008 Share Posted May 16, 2008 Why not use php to create an input box that asks the user for the number of peoples emails they will need to add then have that value be inserted into a variable such as $number_of_input_boxes, then simply hit enter and all the boxes will appear.............. Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542682 Share on other sites More sharing options...
kevgais Posted May 16, 2008 Author Share Posted May 16, 2008 cheers networkthis. do you have any example code for this? Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542688 Share on other sites More sharing options...
networkthis Posted May 16, 2008 Share Posted May 16, 2008 Here is the first page: I just named it upload_number.php -------------------------------------------------------------------------------------------------<? <?php //YOU NEED TO HAVE THIS ON ALL OF YOUR PAGES THAT YOU WANT TO RETAIN THE VALUES IN THE SESSIONS. session_start(); //This will turn ALL of our post variables into session variables foreach($_POST as $key => $val) { $_SESSION[$key] = $val; } ?> <form enctype="multipart/form-data" method="post" action="upload.php"> <label>Number of Email Adresses to Add</label> <input name="email_number" id="email_number" value="<?php echo $_SESSION['email_number']; ?>" size= "20" /> <input type="submit" name="Submit" class="submit-form" value="Submit"> </p></form></h4> ------------------------------------------------------------------------------------------------- Here is the second page.... I just named it upload.php ------------------------------------------------------------------------------------------------- <?php //YOU NEED TO HAVE THIS ON ALL OF YOUR PAGES THAT YOU WANT TO RETAIN THE VALUES IN THE SESSIONS. session_start(); //This will turn ALL of our post variables into session variables foreach($_POST as $key => $val) { $_SESSION[$key] = $val; } ?> <form enctype="multipart/form-data" method="post" action="upload_emails.php"> <label>First Name</label> <input name="first_name" id="first_name" value="<?php echo $_POST['first_name']; ?>" size= "20" /> <br /> <?php // start of emails $number_emails = $_SESSION['email_number']; for($x=0;$x<$number_emails;$x++){ ?> <field>Email Address</field><input class="none" name="file_email<? echo $x;?>" type="text" id="file_email<? echo $x;?>"> <br /> <?php // end of for loop } ?> <p><input name="number_emails" type="hidden" value="<? echo $number_emails;?>"> <input type="submit" name="Submit" class="submit-form" value="Submit"> </p></form></h4> ------------------------------------------------------------------------------------------------- For the final page I named it upload emails....... ------------------------------------------------------------------------------------------------- <?php echo 'Do what you want here!!!'; ?> Sorry its a little sloppy, I just threw it together real quick....hopefully you get the point Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542690 Share on other sites More sharing options...
kevgais Posted May 16, 2008 Author Share Posted May 16, 2008 cheers works perfectly. still having problems with this sql statement $sql.="INSERT INTO guests (guest_name, guest_email) VALUES"; for($i=0;$i<sizeof($_POST['username']);$i++){ $sql.="('".mysql_real_escape_string($_POST['username'][$i])."','".mysql_real_escape_string($_POST['email'][$i])."')"; if(!$i==sizeof($_POST['username'])){ $sql.=","; } } // if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "record added"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542736 Share on other sites More sharing options...
kevgais Posted May 16, 2008 Author Share Posted May 16, 2008 hi again, I've worked out that this script work when using only 2 rows of fields, if I add anymore it fails. So I'm assuming that it's somthing to do with the loop, which, I think, is this line for($i=0;$i<sizeof($_POST['username']);$i++){ does this line look correct? Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542763 Share on other sites More sharing options...
RichardRotterdam Posted May 16, 2008 Share Posted May 16, 2008 try to echo your $sql var that will make the query visible and able to track the problem and plz use the [ code ] [/ code ] tags so the code is highlighted Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542776 Share on other sites More sharing options...
kevgais Posted May 16, 2008 Author Share Posted May 16, 2008 apologies. it prints "INSERT INTO guests (guest_name, guest_email) VALUES" Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542804 Share on other sites More sharing options...
RichardRotterdam Posted May 16, 2008 Share Posted May 16, 2008 nah dont worry bout the code tags thing just use it for future usage did you do the echo the sql after the loop or before if its after then youre right it means the loop is correct otherwise place the echo($sql) after the loop to see what it does Quote Link to comment https://forums.phpfreaks.com/topic/105630-creating-form-fields-on-thefly/page/2/#findComment-542824 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.