1,105,310 Community Members

stock

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

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?
Member Avatar
cereal
Posting Virtuoso
1,710 posts since Aug 2007
Reputation Points: 461 [?]
Q&As Helped to Solve: 345 [?]
Skill Endorsements: 44 [?]
 
0
 

You are missing the $ sign in front of the variable name, change it to $username, bye!

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

The same goes for the password variable.

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

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();">

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

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.

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

As TonyG said put a closing php tag on line 14 in above code.

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

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--

Member Avatar
cereal
Posting Virtuoso
1,710 posts since Aug 2007
Reputation Points: 461 [?]
Q&As Helped to Solve: 345 [?]
Skill Endorsements: 44 [?]
 
0
 

Probably you get an empty set from this query:

SELECT * FROM PO ORDER BY PO ASC

Try it from a mysql client.

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

I wonder why I get empty set - it should works from localhost mysql

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

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.

Member Avatar
davy_yg
Veteran Poster
1,113 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 
$result = mysql_query('SELECT * FROM PO ORDER BY PO ASC') or die(mysql_error());
    echo $result;

it doesn't print out anything

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

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 />
Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

<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.

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

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.

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

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.

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

Sory it should be:

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

My error when copying.

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

The combo box remains empty

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

This is tricky.

What you get when you run this query in phpmyadmin:

SELECT * FROM PO ORDER BY PO ASC
Member Avatar
davy_yg
Veteran Poster
1,113 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

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

BBQ Snack
Metalik
Rendang
Stik BBQ
Stik biru

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: