For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > February 2006 > saving multiple data...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author saving multiple data...
Zoran

2006-01-10, 4:06 am

This is my problem:

In my form I have this five option menus (they are all taking values from
the same table) and one text field for each option menu (it should be
working something like datasheet in MS ACCESS):



<form name=" checkForm" method="POST">

<?php



$query = 'SELECT name FROM spare_part';

$result = mysql_query($query) or die ('Greska u upitu!');

if(mysql_num_rows($result) > 0)

{

echo '<tr valign="top" height="20">';

echo '<td height="28" align="right"> <b>
spare_part: </b> </td>';

echo '<td height="28" align="left"
nowrap="nowrap"><p><select name="thisSpare_partField">';



while($row = mysql_fetch_object($result))

{



echo '<option value="' . $row->spare_part_id. '">' .
$row->name . '</option>';



}

}

else

{

echo 'Nisu pronadeni podaci o rezervnim djelovima!';

}



?>

<td width="63" align="center"> <b> Quantity:</b> </td>

<td width="50"> <input type="text" name="thisQuantityField1" size="10"
value=""> </td>



<?php



$query = 'SELECT name FROM spare_part ';

$result = mysql_query($query) or die ('Greska u upitu!');

if(mysql_num_rows($result) > 0)

{

echo '<tr valign="top" height="20">';

echo '<td height="28" align="right"></td>';

echo '<td height="28" align="left"
nowrap="nowrap"><p><select name="thisSpare_partField">';



while($row = mysql_fetch_object($result))

{



echo '<option value="' . $row->spare_part_id. '">' .
$row->name . '</option>';



}

}

else

{

echo 'Nisu pronadeni podaci o rezervnim djelovima!';

}

?>

<td width="63" align="center"></td>

<td width="50"> <input type="text" name="thisQuantityField2" size="10"
value=""> </td>



<?php

$query = 'SELECT name FROM spare_part ';

$result = mysql_query($query) or die ('Greska u upitu!');

if(mysql_num_rows($result) > 0)

{

echo '<tr valign="top" height="20">';

echo '<td height="28" align="right"></td>';

echo '<td height="28" align="left"
nowrap="nowrap"><p><select name="thisSpare_partField">';



while($row = mysql_fetch_object($result))

{



echo '<option value="' . $row->spare_part_id. '">' .
$row->name . '</option>';



}

}

else

{

echo 'Nisu pronadeni podaci o rezervnim djelovima!';

}

?>

<td width="63" align="center"></td>

<td width="50"> <input type="text" name="thisQuantityField3" size="10"
value=""> </td>



<?php



$query = 'SELECT name FROM spare_part';

$result = mysql_query($query) or die ('Greska u upitu!');

if(mysql_num_rows($result) > 0)

{

echo '<tr valign="top" height="20">';

echo '<td height="28" align="right"></td>';

echo '<td height="28" align="left"
nowrap="nowrap"><p><select name="thisSpare_partField">';



while($row = mysql_fetch_object($result))

{



echo '<option value="' . $row->spare_part_id. '">' .
$row->name . '</option>';



}

}

else

{

echo 'Nisu pronadeni podaci o rezervnim djelovima!';

}

?>

<td width="63" align="center"></td>

<td width="50"> <input type="text" name="thisQuantityField4" size="10"
value=""> </td>



<?php



$query = 'SELECT name FROM spare_part';

$result = mysql_query($query) or die ('Greska u upitu!');

if(mysql_num_rows($result) > 0)

{

echo '<tr valign="top" height="20">';

echo '<td height="28" align="right"></td>';

echo '<td height="28" align="left"
nowrap="nowrap"><p><select name="thisSpare_partField">';



while($row = mysql_fetch_object($result))

{



echo '<option value="' . $row->spare_part_id. '">' .
$row->name . '</option>';



}

}

else

{

echo 'Nisu pronadeni podaci o rezervnim djelovima!';

}

?>

<td width="63" align="center"></td>

<td width="50"> <input type="text" name="thisQuantityField5" size="10"
value=""> </td>



</table>





<p>

<input type="submit" name="submitCheckForm" value="Submit">

</p>

</form>



MySql tables look like this:



Baza: `servis`

CREATE TABLE `check` (

`check_id` int(10) unsigned NOT NULL auto_increment,

`fname` varchar(35) NOT NULL default '',

`lname` varchar(35) NOT NULL default '',

`adress` varchar(60) NOT NULL default '',

`garancy` binary(1) NOT NULL default '0',

`check_number` int(11) NOT NULL default '0',

`date_number` date NOT NULL default '0000-00-00'

PRIMARY KEY (`check_id`)

) ENGINE=InnoDB;



