1,105,352 Community Members

Stock Recording System

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

Stock Recording System - I basically wants to see the data recorded in the table sql. yet this is not the case.

mysql_query("INSERT INTO Produk FROM stock VALUES ('Produk')");
mysql_query("INSERT INTO Jumlah FROM stock VALUES ('Jumlah')");
mysql_query("INSERT INTO Tanggal_Masuk FROM stock VALUES ('Tanggal_Masuk')");

Is that instruction not enough to record data? Thanks.

<h4>STOCK RECORDING SYSTEM</h4>

<form action="action.php" method="post">

<table border="0" width="300">
<tr>
    <tr>
        <td>Produk  :</td><br>
        <td>
          <select name="batch" onchange="submit();">
            <option value="-1" >-- Select Address --</option>
            <?php

            $username='root';
            $password='';

            $con = mysql_connect('localhost', $username, $password);
            mysql_select_db('snack', $con);

            $result = mysql_query("SELECT * FROM PO");

            while($row = mysql_fetch_array($result))
            {
             ?>
            <option value="<?php echo $row['PO'];?>">
            <?php echo $row['PO'];?></option>
            <?php            
            }


            ?>
        </select>
        </td>    
    </tr>    
    <tr>
        <td>Jumlah  :</td>
        <td><input type="text" size="12" maxlength="22" name="Jumlah" value="2 box 1 pack"></td><br> 
    <tr>
        <?php // use date picker to automate date ?>
        <td>Tanggal :</td>
        <td><input type="date" id="datepicker" size="12" maxlength="22" name="Tanggal" value=""></td><br>
    </tr>    
</table>


</form>

<?php

$username='root';
$password='';

$con = mysql_connect('localhost', $username, $password);
mysql_select_db('snack', $con);
?>
<form action="print.php" method="post">
<?php
mysql_query("INSERT INTO Produk FROM stock VALUES ('Produk')");
mysql_query("INSERT INTO Jumlah FROM stock VALUES ('Jumlah')");
mysql_query("INSERT INTO Tanggal_Masuk FROM stock VALUES ('Tanggal_Masuk')");
?>
<input type="submit" value="Submit">
</form>

</html>
Member Avatar
pritaeas
mod_pritaeas
11,315 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

The syntax is this (if the tables are identical):

INSERT INTO Produk SELECT * FROM stock
Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

no VALUES ?

Member Avatar
pritaeas
mod_pritaeas
11,315 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

It's all in the manual.

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

I tried and they do not save the data into mysql tables.

Member Avatar
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 85 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
0
 
INSERT INTO `table` (`field`,`field2`,`field3`) VALUES ('value1','value2',4);

or expanding on the select query pritaeas posted, for different table structures

INSERT INTO `table` (`fielda`,`fieldb`,`fieldc`) select `field1`,`field2`,`field3` FROM `table2`;
Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

Still it won't store the information.

<form action="print.php" method="post">
    <?php
    mysql_query("INSERT INTO Stock ('Produk', 'Jumlah', 'Tanggal Masuk') VALUES ('Produk', 'Jumlah', 'Tanggal')");
    ?>
    <input type="submit" value="Submit">
Member Avatar
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 85 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
1
 

back ticks not single quotes, they are next to 1 under the escape key( on my keyboard at least). you use back ticks to enclose field or table names in mysql

mysql_query("INSERT INTO Stock (`Produk`, `Jumlah`, `Tanggal Masuk`) VALUES ('Produk', 'Jumlah', 'Tanggal')");
Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

I change it. It still won't store any data. I wonder why.

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

I try to enter the mysql_query in the phpmyadmin:

1054 - Unknown column 'Tanggal' in 'field list'

INSERT INTO Stock( Produk , Jumlah , Tanggal Masuk )
VALUES (
Produk , Jumlah , Tanggal
)

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

Still won't record the data:

<h4>STOCK RECORDING SYSTEM</h4>

<form action="action.php" method="post">

