Okay this is my code, i can't get the else statement part to work...can anyone kindly assist me...i find nothing wrong with the syntax...thank u...

ps: no error...

<?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'];

$sql="SELECT * FROM $tbl_name WHERE invoice_no = '$invoiceno'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result) or die(mysql_error());

if($row>0)
echo "Invoice No. found";
else
header("location:main_login.php");

?>

Recommended Answers

All 5 Replies

Hi, i think i can see your question. My advice would either be put the curly brackets in ({) and maybe change the statement to if (mysql_num_rows($result) !=0) { ...

if (mysql_num_rows($result) !=0) {
        echo "Invoice No. found";
} else {
        header("location:main_login.php");
}

Thanks,
Marais

commented: Yes +7

Replace your line 17

$row = mysql_fetch_array($result) or die(mysql_error());

with

$row = mysql_num_rows($result);

heyy...thanks for the reply....its still the same....its just showing a blank page when i click the submit.

the previous file, the invoice number comes from here.

<title>Shipping Cross-Check System</title>
<form method="post" name="form">
<h1>Enter your Invoice No. to create a new shipment</h1>
<table>
<tr>
<td>Invoice No. :</td><td><input name="invoiceno" type="text" size"25"></input></td>
</tr>
</table>
<input type="submit" name="submit" value="Back" onclick="form.action='main_login.php';"></input>
<input type="submit" name="submit" value="Submit" onclick="form.action='display.php';"></input>

</FORM>

hahaha...its working....thank u soo much Mr. Karthik...owe you one...

Hmmm, maybe try changing this:

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

to this:

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

Let me know the result.

~Marais

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.