Jump to content

Recommended Posts

<?php

 

 

$host= "localhost";

$username="root";

$password="root";

$db_name= "test2.0";

 

 

$tbl_name="permohonan";

 

mysql_connect("$host","$username","$password")or die ("cannot connect");

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

 

 

 

if(isset($_POST['submit']))

{

$Jabatan = mysql_real_escape_string($_POST['Jabatan']);

$unit = mysql_real_escape_string($_POST['unit']);

$lain2 = mysql_real_escape_string($_POST['lain2']);

$nama_pemohon = mysql_real_escape_string($_POST['nama_pemohon']);

$destinasi = mysql_real_escape_string($_POST['destinasi']);

$tujuan = mysql_real_escape_string($_POST['tujuan']);

$maklumat_ = mysql_real_escape_string($_POST['maklumat_']);

$datedepart_= mysql_real_escape_string($_POST['datedepart_']);

$timedepart_= mysql_real_escape_string($_POST['timedepart_']);

$datearrive_ = mysql_real_escape_string($_POST['datearrive_']);

$timearrive_ = mysql_real_escape_string($_POST['timearrive_']);

 

 

 

 

$query1 = mysql_query("INSERT INTO permohonan VALUES(NULL,'$Jabatan','$unit','$lain2','$nama_pemohon','$destinasi','$tujuan','$maklumat_','$datedepart_','$timedepart_,'$datearrive_',$timearrive_')");

 

if($query1)

{

header("location : reservationform.php");

}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/301541-data-not-inserted-into-database/
Share on other sites

Write a coherent problem description with specific information (error messages, observations, things you've tried), format your code properly with code tags, and then we might be able to help you.

 

The mysql_* functions you're using are obsolete since more than a decade and have been removed from recent PHP versions.

Try this

 

<?php
$host     = "localhost";
$username = "root";
$password = "root";
$db_name  = "test2.0";
$tbl_name = "permohonan";
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");
if (isset($_POST['submit'])) {
    $Jabatan      = mysql_real_escape_string($_POST['Jabatan']);
    $unit         = mysql_real_escape_string($_POST['unit']);
    $lain2        = mysql_real_escape_string($_POST['lain2']);
    $nama_pemohon = mysql_real_escape_string($_POST['nama_pemohon']);
    $destinasi    = mysql_real_escape_string($_POST['destinasi']);
    $tujuan       = mysql_real_escape_string($_POST['tujuan']);
    $maklumat_    = mysql_real_escape_string($_POST['maklumat_']);
    $datedepart_  = mysql_real_escape_string($_POST['datedepart_']);
    $timedepart_  = mysql_real_escape_string($_POST['timedepart_']);
    $datearrive_  = mysql_real_escape_string($_POST['datearrive_']);
    $timearrive_  = mysql_real_escape_string($_POST['timearrive_']);
    $query1       = mysql_query("INSERT INTO permohonan VALUES(NULL,'$Jabatan','$unit','$lain2','$nama_pemohon','$destinasi','$tujuan','$maklumat_','$datedepart_','$timedepart_,'$datearrive_',$timearrive_')");
    if ($query1) {
        header("location : reservationform.php");
    }
    else
    {
      echo mysql_errno() . ": " . mysql_error() . "\n";
    }
}
?> 

You're missing a few quotes around the values. Try this:

$sql = "INSERT 
        INTO permohonan 
        VALUES (
            NULL, 
            '$Jabatan', 
            '$unit', 
            '$lain2',
            '$nama_pemohon',
            '$destinasi',
            '$tujuan',
            '$maklumat_',
            '$datedepart_',
            '$timedepart_',
            '$datearrive_',
            '$timearrive_'
        )";
$query1 = mysql_query($sql);
Edited by cyberRobot
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.