Jump to content

[SOLVED] php blank insert mysql


Danny620

Recommended Posts

when i run this code i want it to insert the future date into the db but when i run it it inserts blanks like so

 

      1 0000-00-00 00:00:00 2

      1 0000-00-00 00:00:00 2

 

it should insert the current date and time i have set heres the code

 

<?php

require_once ('mysqli_connect.php'); 

//Get HQ level.

// Query the database:
	$q = "SELECT hqlevel FROM `construction` WHERE user_id =1 LIMIT 1";		
	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
 $hqlevel = mysqli_fetch_array ($r, MYSQLI_ASSOC);
//End of Hq level

$hqlevel = $hqlevel['hqlevel'];

//Get HQ Buildtime.

// Query the database:
	$q = "SELECT time FROM `build_time` WHERE level = $hqlevel";		
	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
 $buildtime = mysqli_fetch_array ($r, MYSQLI_ASSOC);
//End HQ Buildtime.

   $buildtime = $buildtime['time'];
   $builddate = date("d/m/Y H:i", time() + (60 * $buildtime));
   $userid = 1;//turn it to session when programmed login

//Upgrade to the next level.
if(isset($_POST['upgrade'])){
// Query the database:
	$q = "INSERT INTO construction( user_id, complete, hqlevel ) VALUES ($userid, '$builddate', $hqlevel)";		
	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
//End Upgrade to next level.
echo $builddate;
}
/*
SELECT * 
FROM `build_time` 
LIMIT 0 , 30 */


?>
<form name="form1" method="post" action="">
  <table width="593" height="33" border="0">
    <tr>
      <td width="103" height="29">Headquarters</td>
      <td width="174"><label>
        <input name="upgrade" type="submit" id="upgrade" value="<?php echo "Upgrade to $hqlevel"; ?>">
      </label></td>
      <td width="302"><?php echo "$buildtime minutes taken to construct this building."; ?></td>
    </tr>
  </table>
</form>
<?php
$date = date("d/m/Y H:i");
echo "<b>Server time:</b> $date";  ?>

Link to comment
https://forums.phpfreaks.com/topic/167806-solved-php-blank-insert-mysql/
Share on other sites

Lets assume that you are using data type as datetime in mysql.

Mysql accept datetime in this format. 2009-07-28 12:23:76

After saving, when you are pulling it from mysql. you can change it to other formats to display.

 

If your problem is solved, plz mark thread as solved.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.