<table border="0" width="300">
<tr>
    <tr>
        <td>Produk  :</td><br>
        <td>
          <select name="batch" onchange="submit();">
            <option value="-1" >-- Select Address --</option>
            <?php

            $username='root';
            $password='';

            $con = mysql_connect('localhost', $username, $password);
            mysql_select_db('snack', $con);

            $result = mysql_query("SELECT * FROM PO");

            while($row = mysql_fetch_array($result))
            {
             ?>
            <option value="<?php echo $row['PO'];?>">
            <?php echo $row['PO'];?></option>
            <?php            
            }


            ?>
        </select>
        </td>    
    </tr>    
    <tr>
        <td>Jumlah  :</td>
        <td><input type="text" size="12" maxlength="22" name="Jumlah" value="2 box 1 pack"></td><br> 
    <tr>
        <?php // use date picker to automate date ?>
        <td>Tanggal :</td>
        <td><input type="date" id="datepicker" size="12" maxlength="22" name="Tanggal" value=""></td><br>
    </tr>    
</table>


</form>

<?php

$username='root';
$password='';

$con = mysql_connect('localhost', $username, $password);
mysql_select_db('snack', $con);
?>
<form action="print.php" method="post">
<?php
mysql_query("INSERT INTO Stock (`Produk`, `Jumlah`,`Tanggal`) VALUES (`PO`, `Jumlah`, `Tanggal`)");
?>
<input type="submit" value="Submit">
</form>

</html>
Member Avatar
TonyG_cyprus
Posting Whiz
329 posts since Dec 2009
Reputation Points: 36 [?]
Q&As Helped to Solve: 47 [?]
Skill Endorsements: 2 [?]
 
-1
 

I never use backticks, or quotes around field names, also make sure there are no spaces

mysql_query("INSERT INTO Stock (Produk,Jumlah,Tanggal) VALUES ('PO','Jumlah','Tanggal')");

spaces will upset mysql!

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
1
 

I never use backticks, or quotes around field names, also make sure there are no spaces

It's good practice to do so as reserved words can often mess up your queries. Anyway - backticks around fieldnames, single quotes around values (if in a double quoted string and data is not numeric).

Tony's sql should work.

Member Avatar
TonyG_cyprus
Posting Whiz
329 posts since Dec 2009
Reputation Points: 36 [?]
Q&As Helped to Solve: 47 [?]
Skill Endorsements: 2 [?]
 
0
 

It's good practice to do so as reserved words can often mess up your queries

Quite right Diafol, I tend to forget as I only code for myself and therefore shouldn't mess it up!

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

Produk Jumlah Tanggal (title)
Stick Biru 2 box 1 pack 2013-01-25
PO Jumlah 0000-00-00

I get this as a result. The first row I insert it manually. The next one, by form. I revise the mysql just like Tony said. It's getting closer yet it just no quite right.

<h4>STOCK RECORDING SYSTEM</h4>


<form action="print.php" method="post">

<table border="0" width="300">
<tr>
    <tr>
        <td>Produk  :</td><br>
        <td>
          <select name="batch" onchange="submit();">
            <option value="-1" >-- Select Address --</option>
            <?php

            $username='root';
            $password='';

            $con = mysql_connect('localhost', $username, $password);
            mysql_select_db('snack', $con);

            $result = mysql_query("SELECT * FROM PO");

            while($row = mysql_fetch_array($result))
            {
             ?>
            <option value="<?php echo $row['PO'];?>">
            <?php echo $row['PO'];?></option>
            <?php            
            }


            ?>
        </select>
        </td>    
    </tr>    
    <tr>
        <td>Jumlah  :</td>
        <td><input type="text" size="12" maxlength="22" name="Jumlah" value="2 box 1 pack"></td><br> 
    <tr>
        <?php // use date picker to automate date ?>
        <td>Tanggal :</td>
        <td><input type="date" id="datepicker" size="12" maxlength="22" name="Tanggal" value=""></td><br>
    </tr>    
    <?php
        mysql_query("INSERT INTO Stock (Produk,Jumlah,Tanggal) VALUES ('PO','Jumlah','Tanggal')");
    ?>
    </table>

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

</form>   
</html>
Member Avatar
TonyG_cyprus
Posting Whiz
329 posts since Dec 2009
Reputation Points: 36 [?]
Q&As Helped to Solve: 47 [?]
Skill Endorsements: 2 [?]
 
0
 

I just revisited your code, several points to check on.
The <form> has action="print.php" , so it's sending post data elsewhere.
The mysql query is within the <form> tags.
If you are 'POST'ing your form you need to create the variables to put into mysql
i.e.
$PO=$_POST['batch'];
$tanggal=$_POST['Tanggal'];
etc;
And your <select> element has the onClick method so it's gonna submit the form as soon as it's changed.

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

I still don't get it. How exactly I have to code it.

