I am beginner in php , i am trying to update specific row but does not work . i need your help: update.php DIR . '/db_connect.php'; // connecting to db $db = new DB_CONNECT();
if (isset($_POST['id'])) {
$id = $_POST["id"];
$location = $_POST["location"];
$sql=mysql_query("UPDATE citizenalert set location={'$location'} WHERE id ={'$id'}");
}
?>
db_config.php
<?php
define('DB_USER', "root"); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', "ikirenga"); // database name
define('DB_SERVER', "localhost"); // db server
?>
db_connect.php
<?php
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>
request_update.php
<!doctype html>
<html lang="en">
<body>
<form name="updates" method="post" action="update.php" >
<label>User location</label> <input id="location" type="text" name="location" > <br><br>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>