Start New Discussion within our Web Development Community

Hello,

I am trying to create a stock recording system:

<h4>STOCK RECORDING SYSTEM</h4>

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

<table border="0" width="200">
<tr>
    <tr>
        <td>Produk  :</td><br>
        <td><input type="text" size="12" maxlength="22" name="Produk"></td>    
    </tr>    
    <tr>
        <td>Jumlah  :</td>
        <td><input type="text" size="12" maxlength="22" name="Jumlah"></td><br> 
    <tr>
        <td>Tanggal :</td>
        <td><input type="text" size="12" maxlength="22" name="Tanggal"></td><br>
    </tr>    
</table>


</form>

<?php

username='root';
password='';

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

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


?>




Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\Innovation\script_shop\stock.php on line 27
Line27:    username='root';

the username is correct.  Why the error still appears?

I am having problem on the combo box.

I have one database : snack
two tables: po and stock

po: po
stock: produk, jumlah, tanggal_masuk

<?php

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

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

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

// combo box

    <select name="batch" onchange="submit();">
    <option value="-1" >-- Select Adress --</option>
    <?php

    $result = mysql_query('SELECT * FROM PO ORDER BY PO ASC') or die(mysql_error());
    while ($item = mysql_fetch_assoc($result))
    {
    echo '<option value="'.$item['po'].'" '.isSelected($item['po'],$batch).'>'.$item['namn'].'</option>';
    }
    ?>
    </select>


?>

I am trying to fill in po with produk type to list all the available products in the combo box.

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\Innovation\script_shop\stock.php on line 39

line 39: <select name="batch" onchange="submit();">

Check your opening and closing php tags. You have one missing.
You should re-write this code referring to a good reference manual as
you are doing it.

Getting close.

I wonder why I do not see the list of products appears in the combo box. I only see // combo box --select address--

Probably you get an empty set from this query:

SELECT * FROM PO ORDER BY PO ASC

Try it from a mysql client.

As cereal said run the query:

SELECT * FROM PO ORDER BY PO ASC

in phpmyadmin (or mysql client) and see if you get the correct resultset for options in your select. If the query returns correct result then check the html code (in Firefox right click -> View page source) and check whether there are no html errors also.

You might want to check whether isSelected($item['po'],$batch) function returns correct value.

$result = mysql_query('SELECT * FROM PO ORDER BY PO ASC') or die(mysql_error());
    echo $result;

it doesn't print out anything

If I view - page source in IE:

// combo box

    <select name="batch" onchange="submit();">
    <option value="-1" >-- Select Adress --</option>
    Resource id #4<br />
<b>Notice</b>:  Undefined index: po in <b>C:\xampp\htdocs\Innovation\script_shop\stock.php</b> on line <b>48</b><br />
<br />
<b>Fatal error</b>:  Call to undefined function isSelected() in <b>C:\xampp\htdocs\Innovation\script_shop\stock.php</b> on line <b>48</b><br />

<b>Fatal error</b>: Call to undefined function isSelected() in <b>C:\xampp\htdocs\Innovation\script_shop\stock.php</b> on line <b>48</b><br />

This is probably the answer: the isSelected() function that you are calling, does not exist. Have you included appropriate file where the function should be defined?

And also

Undefined index: po in <b>C:\xampp\htdocs\Innovation\script_shop\stock.php

means that there are no records since nothing exists in the $item array.

You should temporary remove the isSelected($item['po'],$batch) function and see if you get anything:

while ($item = mysql_fetch_assoc($result))
{
    echo '<option value="'.$item['po'].'" . $item['namn'] . '</option>';
}

The isSelected() function probably only adds selected="selected" to selected option.

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\Innovation\script_shop\stock.php on line 71

that would be line 3.

Sory it should be:

echo '<option value="'.$item['po'].'">' . $item['namn'] . '</option>';

My error when copying.

This is tricky.

What you get when you run this query in phpmyadmin:

SELECT * FROM PO ORDER BY PO ASC

I must first select the database then enter the query: this appears:

BBQ Snack
Metalik
Rendang
Stik BBQ
Stik biru

This is mysterious. The code in the snippet you posted seem to be OK (once corrected with suggestions from other posts). Can you post the whole code? I would have to test it in my environment to try to find something.

This article has been dead for over six months. Start a new discussion instead.