We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,996 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Stock Recording System

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>
5
Contributors
19
Replies
6 Days
Discussion Span
3 Months Ago
Last Updated
20
Views
Question
Answered
davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

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

INSERT INTO Produk SELECT * FROM stock
pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

no VALUES ?

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

It's all in the manual.

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86

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

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2
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`;
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 104
Solved Threads: 83
Skill Endorsements: 7

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">
davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

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')");
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 104
Solved Threads: 83
Skill Endorsements: 7

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

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

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
)

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

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>
davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

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!

TonyG_cyprus
Posting Whiz
312 posts since Dec 2009
Reputation Points: 46
Solved Threads: 39
Skill Endorsements: 2

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.

diafol
Keep Smiling
Moderator
10,653 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

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!

TonyG_cyprus
Posting Whiz
312 posts since Dec 2009
Reputation Points: 46
Solved Threads: 39
Skill Endorsements: 2

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>
davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

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.

TonyG_cyprus
Posting Whiz
312 posts since Dec 2009
Reputation Points: 46
Solved Threads: 39
Skill Endorsements: 2

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

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

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.

TonyG_cyprus
Posting Whiz
312 posts since Dec 2009
Reputation Points: 46
Solved Threads: 39
Skill Endorsements: 2

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]')");

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

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();
    }
    }
TonyG_cyprus
Posting Whiz
312 posts since Dec 2009
Reputation Points: 46
Solved Threads: 39
Skill Endorsements: 2
Question Answered as of 3 Months Ago by TonyG_cyprus, pritaeas, Biiim and 1 other

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1238 seconds using 2.78MB