Jump to content

insert mysql LIMIT?


johnseito

Recommended Posts

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.