johnseito Posted March 9, 2008 Share Posted March 9, 2008 is there an limit amt of data that insert into mysql at once? Such as this code: PHP Code: mysql_query("insert into register(firstname, lastname, gender, month, day) values('$firstname', '$lastname', '$gender', '$month', '$day')"); If i add more field would there be a problem? It seem like it is because when I add more field it won't insert any data. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/ Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 feel free to add as many recrods as you like use () for each record and seperate records by , so VALUES('name', 'last', 'gender', 'month', 'day'), ('name', 'last', 'gender', 'month', 'day'), ('name', 'last', 'gender', 'month', 'day') ofcourse don't use the same variable as it will dublicate the same record several times... Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487456 Share on other sites More sharing options...
johnseito Posted March 9, 2008 Author Share Posted March 9, 2008 use () for each record and seperate records by , so it seems you did this for every 5 records, and you didn't include $ sign infront of each variable. Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487463 Share on other sites More sharing options...
unsider Posted March 9, 2008 Share Posted March 9, 2008 VALUES('$name', '$last', '$gender', '$month', '$day') Wouldn't you need $? EDIT: nevermind it's been covered. Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487469 Share on other sites More sharing options...
johnseito Posted March 9, 2008 Author Share Posted March 9, 2008 Xajel-- i just tried your method and it still doesn't work, it can't add more than 5 records at a time. Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487471 Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 use () for each record and seperate records by , so it seems you did this for every 5 records, and you didn't include $ sign infront of each variable. it's just an example, I did told you not to use the same variable as it will dublicate the record... you may have some variables like $name1, $name2 or an array $name[0], $name[1] ( in this case you can use a for() loop ) and make sure not to add , after the last record $count = count($firstname); $query = "INSERT INTO `register`(`firstname`, `lastname`, `gender`, `month`, `day`) VALUES"; for ($i=0; $i<$count; $i++) { $query .= "('$firstname[$i]', '$lastname[$i]', '$gender[$i]', '$month[$i]', '$day[$i]')"; // adding records // if not the last record, then add a ", "... if ($i < ($count-1)) { $query .= ", "; } } echo $query; Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487476 Share on other sites More sharing options...
johnseito Posted March 9, 2008 Author Share Posted March 9, 2008 doesn't work, thz Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487491 Share on other sites More sharing options...
Stooney Posted March 9, 2008 Share Posted March 9, 2008 You could just build a separate query per record and make it easier. (Less efficient, but that won't matter unless it's a huge amount of records). Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487496 Share on other sites More sharing options...
johnseito Posted March 9, 2008 Author Share Posted March 9, 2008 I did that: mysql_query("insert into register(firstname, lastname, gender, month, day) values('$firstname', '$lastname', '$gender', '$month', '$day')"); mysql_query("insert into register(year, country, address, State, postal) values('$year', '$country', '$address', '$state', '$postal')"); and it doesn't work, it doesn't enter more that 5 data fields at the same time. Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487507 Share on other sites More sharing options...
azfar siddiqui Posted March 9, 2008 Share Posted March 9, 2008 I just separate the records with a comma and surrounded brackets... I have used it several times... Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487545 Share on other sites More sharing options...
blueman378 Posted March 9, 2008 Share Posted March 9, 2008 are you doing this: mysql_query("insert into register(firstname, lastname, gender, month, day, newfield) values('$firstname', '$lastname', '$gender', '$month', '$day', '$newfield')"); or mysql_query("insert into register(firstname, lastname, gender, month, day newfield) values('$firstname', '$lastname', '$gender', '$month', '$day' '$newfield')"); eg the , easy mistake but noone has mentioned it so i thought i would say jsut incase... cheers Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487591 Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 can you echo the final query to verify it ? Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487610 Share on other sites More sharing options...
johnseito Posted March 9, 2008 Author Share Posted March 9, 2008 Xajel $count = count($firstname); $query = "INSERT INTO `register`(`firstname`, `lastname`, `gender`, `month`, `day`) VALUES"; for ($i=0; $i<$count; $i++) { $query .= "('$firstname[$i]', '$lastname[$i]', '$gender[$i]', '$month[$i]', '$day[$i]')"; // adding records // if not the last record, then add a ", "... if ($i < ($count-1)) { $query .= ", "; } } echo $query; I think your code is not doing what I want, it seems your code is adding more records with the same amt of data field. <b>What I want to do is add more fields besides the 5 fields I have, then add more record to those fields</b>. when I add an extra field, say the 6th field, it doesn't insert any data into mysql. Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487804 Share on other sites More sharing options...
eddierosenthal Posted March 9, 2008 Share Posted March 9, 2008 seems like you might be overwriting query on top of query? that would explain the number 5. you need to echo the query you execute to see what it looks like and post it here. Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487814 Share on other sites More sharing options...
johnseito Posted March 9, 2008 Author Share Posted March 9, 2008 Posted by: azfar siddiqui Insert Quote I just separate the records with a comma and surrounded brackets... I have used it several times... Could you show me an example of what you mean? blueman378 mysql_query("insert into register(firstname, lastname, gender, month, day newfield) values('$firstname', '$lastname', '$gender', '$month', '$day' '$newfield')"); The only difference with this code and the other code you have is that this one has <b> day newfield</b> and for this one you didn't have a comma. isn't this a mistake? so to answer your question i am doing this mysql_query("insert into register(firstname, lastname, gender, month, day, newfield) values('$firstname', '$lastname', '$gender', '$month', '$day', '$newfield')"); thx Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487816 Share on other sites More sharing options...
haku Posted March 9, 2008 Share Posted March 9, 2008 If your database isn't set up with a column to hold that information, you can't do it. And if it is set up with a column, you have to list that column in the first part of your query where you list the column names. Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-487817 Share on other sites More sharing options...
johnseito Posted March 10, 2008 Author Share Posted March 10, 2008 Ok, I create a table like this in mysql PHP Code: create table test( day tinyint(2), year int(4)); and I create a form with this two fields and fill in the form, all, or one of the fields and leave one blank. It seems that fill all of them works and the info gets insert into the database, but if i were to fill one field and leave one blank it doesn't work, the info doesn't get inserted into the database. Any idea why? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-488100 Share on other sites More sharing options...
haku Posted March 10, 2008 Share Posted March 10, 2008 You have to write your insert statement like this: "INSERT INTO table (variable1, variable2) VALUES ('value1', "")" You cant leave one blank altogether, you have to at least tell it to insert an empty value. The number of fields in the first set of brackets has to match the number of fields in the second set of brackets. Quote Link to comment https://forums.phpfreaks.com/topic/95169-insert-mysql-limit/#findComment-488149 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.