2 Replies - 252 Views - Last Post: 03 October 2017 - 09:25 PM Rate Topic: -----

#1 sunshinee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-October 17

PROBLEM TO INSERT DATA INTO MULTIPLE DB

Posted 03 October 2017 - 07:15 PM

<?php

session_start();

include('connection/config.php');

include('connection/connect.php');

include('function.php');
include('function1.php');

$con=mysqli_connect("localhost","root","","istock");
?>



   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>iStock|PDKL</title>
<link rel="stylesheet" href="styles/staffstyle.css" media="all" />
<link rel="stylesheet" href="styles/dropdown.css" media="all" />
<style type="text/css">
.l {
	color: #000;
}
.h {
	color: #000;
}
.h {
	color: #000;
}
.h {
	color: #000;
}
.h {
	color: #000;
}
.h {
	color: #000;
}
.btn.btn-success.btn-sm .glyphicon.glyphicon-edit {
	color: #000;
}
</style>
</head>
<body>
	
    <!--Main Container Starts here-->
	<div class="main_wrapper">
    
    	<!--header Starts here-->
    	<div class="header_wrapper"><a href="indexadmin.php"></a><img src="images/adminbanner.jpg" width="1150" height="200" id="logo" />
        <br>
       
	
		<div class="menubar">
      
  <div class="dropdown">
				<button class="dropbtn"> Kawalan Stok Keluar Masuk </button>
				<div class="dropdown-content">
				<a href="terima.php">Terimaan</a>
                <a href="keluar.php">Keluaran</a>
				
				</div>
			    <p>&nbsp;</p>
</div>
			  <div class="dropdown">
				<button class="dropbtn"> Kategori</button>
				<div class="dropdown-content">
				<a href="add_cat.php">Tambah Kategori</a>
                <a href="ViewProduct.php">Senarai Kategori</a>
				
				</div>
			    <p>&nbsp;</p>
		</div>
			<div class="dropdown">
				<button class="dropbtn">Laporan</button>
				<div class="dropdown-content">
				<a href="reportsearchmonthly.php">Bulan</a>
				<a href="reportsearchyearly.php">Tahun</a>
				
				</div>
                </br>
			    <p>&nbsp;</p>
             
		</div>
        
		
			<div class="dropdown">
				<a href="index.php"><button class="dropbtn">Daftar Keluar</button></a>
		    
	  	<p>&nbsp;</p>
	 
		</div>
<div id="content_area">
<form action="" method="post" style="padding:80px;">
		<p>&nbsp;</p>
        <table width="1150" border="0" align="center" cellpadding="10" cellspacing="1">
        <tr align="center">
		<td colspan="10"><h2>Daftar Kawalan Stok Baru</h2>&nbsp; </br><input type="submit" name="add_st" value="Daftar Stok" colspan="10" align="right" /></td>
		</tr>
 <table width="auto" border="1" align="center">
  <tr>
    <td width="10">Tarikh</td>
    <td width="10">No.Kad</td>
    <td  width="10">Terima Daripada/Keluar Kepada</td>
    <td  width="10">Terimaan Kuantiti</td>
    <td  width="10">Seunit (RM)</td>
    <td  width="10">Jumlah (RM)</td>
    <td  width="10">Keluaran Kuantiti</td>
    <td width="10">Jumlah (RM)</td>
    <td width="10">Baki Kuantiti</td>
    <td width="10">Baki Jumlah (RM)</td>
    
   
  </tr>
  <tr>
   
    <td><input name="date" type="date" size="5"  placeholder="Tarikh" border="1"/></td>
    <td><input name="no_kad" type="text" size="5"  placeholder="No.Kad" border="1"/></td>
    <td><input name="in_out" type="text"  placeholder="Terimaan/Keluaran" border="1" required/></td>
    <td><input name="in_qty" type="number" size="5" placeholder="Terimaan Kuantiti" border="1"/></td>
    <td><input name="in_unit_price" type="text"  size="10"  placeholder="Harga Seunit" border="1"/></td>
    <td><input name="in_total" type="text" size="10"  placeholder="Jumlah" border="1"/></td>
    <td><input name="out_qty" type="number" size="10"  placeholder="Keluaran kuantiti" border="1"/></td>
    <td><input name="out_total" type="text"  size="10"  placeholder="Jumlah" border="1" /></td>
    <td><input name="blnce_qty" type="number" placeholder="Baki Kuantiti" border="1"  /></td>
    <td><input name="blnce_total" type="text" size="10"  placeholder="Baki Jumlah" border="1" /></td>
   
   
  </tr>
  </br>
  

 
  </table>
  </table>

<center></br>

</form>
<?php
include("includes/db.php");

	if(isset($_POST['add_st'])){
		
		$date = $_POST['date'];
		$no_kad = $_POST['no_kad'];
		$in_out = $_POST['in_out'];
		$in_qty = mysqli_real_escape_string($_POST['in_qty']);
		$in_unit_price = mysqli_real_escape_string($_POST['in_unit_price']);
		$in_total = mysqli_real_escape_string($_POST['in_total']);
		$out_qty = mysqli_real_escape_string($_POST['out_qty']);
		$out_total = mysqli_real_escape_string($_POST['out_total']);
		$blnce_qty = mysqli_real_escape_string($_POST['blnce_qty']);
		$blnce_total = mysqli_real_escape_string($_POST['blnce_total']);
		
		
		$sql = "INSERT INTO stok_data (date, no_kad, in_out) VALUES ('$date', '$no_kad', '$in_out')";
		
		if(!mysqli_query($con, $sql))
		{
			die ('Error' . mysqli_error());
			}
		$new_id = mysqli_insert_id($con);
		
		$sql2 = "INSERT INTO stok_in (in_qty, in_unit_price) VALUES ('$in_qty', '$in_unit_price')";

		
		$new_id2 = mysqli_insert_id($con);
		$sql = "INSERT INTO stok_out (out_qty) VALUES ('$out_qty')";
		
		if(!mysqli_query($con, $sql))
		{
			die ('Error' . mysqli_error());
			}
	}
	?>

This post has been edited by CTphpnwb: 03 October 2017 - 07:27 PM


Is This A Good Question/Topic? 0
  • +

Replies To: PROBLEM TO INSERT DATA INTO MULTIPLE DB

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3714
  • Posts: 13,468
  • Joined: 08-August 08

Re: PROBLEM TO INSERT DATA INTO MULTIPLE DB

Posted 03 October 2017 - 07:29 PM

  • Use prepared statements! SQL injection attacks can be eliminated with them.
  • Provide details about your problem: error messages are important.


I for one do not help with code that doesn't use prepared statements.
Was This Post Helpful? 0
  • +
  • -

#3 benanamen  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 131
  • Joined: 28-March 15

Re: PROBLEM TO INSERT DATA INTO MULTIPLE DB

Posted 03 October 2017 - 09:25 PM

You are not executing the second query. You should really be using PDO. It burns my eyes looking at your code. See #1 and #2 above.

PDO Tutorial
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1