<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
if (isset($_POST['submit'])){
    mysql_query("INSERT INTO Stock (Produk,Jumlah,Tanggal) VALUES ('$_POST[batch]','$_POST[Jumlah]','$_POST[Tanggal]')");
    echo "<script type=\"text/javascript\">
    window.location = \"print.php\";
    </script>";
}
    ?>
    </table>

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

</form>   

<?php

echo mysql_query("SELECT * FROM stock");

?>

This is a form with sql query to view what's stored in the table. I receive this message though:

Produk :
Jumlah :
Tanggal :

Resource id #5
(where the resource id #5 appeared from?)

Recommended Answers

All 5 Replies

hi,

This might be the culprit

echo mysql_query("SELECT * FROM stock");

how to fix it?

if you want to print the result from table stock then you should do something like this.

!IMPORTANT! My mysql techniques are pretty rusty.. it has been a while since I used it in application. I am so accustomed of using a database wrapper..

here we go let me give it another try...

$result = mysql_query("SELECT * FROM stock") 
or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {


echo $row['Produk'].'<br/>';

echo $row['Jumlah'];

} 

that's pretty much it... Just a friendly suggestion... if you will be using this script for more than a year, I highly recommend to use a PDO wrapper or mysqli..

PHP language is going for High Level language status pretty soon ( I mean it is already is, but it has to be refined). So, our conventional ways of writing codes may become old style that will only work on older version of PHP. I have no problem with the procedural, but OOP will be the standard pretty soon..

in fixing it dont echo the execution
if you want to print the statement separate it like

$sql = "select * from table";
echo $sql;
$query = mysql_query($sql);

but if you want to print the result follow veedeoo's advice

Isn't this part of the script from the question you asked before, and marked solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.