JohnyJohnathan Posted July 22, 2016 Share Posted July 22, 2016 <?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"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/301541-data-not-inserted-into-database/ Share on other sites More sharing options...
Jacques1 Posted July 22, 2016 Share Posted July 22, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301541-data-not-inserted-into-database/#findComment-1534831 Share on other sites More sharing options...
chriscloyd Posted July 22, 2016 Share Posted July 22, 2016 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"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/301541-data-not-inserted-into-database/#findComment-1534833 Share on other sites More sharing options...
cyberRobot Posted July 22, 2016 Share Posted July 22, 2016 (edited) 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 July 22, 2016 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/301541-data-not-inserted-into-database/#findComment-1534838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.