0

I have this PHP code , and i would insert a data in a table. I don't know why , it doesn't work. I receive no error from the query. If i print the $update_miner nothing is showed. This is the code:

<?php


session_start();
include("header.php");
$building['rock_miner'] =3;
$current_time = time();
$update_miner = mysqli_query($connection,"INSERT INTO `updates_queue` (`user_id`,`content`, `start_at`,`end_at`,`finished`,`old_level`) VALUES ('".$_SESSION['uid']."', 'rock_update', '".$current_time."','".$current_time."',0 ,'".$building['rock_miner']."'");




include("footer.php");

?>

This is the table:

enter image description here

5
  • 2
    Try adding ini_set('display_errors', 1); error_reporting(-1); to the top of the page. Also try adding if($update_miner === FALSE){ die(mysqli_error($connection)); }. If an INSERT fails, there's got to be a reason (and an error message). Commented Oct 16, 2015 at 15:04
  • 1
    he said me : syntax error at line 1. What? is the error in <?php ??? Commented Oct 16, 2015 at 15:06
  • 1
    What did the entire message say? Perhaps the error is in the included header.php? Commented Oct 16, 2015 at 15:07
  • it says anlo what i wrote :/ No the error is not in the header. I tried to remove it and nothing changed Commented Oct 16, 2015 at 15:10
  • Is that syntax error from PHP or MySQL? Can you copy and paste the entire message (and edit it into the question)? Commented Oct 16, 2015 at 15:13

2 Answers 2

4

you are missing one parenthesis at last

INSERT INTO `updates_queue` (`user_id`,`content`, `start_at`,`end_at`,`finished`,`old_level`)
VALUES ('".$_SESSION['uid']."', 'rock_update', '".$current_time."',
'".$current_time."',0 ,'".$building['rock_miner']."')")
                                                    ^ 
Sign up to request clarification or add additional context in comments.

Comments

0

Not too sure but wouldn't use int to store a time. Int only goes up to a certain value and then will fail-or just store the highest value it can. I think that might depend on your mysql version though.

The comment before is a good start and make sure you have connected to the database as well.

So your $connection isn't false.

4 Comments

my db is connected. I tried the query in the phpmyadmin and everything works. The problem is the query passed by PHP. I also removed the header and footer include. Nothing changed
Have you tried the previous comment ini_set('display_errors', 1); error_reporting(-1); Will show errors - generally. if($update_miner === FALSE){ die(mysqli_error($connection)); } Will show any errors. Also might be worth a sanity check - are you connected to the right database, I generally have 2. 1 development,1 live. Check both (if you have them)
I wouldn't use INT to store time either, but both PHP and MySQL have functions that allow one to convert to/from a "Unix timestamp" value. Note that you can't use INT(9), however, as that would have overflowed in 2001. Using INT will fail in 2038, and using INT UNSIGNED will fail in 2106.
Yeah I like the unix_timestamp options, but I would store my time as a datetime

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.