Hello,
I am trying to make a system that can check the database A if the record exist before adding it the record to the database B then make a series of number to Database C. I am currently on the checking of database A if the record exist. However I always get a message record does not exist but the record actually exist. My Customer code is the one I am searching to DB A.
I do not know where is my problem here. But kindly have a look. Thanks
[code]
<?php if (isset($_POST['submit'])) { $errorMessage = ''; $con=mysqli_connect('localhost', 'root', 'LNKmis000', 'billing'); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // include 'include/filter.php'; if($errorMessage == '' ) { mysqli_query($con,"INSERT INTO invoice_data ( cust_rec, description, part_number, fob_price, qty, total_fob, trading_price, amount ) VALUES ( '$_POST[customer]', '$_POST[description]', '$_POST[part_number]', '$_POST[fob_price]', '$_POST[qty]', '$_POST[total_fob]', '$_POST[trading_price]', '$_POST[amount]' )"); $errorMessage = 'One record added!'; $cust_code=$_POST['customer'] ; $cust_search = mysqli_query($con,"SELECT rec_no FROM customer_info WHERE rec_no='$cust_code'"); if(mysql_num_rows($cust_search) != 0) { mysqli_query($con,"INSERT INTO invoice_number(company) VALUES ('$cust_code')"); }else { $errorMessage = $errorMessage . 'Customer record does not exist!
'; } } } mysqli_close($con); ?>
<body>
<div id="wrapper">
<?php include('includes/header.php'); ?>
<?php include('includes/nav.php'); ?>
<div id="content">
<h3>Invoice data entry</h3>
<p>
Please fill up the form below to add additional customer.
</p>
<p>
<form method="post">
<fieldset>
<div>
<label for="customer">Customer code</label>
<input name="customer" type="Text" placeholder="Customer Code">
</div>
<div>
<label for="description">Description</label>
<input name="description" type="Text" placeholder="Description">
</div>
<div>
<label for="part_number">Part Number</label>
<input name="part_number" type="Text" placeholder="Part Number">
</div>
<div>
<label for="qty">Quantity Kpcs</label>
<input name="qty" type="Text" placeholder="Quantity Kpcs">
</div>
<div>
<label for="trading_price">Trading Price</label>
<input name="trading_price" type="Text" placeholder="Trading Price">
</div>
<div>
<label for="amount">Amount</label>
<input name="amount" type="Text" placeholder="Amount">
</div>
<?php if ($errorMessage != ''){echo $errorMessage;} ?>
<input value="Create Invoice" name="submit" type="submit">
</fieldset>
</form>
</p>
</div> <!-- end #content -->
</div> <!-- End #wrapper -->
</body>
[/code]