Hello all,

Guys need some advise and some help regarding displaying data from database...
so, basically this is what i'm trying to do, have a keyword (invoice_no)...i'm suppose to search the database, and the find record...the display the remaining attributes (document_no,pallet_no and so on)


invoice.php

<FORM ACTION=".php" METHOD=get>
<h1>Enter your Invoice No.</h1>
<table>
<tr>
<td>Invoice No. :</td><td><input name="invoice_no" type="text" size"20"></input></td>
</tr>
</table>
<input type="submit" name="Submit" value="Submit" id="invoiceno"></input>
</FORM>
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="testdata"; // Database name
$tbl_name="testdata"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

$invoiceno=$_POST['invoice_no'];

$sql="SELECT * FROM $tbl_name WHERE invoice_no='$invoiceno'";

?>

can't think of anyway to proceed...thank u in advance

Recommended Answers

All 4 Replies

Member Avatar for diafol

look at the php.net site and search for mysql_fetch_array and mysql_fetch_assoc and mysql_num_rows

Before you even look at getting the query results as @ardav has mentioned, your query will fail anyway as your form variables are wrong to work with what you are trying to do (you have put the method as get then tried to get the value using post - also not sure where your form is supposed to be submitting to with just .php in the action).

Change your form tag to

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

okay...i did some reading and changes to the code....but still cant retrieve the value from the other form

<FORM ACTION="displaydata.php" METHOD="post">
<h1>Enter your Invoice No.</h1>
<table>
<tr>
<td>Invoice No. :</td><td><input name="invoiceno" type="text" size"25"></input></td>
</tr>
</table>
<input type="submit" value="Submit"></input>
</FORM>
<?php
session_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="testing"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die(mysql_error());

$invoiceno = $_POST['invoiceno'];
//echo $invoiceno;

// $sql="SELECT * FROM $tbl_name WHERE invoice_no=='$invoiceno'";
// $result = mysql_query ($sql);
// if ($result) {
// while ($row = mysql_fetch_array ($result)) {
// echo $row[0] . "<br>";
// }
// }
?>

my bad...was running the php file without inserting the value...it works now...thank u and sorry

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.