Member Avatar
TonyG_cyprus
Posting Whiz
329 posts since Dec 2009
Reputation Points: 36 [?]
Q&As Helped to Solve: 47 [?]
Skill Endorsements: 2 [?]
 
0
 

I don't wish to seem rude or unhelpful, but we have given you a lot of help on this one already. Download the manual that Pritaeas pointed you to and also the php manual is downloadable, by using those carefully you should be able to work this out for yourself.
Nobody is going to write the code for you.

Member Avatar
davy_yg
Veteran Poster
1,117 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

Well here is a revision:

<form action="print.php" method="post">

<table border="0" width="300">
<tr>
    <tr>
        <td>Produk  :</td><br>
        <td>
          <select name="batch" onchange="submit();">
            <option value="-1" >-- Select Address --</option>
            <?php

            $username='root';
            $password='';

            $con = mysql_connect('localhost', $username, $password);
            mysql_select_db('snack', $con);

            $result = mysql_query("SELECT * FROM PO");

            while($row = mysql_fetch_array($result))
            {
             ?>
            <option value="<?php echo $row['PO'];?>">
            <?php echo $row['PO'];?></option>
            <?php            
            }

            ?>
        </select>
        </td>    
    </tr>    
    <tr>
        <td>Jumlah  :</td>
        <td><input type="text" size="12" maxlength="22" name="Jumlah" value="2 box 1 pack"></td><br> 
    <tr>
        <?php // use date picker to automate date ?>
        <td>Tanggal :</td>
        <td><input type="date" id="datepicker" size="12" maxlength="22" name="Tanggal" value=""></td><br>
    </tr>    
    <?php
        mysql_query("INSERT INTO Stock (Produk,Jumlah,Tanggal) VALUES ('$_POST[PO]','$_POST[Jumlah]','$_POST[Tanggal]')");
    ?>
    </table>

Notice: Undefined index: PO in C:\xampp\htdocs\Innovation\script_shop\stock.php on line 70

Notice: Undefined index: Jumlah in C:\xampp\htdocs\Innovation\script_shop\stock.php on line 70

Notice: Undefined index: Tanggal in C:\xampp\htdocs\Innovation\script_shop\stock.php on line 70

line 70: mysql_query("INSERT INTO Stock (Produk,Jumlah,Tanggal) VALUES ('$_POST[PO]','$_POST[Jumlah]','$_POST[Tanggal]')");

Member Avatar
TonyG_cyprus
Posting Whiz
329 posts since Dec 2009
Reputation Points: 36 [?]
Q&As Helped to Solve: 47 [?]
Skill Endorsements: 2 [?]
 
0
 

Try This:

<form action="" method="post">
    <table border="0" width="300">
    <tr>
    <tr>
    <td>Produk :</td><br>
    <td>
    <select name="batch">
    <option value="-1" >-- Select Address --</option>
    <?php
    $username='root';
    $password='';
    $con = mysql_connect('localhost', $username, $password);
    mysql_select_db('snack', $con);
    $result = mysql_query("SELECT * FROM PO");
    while($row = mysql_fetch_array($result))
    {
    ?>
    <option value="<?php echo $row['PO'];?>">
    <?php echo $row['PO'];?></option>
    <?php
    }
    ?>
    </select>
    </td>
    </tr>
    <tr>
    <td>Jumlah :</td>
    <td><input type="text" size="12" maxlength="22" name="Jumlah" value="2 box 1 pack"></td><br>
    <tr>
    <!-- use date picker to automate date -->
    <td>Tanggal :</td>
    <td><input type="date" id="datepicker" size="12" maxlength="22" name="Tanggal" value=""></td><br>
    </tr>
    <tr> <td align="center" colspan="2"><input type="submit" name="submit" value="Send"></td>
    </tr>
    </table>
    </form>


    <?php
    if(isset($_POST['submit'])){
    $PO=$_POST['batch']; //the name of your select element
    $Jumlah=$_POST['Jumlah'];
    $Tanggal=$_POST['Tanggal'];

    $result=mysql_query("INSERT INTO Stock (Produk,Jumlah,Tanggal) VALUES ('$PO','$Jumlah','$Tanggal')");
    // for debugging
    if(!$result){
    echo "Query not processed".mysql_error();
    }
    }
Question Answered as of 1 Year Ago by TonyG_cyprus, pritaeas, Biiim and 1 other
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article