[SOLVED] sql query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

[SOLVED] sql query

Post by g3ckO »

Code: Select all

<?php
<?

include("database.php");

define('HOST', 'localhost');
define('USER', 'root');
define('PASS', '');
define('DB', 'db1');


   	$nama = $_POST['nama'];
	$jawatan = $_POST['jawatan'];
	$staffNo = $_POST['StaffNo'];
        $unit = $_POST['unit'];
	$jenis = $_POST['jenis'];
	$datemula = $_POST['datemula'];
	$datetamat = $_POST['datetamat'];
	$jumlah = $_POST['jumlah'];
	$datemohon = $_POST['datemohon'];

	$RefID = "L(".$staffNo.")(".$datemohon.")";	


global $conn;

$query = "INSERT INTO leave VALUES ('$nama', '$jawatan', '$staffNo', '$unit', '$jenis', '$datemula', '$datetamat', '$jumlah', '$jumlah', 

'$datemohon', '$RefID')";

 mysql_query($query,$conn);
  

?>
	<br><br><center>YOUR APPLICATION HAVE BEEN SUBMITTED.</center>
?>
Why the data doesn't added to the database??
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

this

Code: Select all

$query = "INSERT INTO leave VALUES ('$nama', '$jawatan', '$staffNo', '$unit', '$jenis', '$datemula', '$datetamat', '$jumlah', '$jumlah',  '$datemohon', '$RefID')";
will not work because you are not telling mysql what fields you want the values to be inserted into..

ie, the query should look like this :

Code: Select all

$query = "INSERT INTO leave (field1, field2, field3, field4, field5, field6, field7, field8, field9, field10,field11) VALUES ('$nama', '$jawatan', '$staffNo', '$unit', '$jenis', '$datemula', '$datetamat', '$jumlah', '$jumlah', '$datemohon', '$RefID')";
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

I do like this but still doesn't work:

Code: Select all

<?php
$query = "INSERT INTO leave (Nama, Jawatan, StaffNo, Unit, Jenis, DateMula, DateTamat, Jumlah, DateMohon, RefID) VALUES ('$nama', 
'$jawatan', '$staffNo', '$unit', '$jenis', '$datemula', '$datetamat', '$jumlah', '$jumlah', '$datemohon', '$RefID')";
?>
User avatar
g3ckO
Forum Contributor
Posts: 117
Joined: Mon Jul 12, 2004 2:57 am
Location: Malaysia
Contact:

Post by g3ckO »

Sorry guys.. Its work now... Just some typing error.. :)

Really sorry... TQ
Post Reply