Page 1 of 1
Barcode Search Thing..
Posted: Mon Oct 21, 2002 11:50 am
by Dale
Could someone please tell me how to do this:
Have a form on your webpage that when you enter in a 12 digit number and press search it use's the database to get just that number and tell you the following information:
Product Name:
Product Barcode No. :
Product Price:
And if the number that you entered ISNT in the database then it says "Sorry, But this product hasnt been put into the database"
Thanks

Posted: Mon Oct 21, 2002 12:27 pm
by twigletmac
Well you do a
SELECT on the data from the form and then you can use
mysql_num_rows() to see how many results there were. You use this info in an if statement to determine what information you show.
Mac
Posted: Mon Oct 21, 2002 12:31 pm
by Dale
:shrug: Dont understand.
Posted: Mon Oct 21, 2002 12:42 pm
by twigletmac
You need a form with a textbox into which people can enter the data.
You have to compare the data the user entered to the data that's in the database:
Code: Select all
$sql = "SELECT name, price FROM table WHERE barcode = '{$_POSTї'barcode']}'";
@$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
echo 'Product Name: '.$rowї'name'];
echo '<br />';
echo 'Product Barcode No.: '.$_POSTї'barcode'];
echo '<br />';
echo 'Product Price: '.$rowї'price'];
} else {
echo 'Sorry, But this product hasnt been put into the database';
}
Obviously I know nothing about the names of the relevant fields in your database so you'll have to change that, I also don't know what you've called the field on your form or what version of PHP you are running.
Mac
Posted: Mon Oct 21, 2002 2:29 pm
by Dale
So... this is just a random think back excersise...
index.php
Code: Select all
<?php
include("header.php");
?>
<form method="POST" action="search.php">
Barcode Number:<br>
<input type="text" name="barcode" size="20">
<br><br>
<input type="submit" value="Submit" name="B1">
</form>
<?php
include("footer.php");
?>
search.php
Code: Select all
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("dale", $db);
$sql = "SELECT name, price FROM table WHERE barcode = '{$_POSTї'barcode']}'";
@$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
echo 'Product Name: '.$rowї'name'];
echo '<br />';
echo 'Product Barcode No.: '.$_POSTї'barcode'];
echo '<br />';
echo 'Product Price: '.$rowї'price'];
} else {
echo 'Sorry, But this product hasnt been put into the database';
}
?>
Im going to test that now

Posted: Wed Oct 23, 2002 4:48 pm
by Dale
Neado it works!!!!!!!!1111#
Thanks twigletmac for the coding bits and then i done the rest in he database
