A) I would like to have 2 different functions for 1 button. For first click function 1 should start, for second click function 2, for third click function 1, fourth click function 2 ...
For now I need 2 buttons, one disables and the other one enables the possibility to input data in a form field. The best would be to have both functions for 1 button (as explained above).
Does anyone has an idea how to do that?
B) All data get saved and can be reopened in the datamanagementsystem. I would like that disabled fields stay disabled (after reopening the form again) for input. Is there a possibility to do so?
<script>
var nav = false;
function disable18() {
document.getElementById("field1").style.color = "red";
document.getElementById("field1").value = "X";;
document.getElementById("field1").disabled = true;
nav = true;
}
function enable18() {
document.getElementById("field1").disabled = false;
document.getElementById("field1").value = "";
document.getElementById("field1").style.color = "black";
nav = false;
}
function toggleNav() {
if(nav==false){
disable18();
} else {
enable18();
}
}
</script>
How I get the data from database:
<?php
session_start();
require_once 'sc/functions.php';
$user_home = new USER();
if(!$user_home->is_logged_in())
{
$user_home->redirect('index.php');
}
$stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
?>
<?php
// php search data in mysql database using PDO
// set data in input text
$user = "xxx";
$pass = "xxxx";
if(isset($_POST['Find']))
{
// connect to mysql
try {
$pdoConnect = new PDO('mysql:host=localhost;dbname=xxx;charset=utf8', $user, $pass); //mysql:host=localhost;dbname=test_db","root","")
$pdoConnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $exc) {
echo $exc->getMessage();
exit();
}
// id to search
$ID = $_POST['ID'];
// mysql search query
$pdoQuery = "SELECT * FROM dabase WHERE ID = :ID";
$pdoResult = $pdoConnect->prepare($pdoQuery);
//set your ID to the query ID
$pdoExec = $pdoResult->execute(array(":ID"=>$ID));
if($pdoExec)
{
// if ID exist
// show data in inputs
if($pdoResult->rowCount()>0)
{
foreach($pdoResult as $row)
{
$ID = $row['ID'];
$field1 = $row['field1'];
}
}
// if the id not exist
// show a message and clear inputs
else{
header( "Location: nodatasearch.php" ); die;
}
}else{
echo 'ERROR Data Not Inserted';
}
} ?>
Submitting/Saving data:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require("php/tc.php");
$ID = $_POST['ID'];
$field1 = $_POST['field1'];
$sql = "UPDATE pdbase SET
field1 = :field1
WHERE ID = :ID";
$stmt = $dbh->prepare($sql);
$stmt->bindValue(':ID', $ID);
$stmt->bindValue(':field1', $field1);
$stmt->execute();
// var_dump($_POST['user']);
?>