I was looking why my mysql doesn’t work, but didn’t find anything helping me in this case.
My issue is that I want to update
my database by insering a date in it with a specific id taken in $_GET
. Here was looking at :
$date = date('Y-m-d', time());
session_start();
header( 'content-type: text/html; charset=utf-8' );
require_once("cnx_db_inventory.php");
$idComputer=$_GET['idComputer'];
$query="select computer.computer_id,
computer.computer_name
from computer
where computer.computer_id='$idComputer'";
$data = get_array($query);
foreach($data as $value) {
$computername=$value['computer_name'];
}
//Update the database
if(isset($_GET['validate'])){
$idComputer;
$query="UPDATE computer
SET deleted_date='$date'
WHERE computer.computer_id=$idComputer";
mysql_query($query);
echo $query;
}
My echo
of my query looks like this went validate :
UPDATE computer SET deleted_date='2017-04-07' WHERE computer.computer_id=
And if I put some quotes (' ') to $idComputer
, the echo gave me this :
UPDATE computer SET deleted_date='2017-04-07' WHERE computer.computer_id=”
But it gave me the id if I echo outside the isset()
(see here).
Why then, when I click on validate, the computer_id
didn’t pass through?
My form look like this :
<form id="general" name="general" action="delete.php" method="get">
Are you sure you want to delete this?<br />
<strong><font size="2" color ="black">Computer name </font></strong>
<input type="text" id="computername" name="computername" value="<?php echo $computername;?>"/><br />
<input type="submit" name="validate" value="Validate" class="button">
<input type="submit" name="cancel" class="button" value="Cancel" onClick="general.action='researchInventory.php'; return true;"/>
</form>
I try to put the $IdComputer
in the isset, but doesn’t change anything. I’ve got a similar issue like that before and that was helping me fixed it, but not in this case. I try to pass the mysql_query outside the if(){}
. I try to call computer.deleted_date
in the SELECT
, but give nothing has well.
I try to put an hidden input with the value of computer_id
, try the $_post
method (looking with this one), but nothing change when I validate! The computer_id
doesn't pass anyway.
class DBConnection{
private static $_singleton;
private $_connection;
private function __construct(){
$ip =$_SERVER['REMOTE_ADDR'];
$this->_connection = @mysqli_connect(DB_HOST, DB_USER, DB_PASS,DB_NAME) or die("Could not connect to database");
mysqli_set_charset($this->_connection,"utf8");
}
public static function getInstance(){
$ip =$_SERVER['REMOTE_ADDR'];
if (is_null (self::$_singleton)) {
self::$_singleton = new DBConnection();
mysqli_set_charset('utf8');//Line 20;
}
return self::$_singleton;
}
public function getHandle(){
return $this->_connection;
}
}