I can't get my form to submit. I used similar code to submit a different form and it worked fine, I just can't see why it does not work this time.
I don't get any errors. I tried error reporting I couldn't get any errors. The form input is sticky so the page reloads and the input is still there.
This is my html form:
<form action="evenement_maken.php" method="POST" enctype="multipart/form-data">
<input type="text" name="ev_naam" class="input-lg form-control" value='<?php echo (isset($_POST['ev_naam']) ? $_POST['ev_naam'] : "" );?>'>
<input type="text" name="ev_datum">
<input type="text" name="ev_adres" class="input-lg form-control" placeholder="Vul hier het adres van het evenement in..." value='<?php echo (isset($_POST['ev_adres']) ? $_POST['ev_adres'] : "" );?>'>
<textarea class="input-lg form-control" rows="10" name="ev_omschrijving" id="textarea" placeholder="Korte omschrijving van het evenement...">
<?php
if(isset($_POST['ev_omschrijving'])){
echo htmlentities($_POST['ev_omschrijving'], ENT_QUOTES);
}
?>
</textarea>
<button type="submit" class="pull-right btn btn-danger" name="submit">Opslaan</button>
</form>
And my php code:
<?php
$ev_naam = $ev_datum = $ev_omschrijving = $ev_adres = "";
if(isset($_POST['submit'])) {
$ev_naam = mysqli_real_escape_string($conn, $_POST['ev_naam']);
$ev_datum = mysqli_real_escape_string($conn, $_POST['ev_datum']);
$ev_omschrijving = mysqli_real_escape_string($conn, $_POST['ev_omschrijving']);
$ev_adres = mysqli_real_escape_string($conn, $_POST['ev_adres']);
if ($ev_naam=='') {
echo "<script>alert('Vul alsjeblieft alle velden in!')</script>";
exit();// zorgt ervoor dat de rest van het script niet wordt uitgevoerd
} else {
$insert_evenementen = "INSERT INTO evenementen (ev_naam,ev_datum,ev_omschrijving,ev_adres)
VALUES ( '$ev_naam','$ev_datum','$ev_omschrijving','$ev_adres')";
$run_evenementen = mysqli_query($conn, $insert_evenementen);
if (mysqli_query($conn, $insert_evenementen)) {
echo "<script>alert('Post is succesvol opgeslagen!')</script>";
echo "<script>window.open('evenement_maken.php','_self')</script>";
}
}
}
?>
This is the form that does submit properly (only uploading the img to ftp is not working):
<form action="post_maken.php" method="post" enctype="multipart/form-data">
<h4>Titel: </h4>
<input type="text" name="post_titel" class="input-lg form-control" value='<?php echo (isset($_POST['post_titel']) ? $_POST['post_titel'] : "" );?>' required>
<h4>Inhoud: </h4>
<textarea class="input-lg form-control" rows="10" name="post_inhoud" id="textarea" required>
if(isset($_POST['post_inhoud'])){
echo htmlentities($_POST['post_inhoud'], ENT_QUOTES);
}
?>
</textarea>
<h4>Categorie:</h4>
<select class="form-control" name="categorie_id" >
<option value="null" >selecteer een categorie...</option>
<?php
$categorie = mysqli_query($conn, "SELECT * FROM categorie");
while ($cat_row=mysqli_fetch_array($categorie, MYSQLI_ASSOC)) {
$cat_naam=$cat_row['cat_naam'];
echo "<option value='$cat_naam'>$cat_naam</option>";
}
</select>
<h4>Afbeelding toevoegen</h4>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-primary btn-file">
Zoeken…
</span>
</span>
</div>
<input type="file" name="post_img"/>
<p class="help-block">Voeg een afbeelding voor je blogpost toe.</p>
<br>
<button type="submit" class="pull-right btn btn-danger" name="submit">Opslaan</button>
</form>
And the php code:
<?php
$post_titel = $post_datum = $post_inhoud = $categorie_id = "";
if(isset($_POST['submit'])) {
$post_titel = mysqli_real_escape_string($conn, $_POST['post_titel']);
$post_datum = mysqli_real_escape_string($conn, date('m-d-y'));
$post_inhoud = mysqli_real_escape_string($conn, $_POST['post_inhoud']);
$categorie_id = mysqli_real_escape_string($conn, $_POST['categorie_id']);
$post_img = mysqli_real_escape_string($conn, $_FILES['post_img']['name']);
$post_img_tmp = mysqli_real_escape_string($conn, $_FILES['post_img']['tmp_name']);
if ($post_titel=='' || $categorie_id=='null' || $post_inhoud=='') {
echo "<script>alert('Vul alsjeblieft alle velden in!')</script>";
exit();
} else {
move_uploaded_file($post_img_tmp, "post_img/$post_img");
$post_bron = 0;
$post_datum = date("y-m-d");
$insert_posts = "INSERT INTO post (post_title,post_inhoud,post_datum,categorie_id, post_img, post_bron)
VALUES ( '$post_titel','$post_inhoud','$post_datum','$categorie_id','$post_img','$post_bron')";
$run_posts = mysqli_query($conn, $insert_posts);
if (mysqli_query($conn, $insert_posts)) {
echo "<script>alert('Post is succesvol opgeslagen!')</script>";
echo "<script>window.open('post_maken.php','_self')</script>";
}
}
}
?>
I am retrieving values from both databases (connection workes) and displaying it on the website, that also works. I'm using bootstrap 3.
Screenshot of my database table:
Can anyone see what I am doing wrong? I have been staring at this for hours.
You probably have a SQL error. Its always good to check and output mysqli_erros when they occur. Switch your code up to do this
if (mysqli_query($conn, $insert_evenementen)) {
// query was succesful
}else{
echo mysqli_erro($cnon); // sthing went wrong
}
Your code is open to SQL injection, I suggest you look into prepared statements
<?php
//procedural example from http://php.net/manual/en/mysqli.prepare.php
$city = "Amersfoort";
/* create a prepared statement */
if ($stmt = mysqli_prepare($link, "SELECT District FROM City WHERE Name=?")) {
/* bind parameters for markers */
mysqli_stmt_bind_param($stmt, "s", $city);
/* execute query */
mysqli_stmt_execute($stmt);
/* bind result variables */
mysqli_stmt_bind_result($stmt, $district);
/* fetch value */
mysqli_stmt_fetch($stmt);
printf("%s is in district %s\n", $city, $district);
/* close statement */
mysqli_stmt_close($stmt);
}
Related
I have a registration form and when people compile the form and submit it I want to show a popup, but the problem is it's not working. here is the code:
<?php
// result is when it's all good
if ($result) {
echo '<div class="vai-accedi">
<div class="vai-accedi2">
<div class="vai-accedi3">
<p>Congratulazioni! Registrazione Completata, puoi procedere ad accedere al tuo account. clicca ok per procedere</p>
Ok
</div>
</div>
</div>';
}
?>
All the code
<!-- signup backend connection -->
<?php
include 'dbcon.php';
session_start();
// error_reporting(0);
// if (isset($_SESSION['nome'])) {
// header("Location: header.php");
// }
if (isset($_POST['submit'])) {
$nome = mysqli_real_escape_string($conn,$_POST['nome']);
$cvn = mysqli_real_escape_string($conn,$_POST['cittàvn°']);
$numerodicell = mysqli_real_escape_string($conn,$_POST['numerodicell']);
$email = mysqli_real_escape_string($conn,$_POST['email']);
$password = mysqli_real_escape_string($conn,$_POST['password']);
$confpassword = mysqli_real_escape_string($conn,$_POST['confpassword']);
$password = md5($_POST['password']);
$confpassword = md5($_POST['confpassword']);
if ($password == $confpassword) {
$sql = "SELECT * FROM utenti WHERE email='$email'";
$result = mysqli_query($conn, $sql);
if (!$result->num_rows > 0) {
$sql = "INSERT INTO utenti (nome,cittàvn°, numerodicell, email, password, confpassword)
VALUES ('$nome','$cvn','$numerodicell','$email','$password','$confpassword')";
$result = mysqli_query($conn, $sql);
if ($result) {
// echo "<script>alert('Congratulazioni! Registrazione Completata, puoi procedere ad accedere al tuo account. clicca ok per procedere')</script>";
echo '<div class="vai-accedi">
<div class="vai-accedi2">
<div class="vai-accedi3">
<p>Congratulazioni! Registrazione Completata, puoi procedere ad accedere al tuo account. clicca ok per procedere</p>
Ok
</div>
</div>
</div>';
// header( "Refresh:1; url='login.php'");
$nome = "";
$cvn = "";
$numerodicell = "";
$email = "";
$_POST['password'] = "";
$_POST['confpassword'] = "";
} else {
echo "<script>alert('oops! qualcosa è andato storto.')</script>";
}
} else {
echo "<script>alert('oops! Email già registrata.')</script>";
}
} else {
echo "<script>alert('le due password non combaciano.')</script>";
}
}
?>
<!-- signup backend connection -->
<div class="registrati">
<div class="registratiinner registratiinner2">
<h1>Registrati</h1>
<form action="" class="sign-up-form" method="POST" style="width:100%;">
<div class="input-wrapper">
<input type="text" placeholder="Nome" name="nome" required>
</div>
<div class="input-wrapper">
<input type="text" placeholder="Citta,Via,n°" required name="cittàvn°">
</div>
<div class="input-wrapper">
<input type="text" placeholder="Numero di Cellulare" required name="numerodicell">
</div>
<div class="input-wrapper">
<input type="email" placeholder="Email" required name="email">
</div>
<div class="input-wrapper">
<input type="password" placeholder="Crea una Nuova Password" required name="password">
</div>
<div class="input-wrapper">
<input type="password" placeholder="Conferma Password" required name="confpassword">
</div>
<div class="accetti">
<p style="font-size: 1.8rem; margin-top: 0;">Inviando accetti Termini & Condizioni</p>
</div>
<button type="submit" class="contact-button" style="border-radius: .5rem;" name="submit" type="submit">Registrati</button>
</form>
I'm doing something like a posting tool and it was working fine with the data being inserted on the database. I decided adding the field link and this error appeared:
Recoverable fatal error: Object of class mysqli could not be converted to string in C:\xampp\htdocs\Pequeno Davi 2 Versão completa\Painel de postagens\armazenar_postagens.php on line 23
My code:
<body>
<div class="col-md-4"></div>
<div class="col-md-4">
<div id="well well-sm">
<div id="panel">
<form action="armazenar_postagens.php" method="POST" enctype="multipart/form-data">
<h4>Escolha uma imagem de capa</h4>
<p><input type="file" name="image" id="image" class="form form-control"/></p>
<h4>Título da publicação</h4>
<p><input type="text" name="titulo" id="titulo" placeholder="Insira um título" class="form form-control"/></p>
<h4>Texto da publicação</h4>
<p><textarea name="descricao" id="descricao" placeholder="Texto da publicação" class="form form-control"></textarea></p>
<h4>Link</h4>
<p><input type="text" name="link" id="link" placeholder="Insira o endereço de um link" class="form form-control"/></p>
<h4>Adicione uma imagem para o corpo da publicação</h4>
<p><input type="file" name="image_imagem" id="image_imagem" class="form form-control"/></p>
<button type="submit" class="btn btn-primary form-control">Publicar</button>
</form>
<!--<?php
//if($campo_vazio == 1){
//echo '<font color="#FF0000">Você não preencheu algum dos campos!</font>';
//}
?> -->
</div>
</div>
</div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
<?php
require_once('db.class.php');
$titulo = $_POST['titulo'];
$descricao = $_POST['descricao'];
$link = $_POST['link'];
date_default_timezone_set('America/Sao_Paulo');
$data = date("d/m/Y");
$hora = date("H:i");
$uploaddir = 'imagens/uploads/';
$uploadfile = $uploaddir.basename($_FILES['image']['name']);
$imagename = $uploaddir.basename($_FILES['image']['name']);
$objDb = new db();
$link = $objDb-> conecta_mysql ();
if(move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)){
echo "Imagem enviada com sucesso";
$sql = "INSERT INTO postagens(titulo, descricao, data, hora, imagem_capa, link) VALUES ('$titulo', '$descricao', '$data', '$hora', '$imagename', '$link')";
echo'<img src="'.$imagename.'"/>' ;
if(mysqli_query($link, $sql)){
if(empty($titulo) || empty($descricao)){
header('Location: Ferramenta_postagem.php?campo_vazio=1');
}else{
header('Location: Ferramenta_postagem.php');
}
} else {
echo 'Erro ao registrar postagem!';
echo("Error description: " . mysqli_error($link));
}
}
?>
This line causes the problem
if(mysqli_query($link, $sql)){
You defined at the start
$link = $_POST['link'];
And in the middle
you used following code
$link = $objDb-> conecta_mysql ();
Where used the same varaible name
but mysqli_query($link expects a mysql connection instead of your $Link defined at the start
Exchange $link with $conn and use that in
$conn = $objDb-> conecta_mysql ();
----
mysqli_query($conn,sql
And please read up on prepared statements because of sql injection
Change your database connection variable $link.
You used this variable ($link) in POST method for data input, and also use database connection variable
$link = $objDb-> conecta_mysql ();
Change this variable like this:
$connect = $objDb-> conecta_mysql ();
If you change this variable then you should also change those line
if(mysqli_query($connect, $sql)){
And
echo("Error description: " . mysqli_error($connect));
I have passed a variable using GET to a new page and will like to insert the value into a table in my database but it is saying undefined variable $exex. I tried to echo it inside the 'submit' if statement but it is not seen there either. It only echo the variable inside the isset GET if statement.
Below is the code:
<?php
session_start();
include "includes/connec.inc.php";
if (isset($_GET['exid'])){
$exex=$_GET['exid'];
}
$sql = "SELECT id FROM eaouser WHERE email = '" . $_SESSION['email'] . "'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result);
$eaofid=$row['id'];
if (isset($_POST['submit'])){
if (isset($_POST['feedbacks'])){
$feedback = $_POST['feedbacks'];
if (!empty($feedback)){
$INSERT = "INSERT Into feedback (exfid,eaofid,comment) values(?,?,?)";
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("iis", $exex, $eaofid, $feedback);
$stmt->execute();
if ($stmt==TRUE){
echo "<script> alert('Feedback sent!');
window.location='feedback.php'
</script>";
}else{
echo "<script> alert('Error sending feedback!');
window.location='feedback.php'
</script>";
}
}else{
echo "<script> alert('Feedback form is empty!');
window.location='feedback.php'
</script>";
}
}
}
HTML:
<div class="panel-body">
<form method="POST" action="feedback.php">
<div class="form-group">
<label for="message-text" class="col-form-label">Comment on the experiment:</label>
<textarea class="form-control" name="feedbacks" cols="142" rows="5" placeholder="Type here..."></textarea>
<br>
<button type="submit" name="submit" class="btn" style="background-color: purple;color: white">Send feedback</button>
</div>
</form>
</div>
i'm here trying to learn some php but i'm having some problems with my code now i'm trying to solve the "getimagesize(): Filename cannot be empty" but there are many others like:/
-Undefined variable: date/
-Undefined variable: imgData /
And yes i've tried other codes and still have the same problem/
So here's my code.
<?php
$link = mysqli_connect("blah", "blah", "blah", "blah");
if($link === false){
die("ERRRO: Não foi possivel a conexão com a base de dados. " . mysqli_connect_error());
}
if(!empty($_FILES['userImage']['tmp_name'])
&& file_exists($_FILES['userImage']['tmp_name'])) {
$imgData= addslashes(file_get_contents($_FILES['userImage']['tmp_name']));
}
$imageProperties = getimageSize($_FILES['userImage']['tmp_name']);
$portal = mysqli_real_escape_string($link, $_POST['field1']);
$datacri = mysqli_real_escape_string($link, $_POST['field2']);
$datacri = date('Y-m-d', strtotime(str_replace('-', '/', $date)));
$datapub = mysqli_real_escape_string($link, $_POST['field3']);
$datapub = date('Y-m-d', strtotime(str_replace('-', '/', $date)));
$titulo = mysqli_real_escape_string($link, $_POST['field4']);
$keyword = mysqli_real_escape_string($link, $_POST['field5']);
$hashtags = mysqli_real_escape_string($link, $_POST['field6']);
$pedido = mysqli_real_escape_string($link, $_POST['field7']);
$autor = mysqli_real_escape_string($link, $_POST['field8']);
if (!$portal) {
echo '<script type="text/javascript"> alert("Preencha todos os campos "); </script>';
mysqli_close($link);
}
$sql = "INSERT INTO pedidos (p_portal, p_datacri, p_datapub, p_titulo, p_titulo, p_keywords, p_hashtags, p_imageType, p_imageData, p_pedido, p_autor)
VALUES('$portal', '$datacri', '$datapub', '$titulo', '$keyword', '$hashtags', '{$imageProperties['mime']}', '{$imgData}', '$pedido', '$autor')";
if(mysqli_query($link, $sql)){
echo '<script type="text/javascript"> alert("Portal Criado"); </script>';
} else{
echo "ERRO: Não foi possivel executar o comando $sql. " . mysqli_error($link);
}
?>
And my html file:
<form action="php\pedidos\p_ins.php" enctype="multipart/form-data" method="post">
<link rel="stylesheet" href="css\pedidos.css">
<fieldset>
<legend><span class="number">1</span> Criar Pedido</legend>
<label for="portal">Portal</label
<?php
$link = mysqli_connect("blah", "blah", "blah", "blah");
if($link === false){
die("ERRRO: Não foi possivel a conexão com a base de dados. " . mysqli_connect_error());}
$result = $link->query("select po_id, po_nome from portais");
echo "<html>";
echo "<body>";
echo "<select name='field1' name='po_id'>";
echo "<option value=''>----Selecione um Portal----</option>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['po_id'];
$name = $row['po_nome'];
echo '<option value="'.$id.'">'.$name.'</option>';
} echo "</select>";
echo "</body>";
echo "</html>";?>
<label>Data de Criação</label>
<input type="date" name="field2" placeholder="Data de publicacao do Post">
<label>Data de Publicação</label>
<input type="date" name="field3" placeholder="Data de publicacao do Post">
<label>Titulo</label>
<input type="text" name="field4" placeholder="Insira aqui o Titulo">
<label>Keywords</label>
<input type="text" name="field5" placeholder="Insira aqui as Keywords">
<label>Hashtags</label>
<input type="text" name="field6" placeholder="Insira aqui as Hashtags">
<label>Imagem</label>
<p> </p>
<input type="file" name="userImage" accept="image/*" class="inputFile"> <p> </p>
<label>Pedido</label>
<textarea type="text" name="field7" placeholder="Insira aqui o Pedido"></textarea>
<label for="autores">Autor</label>
<?php
$result = $link->query("SELECT *FROM autores");
echo "<html>";
echo "<body>";
echo "<select name='field8' name='a_id'>";
echo "<option value=''>----Selecione um autor----</option>";
while ($row = $result->fetch_assoc()) {
unset($id, $name)
; $id = $row['a_id'];
$name = $row['a_nome'];
echo '<option value="'.$id.'">'.$name.'</option>';
} echo "</select>";
echo "</body>";
echo "</html>";?>
<input type="submit" value="Enviar" />
<div id='footer'>
</div>
</form>
Thanks.
Make sure your input type="file" is inside a form that has an enctype="multipart/form-data" or it will not send to file to your PHP script and $_FILES['userImage']['tmp_name'] will be empty
<form method="post" enctype="multipart/form-data" action="yourphpfile.php">
<label>Data de Criação</label>
<input type="date" name="field2" placeholder="Data de publicacao do Post">
<label>Data de Publicação</label>
<input type="date" name="field3" placeholder="Data de publicacao do Post">
<label>Titulo</label>
<input type="text" name="field4" placeholder="Insira aqui o Titulo">
<label>Keywords</label>
<input type="text" name="field5" placeholder="Insira aqui as Keywords">
<label>Hashtags</label>
<input type="text" name="field6" placeholder="Insira aqui as Hashtags">
<label>Imagem</label>
<p> </p>
<input type="file" name="userImage" class="inputFile"> <p> </p>
<label>Pedido</label>
<textarea type="text" name="field7" placeholder="Insira aqui o Pedido"></textarea>
<label for="autores">Autor</label>
</form>
As for your PHP code, I would advise putting all the block concerning the insert to database inside your if block. Plus you have some errors that are fixed here :
if(!empty($_FILES['userImage']['tmp_name'])
&& file_exists($_FILES['userImage']['tmp_name'])) {
$imgData= mysqli_real_escape_string($link, file_get_contents($_FILES['userImage']['tmp_name']));
$imageProperties = getimageSize($_FILES['userImage']['tmp_name']);
$portal = mysqli_real_escape_string($link, $_POST['field1']);
$date = mysqli_real_escape_string($link, $_POST['field2']);
$datacri = date('Y-m-d', strtotime(str_replace('-', '/', $date)));
$date = mysqli_real_escape_string($link, $_POST['field3']);
$datapub = date('Y-m-d', strtotime(str_replace('-', '/', $date)));
$titulo = mysqli_real_escape_string($link, $_POST['field4']);
$keyword = mysqli_real_escape_string($link, $_POST['field5']);
$hashtags = mysqli_real_escape_string($link, $_POST['field6']);
$pedido = mysqli_real_escape_string($link, $_POST['field7']);
$autor = mysqli_real_escape_string($link, $_POST['field8']);
if (!$portal) {
echo '<script type="text/javascript"> alert("Preencha todos os campos "); </script>';
mysqli_close($link);
}
$sql = "INSERT INTO pedidos (p_portal, p_datacri, p_datapub, p_titulo, p_keywords, p_hashtags, p_imageType, p_imageData, p_pedido, p_autor)
VALUES('$portal', '$datacri', '$datapub', '$titulo', '$keyword', '$hashtags', '{$imageProperties['mime']}', '{$imgData}', '$pedido', '$autor')";
if(mysqli_query($link, $sql)) {
echo '<script type="text/javascript"> alert("Portal Criado"); </script>';
} else{
echo "ERRO: Não foi possivel executar o comando $sql. " . mysqli_error($link);
}
} else {
echo "ERROR: couldn't get image Data";
}
?>
......
Have being trying this query for 3 days now. I have a list of rows here: http://prntscr.com/dick00. All what I want to is to edit and delete each row respectively. For some reason the id is not carrying forward and no record is updating.
When I click on edit in access.php I get edit_access.php?id= in address bar.
Here is my link in access.php
<td><a href="edit_access.php?id=<?php echo $row['id']; ?>"><i class="fa fa-edit"></i>edit</td>
edit_access.php
EDIT 1: php code
<?php
// start session
session_start();
// error_reporting(E_ALL); ini_set('display_errors', 1);
if(!isset($_SESSION['user_type'])){
header('Location: index.php');
}
// include connection
require_once('include/connection.php');
// set user session variables
$userId = $_SESSION['user_id'];
$error = [] ;
if(isset($_POST['update']))
{
$id = $_POST['id'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$therapist = $_POST['therapist'];
$access_type = $_POST['access_type'];
$code = $_POST['code'];
$created_at = $_POST['created_at'];
$postcode = $_POST['postcode'];
// validate form field
if (empty($firstname)){
$error[] = 'Field empty, please enter patient first name';
}
if (empty($lastname)){
$error[] = 'Field empty, please enter patient last name';
}
if (empty($therapist)){
$error[] = 'Field empty, please enter your name';
// $error = true;
}
if (empty($code)){
$error[] = 'Field empty, please enter patient access code';
// $error = true;
}
if (empty($access_type)){
$error[] = 'Field empty, please check access type';
// $error = true;
}
if (empty($postcode)){
$error[] = 'Field empty, please enter patient postcode';
// $error = true;
}
//if no errors have been created carry on
if(empty($error)){
$updated_at = date('Y-m-d');
// ************* UPDATE PROFILE INFORMATION ************************//
if(!($stmt = $con->prepare("UPDATE access SET firstname = ?, lastname = ?, therapist = ?, access_type = ?, postcode = ?, code = ?, updated_at = ?
WHERE id = ?"))) {
echo "Prepare failed: (" . $con->errno . ")" . $con->error;
}
if(!$stmt->bind_param('sssssssi', $firstname, $lastname, $therapist, $access_type, $postcode, $code, $updated_at, $userId)){
echo "Binding paramaters failed:(" . $stmt->errno . ")" . $stmt->error;
}
if(!$stmt->execute()){
echo "Execute failed: (" . $stmt->errno .")" . $stmt->error;
}
if($stmt) {
$_SESSION['main_notice'] = '<div class="alert alert-success">"Access Code Added successfully!"</div>';
header('Location: access.php');
exit;
}else{
$_SESSION['main_notice'] = '<div class="alert alert-danger">"Some error, try again"</div>';
header('Location: '.$_SERVER['PHP_SELF']);
}
}
}
// title page
$title = "Edit Access Record | Allocation | The Whittington Center";
// include header
require_once('include/header.php');
?>
<?php
if(isset($_GET['id'])){
$userId = $_GET['id'];
}
else{
$userId = $_POST['user_id'];
// mysqli_close($con);
$stmt = $con->prepare("SELECT * FROM access WHERE id = ?");
$stmt->bind_param('s', $userId);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows == 0) {
echo 'No Data Found for this user';
}else {
$stmt->bind_result($firstname, $lastname, $therapist, $access_type, $postcode, $code);
while ($row = $stmt->fetch());
$stmt->close();
}
?>
EDIT 2: HTML part
<h2 class="text-light text-greensea">Edit Access Record</h2>
<form name="access" class="form-validation mt-20" novalidate="" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" autocomplete='off'>
<div class="form-group">
<input type="text" name="firstname" class="form-control underline-input" value='<?php if(isset($error)){ echo $_POST[' firstname ']; } ?>' placeholder='firstname'></td>
</div>
<div class="form-group">
<input type="text" name="lastname" class="form-control underline-input" value='<?php if(isset($error)){ echo $_POST[' lastname ']; } ?>' placeholder='lastname'></td>
</div>
<div class="form-group">
<input type="text" name="therapist" class="form-control underline-input" value='<?php if(isset($error)){ echo $_POST[' therapist ']; } ?>' placeholder='therapist'></td>
</div>
<?php $access_type = $access_type; ?>
<div class="form-group ">
<label for="work status">Access Type</label>
<div name="access_type" value='<?php if(isset($error)){ echo $_POST[' access_type ']; } ?>'>
<label class="checkbox-inline checkbox-custom">
<input type="checkbox" name="access_type" <?php if (isset($work_status) && $access_type == "Keysafe") echo "checked"; ?> value="Keysafe"><i></i>Keysafe
</label>
<label class="checkbox-inline checkbox-custom">
<input type="checkbox" name="access_type" <?php if (isset($access_type) && $access_type == "keylog") echo "checked"; ?> value="keylog"><i></i>Keylog
</label>
</div>
</div>
<div class="form-group">
<input type="text" name="code" class="form-control underline-input" value='<?php if(isset($error)){ echo $_POST[' code ']; } ?>' placeholder='access code'></td>
</div>
<div class="form-group">
<input type="text" name="postcode" class="form-control underline-input" value='<?php if(isset($error)){ echo $_POST[' postcode ']; } ?>' placeholder='postcode'></td>
</div>
<div class="form-group text-left mt-20">
<button type="update" class="btn btn-primary pull-right" name="update" id='update'>Add Access</button>
<!-- <label class="checkbox checkbox-custom-alt checkbox-custom-sm inline-block">
<input type="checkbox"><i></i> Remember me
</label> -->
<a href="access.php">
<button type="button" class="btn btn-greensea b-0 br-2 mr-5">Back</button>
</a>
</div>
</form>
</div>
<!-- end of container -->
Thanks guy's for requesting for more code... i hope have given enough code sample.
you most put your id inside of a hidden input in your html form like this:
<input type="hidden" name="itemId" value="<?php echo '$_GET['id']'?>">
and then when you submit your form you have itemId in side $_POST['itemId'] variable.
EDIT:
I must describe scenario for you. maybe you got the point.
you have a list of access witch in every row has this tag:
access ....
in your access-form.php you have a form with this structure:
<form method="post" action="edit-access.php">
.....
<input type="hidden" name="id" value="<?php echo $_GET['id']?>">
.....
</form>
next in your edit-access.php you can access to this id by this syntax:
echo $_POST['id'];