pixeltrace Posted November 8, 2006 Share Posted November 8, 2006 guys,i need help, i have a form that needs to add 1 to 5 email addresses with its name, company, catergory, etcmy problem is with the emailadded.php because its getting an error on my insert query part.here is the codes for my emailadd.php pagehttp://www.sinagtala.net/emailadd.phpsand here is the code for my emailadded.phphttp://www.sinagtala.net/emailadded.phpswhat could be the problem on my codes?thanks! Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/ Share on other sites More sharing options...
btherl Posted November 8, 2006 Share Posted November 8, 2006 I suggest you do 5 seperate queries rather than just 1, with error checking for each. It would also be a good idea to validate all of the emails, not just the first one.If a query fails, display the SQL so you can see what went wrong. Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-121416 Share on other sites More sharing options...
Vikas Jayna Posted November 8, 2006 Share Posted November 8, 2006 The mysql_query() function expects a single query and not multiple queries. Ideally this script should be giving a parsing error p[i][b]arse error, unexpected '\"'[/b][/i] as there is no concatenation operator between the five strings. Probably you can have five calls to mysql_query() function with one query each or a single insert statement to insert all the five records at once - See the Insert query syntax in the mysql manual for the same. Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-121417 Share on other sites More sharing options...
pixeltrace Posted November 8, 2006 Author Share Posted November 8, 2006 i did the query for the other entriesbut i am getting an error on line 107Parse error: syntax error, unexpected $end in /home/sinag/public_html/admean/emailadded.php on line 107below is the code that i didhttp://www.sinagtala.net/emailadded.phps Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-121420 Share on other sites More sharing options...
Vikas Jayna Posted November 8, 2006 Share Posted November 8, 2006 There are no closing braces for the [b]if statements[/b] used. Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-121424 Share on other sites More sharing options...
pixeltrace Posted November 8, 2006 Author Share Posted November 8, 2006 great!it work!but i have one more problem.i tried adding just two (2) emails. but codes run and it work but the problem isit also adds the empty fields for query 3, 4, and 5 to the database.so when i view my table, there are new items which are empty.how should i fix this one?thanks! Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-121427 Share on other sites More sharing options...
pixeltrace Posted November 8, 2006 Author Share Posted November 8, 2006 this is the code for my emailadded.phphttp://www.sinagtala.net/emailadded.phps Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-121429 Share on other sites More sharing options...
Vikas Jayna Posted November 8, 2006 Share Posted November 8, 2006 The queries should be executed conditionally i.e. they should be executed only if the corresponding value of email is not blank. Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-121442 Share on other sites More sharing options...
pixeltrace Posted November 9, 2006 Author Share Posted November 9, 2006 Hi,I dont know how to start the conditions and where.Hope you could help me with this.this is my code http://www.sinagtala.net/emailadded.phpsThanks! Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-122135 Share on other sites More sharing options...
Orio Posted November 9, 2006 Share Posted November 9, 2006 I've edited your code so it will run in a loop, including the conditions.** I've changed all of the script tags into <scrip> becuase SMF won't let me post using this tag. Please edit before testing.[code]<?phpinclude '../db_connect2.php'; $name=array();$company=array();$email=array();$category=array();$i=1;while($i<=5){ $name[$i] = stripslashes($_POST['name'.$i]); $company[$i] = stripslashes($_POST['company'.$i]); $email[$i] = stripslashes($_POST['email'.$i]); $category[$i] = stripslashes($_POST['category'.$i]); if(empty($name[$i]) || empty($company[$i]) || empty($email[$i]) || empty($category[$i])) { die('<scrip language=javascript> alert("You did not submit all of the required information!");</script>'); } $sql = mysql_query("INSERT INTO emailadd (full_name, company, email, category) VALUES('".$name[$i]."', '".$company[$i]."', '".$email[$i]."' , '".$category[$i]."')") or die ("Error with query ".$i.":<br>".mysql_error()); if(mysql_affected_rows() == 0) die('<scrip language=javascript> alert("Error adding event");top.location = "email.php?id=2";</script>'); $i++;}echo '<scrip language=javascript> alert("New email address has been added for the mailing list!");top.location = "email.php?id=2";</script>'; ?>[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/26540-need-help-on-inserting-mulitple-entries/#findComment-122190 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.