Ok, I have a table generated from a mysql database after that I insert some datas. For example:
Id Date Title Link Type ...
Now beside every row of the table, there is an Edit button. I'd wish that pressing the button I can open a popup with already filled the fields of the selected row and possibly, after saving it, automatically close the popup and refresh the page with the table, so can show immediately the modified fields. Thank you in advance.
I think I have found a similar one you shall try.. Passing variable to popup box if you have some ajax know-how you shall do it better.
I partially solved my problem in this way:
if(isset($_POST["Go"])){
$servername = "localhost";
$username = "root";
$password = "MickeyGoofyDonald";
$dbname = "MyDb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE video SET
Descrizione='".$_POST["descrizione"]."',
Titolo='".$_POST["titolo"]."',
Link='".$_POST["link"]."',
Tipo='".$_POST["tipo"]."',
Bit='".$_POST["visualizza"]."' WHERE Id= '" .$_POST["id"]."' ;";
if ($conn->query($sql) === TRUE) { ?>
<br>
<div class="alert alert-success alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Successo!</strong><?php echo " Nuovo link creato con successo";
?>
<script>if (window.opener) window.opener.location.reload();
setTimeout('window.close()', 1500)</script>
<?php } else { ?>
</div>
<br>
<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Errore</strong> <?php echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}?>
</div>
</div>
I wrote partially because now i am having a small problem with Mysql: Whenever i insert in the description something that I have to update that contains the symbol ' I get Syntax error on MySql. I have another page similar to this, that istead to update is inserting new records (links) and there everything is ok:
Insertlinks.php:
if(isset($_POST["Go"])){
$servername = "localhost";
$username = "root";
$password = "MickeyGoofyDonald";
$dbname = "MyDb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO linkpage (Id, Descrizione, Link)
VALUES ('".$_POST["NULL"]."','".$_POST["descrizione"]."','".$_POST["link"]."')";
if ($conn->query($sql) === TRUE) { ?>
<br>
<div class="alert alert-success alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Successo!</strong><?php echo " Nuovo link creato con successo";
} else { ?>
</div>
<br>
<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Errore</strong> <?php echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}?>
</div>
</div>
(I know for the Injection vulnerability... i will correct that when i will put it online... for the moment i need only offline on my pc for testing purpose)