CREATE TABLE `check_spare` (

`check_id` int(10) NOT NULL default '0',

`spare_part_id` int(11) NOT NULL default '0',

`quantity` int(100) NOT NULL default '0'

PRIMARY KEY ('check_id`)

PRIMARY KEY (`spare_part_id `)

) ENGINE=InnoDB;



CREATE TABLE `spare_part` (

`spare_part_id` int(10) NOT NULL auto_increment,

`name` varchar(100) NOT NULL default '',

`price` int(11) NOT NULL default '0',

`description` varchar(255) default NULL,

PRIMARY KEY (`spare_part_id`)

) ENGINE=InnoDB;





What I don't know is how and where do I insert this selected values to be
able to show them latter with some kind of select query. I was working with
ms access and in it this table 'check_spare' should be looking something
like this:



Check_id spare_part_id quantity

3 part 1 2

3 part 2 1

3 part 3 4

3 part 4 1

3 part 5 2



If someone can help me or know where can I find some similar example I would
be thankful!



Zoran




Jim Michaels

2006-02-23, 7:56 am


"Zoran" <zoransi@email.t-com.hr> wrote in message
news:do9i3o$ahi$1@bagan.srce.hr...
> This is my problem:
>
> In my form I have this five option menus (they are all taking values from
> the same table) and one text field for each option menu (it should be
> working something like datasheet in MS ACCESS):
>


why not turn that code into a function and reuse it easily?
and nowrap doesn't need a value.
you also forgot the </select>. the </p> is supposedly optional.
you also needed to modify your query to include the extra column..
you can even put in some extra code to make the first option SELECTED (also
doesn't need a value).
you *probably* shouldn't use the same field name for the <select> elements.
otherwise, you'll have to access them as an array like
$_POST['thisSpare_partField'][0].
<b></b> has been deprecated. use <strong></strong> instead. actually, if
you can, specify the attribute in the td tag style="font-weight:bold;" or
just use th instead of td.

<form name=" checkForm" method="POST">
<?php
include 'dbinc.php';
function display_spare_part_select($name) {
global $link;
$query = 'SELECT name,spare_part_id FROM spare_part';
$result = mysql_query($query, $link) or die ('Greska u upitu!');
if(mysql_num_rows($result) > 0) {
?>
<tr valign="top" height="20">
<td height="28" align="right"> <strong>spare_part: </strong> </td>
<td height="28" align="left" nowrap><p>
<?php
echo "<select name=\"$name\">\n";
while($row = mysql_fetch_array($result)) {
echo "<option
value=\"$row[spare_part_id]\">$row[name]</option>\n";
}
echo "</select></p>\n";
} else {
echo 'Nisu pronadeni podaci o rezervnim djelovima!';
}
}


for ($i=1; $i <= 5; $i++) {
display_spare_part_select("thisSpare_partField$i");
?>
<td width="63" align="center"> <strong> Quantity:</strong> </td>
<td width="50"> <input type="text" name="thisQuantityField<?php echo $i;
?>" size="10" value=""> </td>
<php
}
?>
<p>
<input type="submit" name="submitCheckForm" value="Submit">
</p>
</form>



>
>
> <form name=" checkForm" method="POST">
>
> <?php
>
>
>
> $query = 'SELECT name FROM spare_part';
>
> $result = mysql_query($query) or die ('Greska u upitu!');
>
> if(mysql_num_rows($result) > 0)
>
> {
>
> echo '<tr valign="top" height="20">';
>
> echo '<td height="28" align="right"> <b>
> spare_part: </b> </td>';
>
> echo '<td height="28" align="left"
> nowrap="nowrap"><p><select name="thisSpare_partField">';
>
>
>
> while($row = mysql_fetch_object($result))
>
> {
>
>
>
> echo '<option value="' . $row->spare_part_id. '">' .
> $row->name . '</option>';
>
>
>
> }
>
> }
>
> else
>
> {
>
> echo 'Nisu pronadeni podaci o rezervnim djelovima!';
>
> }
>
>
>
> ?>
>
> <td width="63" align="center"> <b> Quantity:</b> </td>
>
> <td width="50"> <input type="text" name="thisQuantityField1" size="10"
> value=""> </td>
>
>
>
> <?php
>
>
>
> $query = 'SELECT name FROM spare_part ';
>
> $result = mysql_query($query) or die ('Greska u upitu!');
>
> if(mysql_num_rows($result) > 0)
>
> {
>
> echo '<tr valign="top" height="20">';
>
> echo '<td height="28" align="right"></td>';
>
> echo '<td height="28" align="left"
> nowrap="nowrap"><p><select name="thisSpare_partField">';
>
>
>
> while($row = mysql_fetch_object($result))
>
> {
>
>
>
> echo '<option value="' . $row->spare_part_id. '">' .
> $row->name . '</option>';
>
>
>
> }
>
> }
>
> else
>
> {
>
> echo 'Nisu pronadeni podaci o rezervnim djelovima!';
>
> }
>
> ?>
>
> <td width="63" align="center"></td>
>
> <td width="50"> <input type="text" name="thisQuantityField2" size="10"
> value=""> </td>
>
>
>
> <?php
>
> $query = 'SELECT name FROM spare_part ';
>
> $result = mysql_query($query) or die ('Greska u upitu!');
>
> if(mysql_num_rows($result) > 0)
>
> {
>
> echo '<tr valign="top" height="20">';
>
> echo '<td height="28" align="right"></td>';
>
> echo '<td height="28" align="left"
> nowrap="nowrap"><p><select name="thisSpare_partField">';
>
>
>
> while($row = mysql_fetch_object($result))
>
> {
>
>
>
> echo '<option value="' . $row->spare_part_id. '">' .
> $row->name . '</option>';
>
>
>
> }
>
> }
>
> else
>
> {
>
> echo 'Nisu pronadeni podaci o rezervnim djelovima!';
>
> }
>
> ?>
>
> <td width="63" align="center"></td>
>
> <td width="50"> <input type="text" name="thisQuantityField3" size="10"
> value=""> </td>
>
>
>
> <?php
>
>
>
> $query = 'SELECT name FROM spare_part';
>
> $result = mysql_query($query) or die ('Greska u upitu!');
>
> if(mysql_num_rows($result) > 0)
>
> {
>
> echo '<tr valign="top" height="20">';
>
> echo '<td height="28" align="right"></td>';
>
> echo '<td height="28" align="left"
> nowrap="nowrap"><p><select name="thisSpare_partField">';
>
>
>
> while($row = mysql_fetch_object($result))
>
> {
>
>
>
> echo '<option value="' . $row->spare_part_id. '">' .
> $row->name . '</option>';
>
>
>
> }
>
> }
>
> else
>
> {
>
> echo 'Nisu pronadeni podaci o rezervnim djelovima!';
>
> }
>
> ?>
>
> <td width="63" align="center"></td>
>
> <td width="50"> <input type="text" name="thisQuantityField4" size="10"
> value=""> </td>
>
>
>
> <?php
>
>
>
> $query = 'SELECT name FROM spare_part';
>
> $result = mysql_query($query) or die ('Greska u upitu!');
>
> if(mysql_num_rows($result) > 0)
>
> {
>
> echo '<tr valign="top" height="20">';
>
> echo '<td height="28" align="right"></td>';
>
> echo '<td height="28" align="left"
> nowrap="nowrap"><p><select name="thisSpare_partField">';
>
>
>
> while($row = mysql_fetch_object($result))
>
> {
>
>
>
> echo '<option value="' . $row->spare_part_id. '">' .
> $row->name . '</option>';
>
>
>
> }
>
> }
>
> else
>
> {
>
> echo 'Nisu pronadeni podaci o rezervnim djelovima!';
>
> }
>
> ?>
>
> <td width="63" align="center"></td>
>
> <td width="50"> <input type="text" name="thisQuantityField5" size="10"
> value=""> </td>
>
>
>
> </table>
>
>
>
>
>
> <p>
>
> <input type="submit" name="submitCheckForm" value="Submit">
>
> </p>
>
> </form>
>
>
>
> MySql tables look like this:
>
>
>
> Baza: `servis`
>
> CREATE TABLE `check` (
>
> `check_id` int(10) unsigned NOT NULL auto_increment,
>
> `fname` varchar(35) NOT NULL default '',
>
> `lname` varchar(35) NOT NULL default '',
>
> `adress` varchar(60) NOT NULL default '',
>
> `garancy` binary(1) NOT NULL default '0',
>
> `check_number` int(11) NOT NULL default '0',
>
> `date_number` date NOT NULL default '0000-00-00'
>
> PRIMARY KEY (`check_id`)
>
> ) ENGINE=InnoDB;
>
>
>
> CREATE TABLE `check_spare` (
>
> `check_id` int(10) NOT NULL default '0',
>
> `spare_part_id` int(11) NOT NULL default '0',
>
> `quantity` int(100) NOT NULL default '0'
>
> PRIMARY KEY ('check_id`)
>
> PRIMARY KEY (`spare_part_id `)
>
> ) ENGINE=InnoDB;
>
>
>
> CREATE TABLE `spare_part` (
>
> `spare_part_id` int(10) NOT NULL auto_increment,
>
> `name` varchar(100) NOT NULL default '',
>
> `price` int(11) NOT NULL default '0',
>
> `description` varchar(255) default NULL,
>
> PRIMARY KEY (`spare_part_id`)
>
> ) ENGINE=InnoDB;
>
>
>
>
>
> What I don't know is how and where do I insert this selected values to be
> able to show them latter with some kind of select query. I was working
> with
> ms access and in it this table 'check_spare' should be looking something
> like this:
>


please restate the question. Not enough information for me to understand.
latter referring to what?
What do you mean how to insert selected values?


>
>
> Check_id spare_part_id quantity
>
> 3 part 1 2
>
> 3 part 2 1
>
> 3 part 3 4
>
> 3 part 4 1
>
> 3 part 5 2
>
>
>
> If someone can help me or know where can I find some similar example I
> would
> be thankful!
>
>
>
> Zoran
>
>
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com