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

stock

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

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

cereal
Veteran Poster
1,144 posts since Aug 2007
Reputation Points: 344
Solved Threads: 222
Skill Endorsements: 22

The same goes for the password variable.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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

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

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.

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

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

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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

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

Probably you get an empty set from this query:

SELECT * FROM PO ORDER BY PO ASC

Try it from a mysql client.

cereal
Veteran Poster
1,144 posts since Aug 2007
Reputation Points: 344
Solved Threads: 222
Skill Endorsements: 22

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

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

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.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
$result = mysql_query('SELECT * FROM PO ORDER BY PO ASC') or die(mysql_error());
    echo $result;

it doesn't print out anything

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

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

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

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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.

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

Sory it should be:

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

My error when copying.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

The combo box remains empty

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

This is tricky.

What you get when you run this query in phpmyadmin:

SELECT * FROM PO ORDER BY PO ASC
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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

BBQ Snack
Metalik
Rendang
Stik BBQ
Stik biru

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

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.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1267 seconds using 2.75MB