1

I am confused about a MySql query that I have created. The query is not able to insert data into the database when I run the code. I'm trying to figure out what happened. When I try to run it on my localhost, there are no error found, the query inserted.. I'm using PHP 5.6 and my web server is also using PHP 5.6.

<?php 
    include 'koneksi.php';
    $user = $_POST['username'];
    $pass = $_POST['password'];
    $nama = $_POST['nama'];
    $mail = $_POST['email'];
    $tlp  = $_POST['telp'];
    $date = date("j F Y");
    $invoice = mt_rand(100000, 999999);
    if ($_POST['pack'] === 'Basic') {
        $pack_name = 'Basic Pack';
        $price = '$5';
        $permiti = 'basic';
        $limit = '15';
    } elseif ($_POST['pack'] === 'Premium') {
        $pack_name = 'Premium Pack';
        $price = '$10';
        $permiti = 'premium';
        $limit = '20';
    } elseif ($_POST['pack'] === 'Pro') {
        $pack_name = 'Pro Pack';
        $price = '$15';
        $permiti = 'pro';
        $limit = '25';
    } elseif ($_POST['pack'] === 'Ultimate') {
        $pack_name = 'Ultimate Pack';
        $price = '$20';
        $permiti = 'ultimate';
        $limit = '99';
    } else {

    }
    $permit = 'member';
    $start = date("md");
    $end = date("md", strtotime(date("md", strtotime($start)). " + 30 day"));
    $start_date = date("j F Y");
    $end_date = date("j F Y", strtotime(date("j F Y", strtotime($start_date)). " + 30 day"));

    $encrypts = md5($nama);

        $check = mysql_query("SELECT * FROM user WHERE username = '$user'");
    if(mysql_num_rows($check) <> 0 ){
        header("location:register.php?message=fail");
    } else {
        if(!$user || !$pass || !$mail || !$nama || !$tlp){
            echo 'Terdapat data yang kosong<br/>';
            echo '<a href="register.php">Back</a>';
        } else {
            $save = mysql_query("INSERT INTO user VALUES('', '$nama', '$user', '$pass', '$date', '$mail', '$tlp', '$permit')");
            $gets = mysql_query("INSERT INTO user_pack VALUES('', '$pack_name', '$user', '$start', '$end', '0', '$limit', '$price', '$permiti', '$encrypts', '$invoice', '$start_date', '$end_date', '0')");
            if($save || $gets){
                session_start();
                $_SESSION['username'] = $user;
                $_SESSION['status'] = 'login';
                header("location:user/invoice.php");

            } else {
                header("location:register_pack.php?message=fail1");
            }   
        }
    }

?>

Please help me :(

2
  • So are you saying if you echo your queries, $save and $gets and paste the generated SQL of each of those into your localhost phpmyadmin SQL tab or similar, that they worked? Commented Oct 23, 2016 at 6:04
  • This problem is solve. The problem is in my fault. i didnt check the query that i have import to the database.. i dont know why this is happend, but every time when i want to import all of the data from my localhost to my online web it also have the same problem.. Now its done, i have put all the query table one by one. Commented Nov 2, 2016 at 22:20

1 Answer 1

3
you have to put names of your columns in you sql query

$save = mysql_query("INSERT INTO `user`(``, ``, ``, ``, ``, ``, ``, ``) VALUES('', '$nama', '$user', '$pass', '$date', '$mail', '$tlp', '$permit')");
$gets = mysql_query("INSERT INTO `user_pack`(``, ``, ``, ``, ``, ``, ``, ``, ``, ```, ``, ``, ``, ``) VALUES('', '$pack_name', '$user', '$start', '$end', '0', '$limit', '$price', '$permiti', '$encrypts', '$invoice', '$start_date', '$end_date', '0')");
Sign up to request clarification or add additional context in comments.

3 Comments

. . The names of columns should be in the query but they are not required.
@GordonLinoff i didnt know that to be honest, thanks Gordon
Thank you for your help,. i appriciated that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.