PDA

View Full Version : INSERT multi-row at once?


mokujin
08-30-2008, 07:30 PM
Hi,
I need a script, which I can INSERT more rows at once.

I have this code in admincp:


if ($_REQUEST['do'] == 'add')
{
print_form_header('myscript', 'insert');
print_table_header('Total 10 rows will be shown ');
print_select_row('Select a Category', 'categoryid', fetch_categories_array($catid));

for ($x = 1; $x <= 10; $x++)
{
print_input_row('Title '.$x.'', 'title['.$x.']');
print_input_row('Description '.$x.'', 'description['.$x.']');
}

print_submit_row($vbphrase['add']);
}

How do I have POST insert code?

Can anyone help me?
Thank you (sorry for my very bad English :( )

Dismounted
08-31-2008, 05:39 AM
What's POST insert code?

Opserty
08-31-2008, 08:48 AM
<a href="http://www.desilva.biz/mysql/insert.html" target="_blank">http://www.desilva.biz/mysql/insert.html</a>

mokujin
08-31-2008, 07:03 PM
What's POST insert code?

print_form_header('myscript', 'insert');

You can see: $_POST['do'] = 'insert' in myscript.php here

http://www.desilva.biz/mysql/insert.html

Thank you very much, but do you know how to use Loops for multi VALUES?
I mean how to use Loops =>

VALUES
('Helen', 24),
('Katrina', 21),
('Samia', 22),
('Hui Ling', 25),
('Yumie', 29)";


Thank you for helping me :) I hope you understand it

MoT3rror
09-01-2008, 05:41 AM
$sqlvalues = 'VALUES';
$first = true;

for()//something goes there or make it a while, foreach
{
$sqlvalues .= ($first ? '' : ', ') . "('" . $db->escape_string($somevalue) . "', '" . $db->escape_string($somevalue2) . "')";

$first = false;
}

$db->query_write("
INSERT INTO TABLE(value1, value2)
$sqlvalues
");

mokujin
09-02-2008, 07:38 PM
Thanks MoT3, could you help me again with

$vbulletin->input->clean_gpc('p', 'title', TYPE_STR);
$vbulletin->input->clean_gpc('p', 'description', TYPE_STR);

Now I have method POST = insert like this:


// CHECK FOR TOTAL INPUTS...
$vbulletin->input->clean_gpc('p', 'title', TYPE_FILE);
$vbulletin->input->clean_gpc('p', 'description', TYPE_FILE);

$totaltitles = count($vbulletin->GPC['title']['name']);

// INSERT FORM
$sqlvalues = 'VALUES';
$first = true;
for($x = 1; $x <= $totaltitles; $x++) //something goes there or make it a while, foreach
{
$sqlvalues .= ($first ? '' : ', ') . "

('" . $db->escape_string($somevalue) . "', '" . $db->escape_string($somevalue2) . "')

";

$first = false;
}

/* query insert */
$db->query_write("
INSERT INTO TABLE(value1, value2)
$sqlvalues
");


But there is an error that cant count how many rows need to insert :((

MoT3rror
09-03-2008, 04:48 AM
What is title and description supposed to be a file or plain text?

mokujin
09-03-2008, 10:05 AM
What is title and description supposed to be a file or plain text?
Its a plain text only, no files. I need the function which counts how many inputs form.

THanks

Marco van Herwaarden
09-03-2008, 11:01 AM
$vbulletin->input->clean_gpc('p', 'title', TYPE_FILE);
Then you should not use TYPE_FILE but TYPE_STR or TYPE_NOHTML.

mokujin
09-03-2008, 07:26 PM
$vbulletin->input->clean_gpc('p', 'title', TYPE_FILE);
Then you should not use TYPE_FILE but TYPE_STR or TYPE_NOHTML.
Yeah I changed to TYPE_STR, but how can I count total names of the form fields where is not blank?

And how to make this in vbulletin?

for ($x = 1; $x <= 10; $x++)
{
$_POST["title"][$i] = $vbulletin->input->clean_gpc('p', 'title'[$i], TYPE_STR);
}

Marco van Herwaarden
09-04-2008, 06:06 AM
So 'title' is not a simple text field like you said previously but an array?