Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have form for updating some data on my category table. After i post my new data via form, page refresh but it still show old data to me.
public function updateCategory($status, $main_category, $title, $bg_color, $meta_title, $meta_description, $meta_keywords, $id)
{
$sql = "UPDATE categories SET status = ?, main_category = ? , title = ?, bg_color = ?, meta_title = ?, meta_description = ?, meta_keywords = ? WHERE id = ?";
$stmt = $this->conn->prepare($sql);
try {
$stmt->execute([$status, $main_category, $title, $bg_color, $meta_title, $meta_description, $meta_keywords, $id]);
return true;
} catch (Exception $e) {
echo $e->getMessage();
return false;
}
}
Form post area
$category = new Categories();
$id = $_GET['id'];
$query = $category->getCategoryDetails($id);
$result = false;
if (isset($_POST['categorySave'])) {
$result = $category->updateCategory($_POST['status'],$_POST['main_category'],$_POST['title'],$_POST['bg_color'],$_POST['meta_title'],$_POST['meta_description'], $_POST['meta_keywords'], $query->id);
}
?>
<form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" enctype="multipart/form-data">
<?php if ($result) { ?>
<div class="alert alert-success" role="alert">
<?=UPDATESUCCESS?>
</div>
<?php } ?>
<label for="title">Başlık</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Başlık" value="<?=$query->title?>">
...
Its update data without problem. As an example if i change title 'Title New', it updates on my database. But after form submit, it stay as the same. 'Title Old'
move update code above the get code.
$result = false;
if (isset($_POST['categorySave'])) {
$result = $category->updateCategory($_POST['status'],$_POST['main_category'],$_POST['title'],$_POST['bg_color'],$_POST['meta_title'],$_POST['meta_description'], $_POST['meta_keywords'], $query->id);
}
$category = new Categories();
$id = $_GET['id'];
$query = $category->getCategoryDetails($id);
?>
<form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" enctype="multipart/form-data">
<?php if ($result) { ?>
<div class="alert alert-success" role="alert">
<?=UPDATESUCCESS?>
</div>
<?php } ?>
<label for="title">Başlık</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Başlık" value="<?=$query->title?>">
...
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed yesterday.
Improve this question
I am currently working on a mailing/messaging system. Now I want to send a message, but I want to add more recipients, but I can't do this. It would be kind if one of you would like to help me.
I would like each message(body, from and subject) to be in a separate table. And that the message id and to(and if there are multiple recipients that it creates multiple rows.) come in another table.
(My English is not so good, so sorry if there are spelling mistakes).
// JS for the to-tags.
function parse() {
var tag_input = document.getElementById("tags_input");
var tags = document.getElementById("tags");
//
var input_val = tag_input.value.trim();
var no_comma_val = input_val.replace(/,/g, "");
//
if (input_val.slice(-1) === "," && no_comma_val.length > 0) {
var new_tag = compile_tag(no_comma_val);
tags.appendChild(new_tag);
tag_input.value = "";
}
}
function compile_tag(tag_content) {
let a = -3;
var tag = document.createElement("p");
//
var text = document.createElement("span");
text.setAttribute("class", "badge badge-success");
text.setAttribute("id", tag_content);
text.innerHTML = tag_content;
//
var remove = document.createElement("i");
remove.setAttribute("class", "fa fa-remove");
remove.setAttribute("id", "remove");
remove.onclick = function() {this.parentNode.remove();};
//
tag.appendChild(remove);
tag.appendChild(text);
//
return tag;
}
// HTML AND PHP
<?php
session_start();
include_once("error.php");
include "db.php";
if (isset($_SESSION['login'])){
?>
<?php
$functions = array('newMessage');
if (isset($_GET['action'])){
if (in_array($_GET['action'], $functions)){
function newMessage(){
// when on the button press
if (isset($_POST['button_send'])) {
global $conn;
// take the user id
$from = $_SESSION['id'];
// create table one
$create = "INSERT INTO `messages` SET
`messageFrom` = '$from',
`messageSubject` = '".mysqli_real_escape_string($conn, $_POST['inp_subject'])."',
`messageBody` = '".mysqli_real_escape_string($conn, $_POST['textarea_body'])."'
";
// when table one is created make table to. **This is where things go wrong**
if (mysqli_query($conn, $create)){
if ($create = true){
$read = mysqli_query($conn, "SELECT * FROM `blog` WHERE `messageSubject` = '$_POST['inp_subject']' AND `messageFrom` = '$from' ");
$data = mysqli_fetch_assoc($read);
$id = $data['messageId'];
$create = "INSERT INTO `receivers` SET
`messageId` = '$id',
`messageSubject` = '".mysqli_real_escape_string($conn, $_POST['inp_subject'])."',
`messageBody` = '".mysqli_real_escape_string($conn, $_POST['textarea_body'])."'
"; if (mysqli_query($conn, $create)){
echo "fine";
}else{
echo 'Sorry, '.mysqli_error($conn);
}
}else{
echo 'Sorry, '.mysqli_error($conn);
}
}else{
echo 'Sorry, '.mysqli_error($conn);
}
}
?>
<form method="post">
<div class="from_group">
<input type="text" name="inp_to" id="inp_to" placeholder="Give the name(s)..." required>
<label>To:</label>
</div>
// The TO-input
<div class="container">
<div class="col-sm-6">
<input onkeyup="parse();" type="text" id="tags_input" placeholder="comma-separated tags" maxlength="100" class="form-control">
</div>
// the to tags
<div class="col-sm-6" id="tags" name="tags">
</div>
</div>
<script src="js/input_comma.js"></script>
<div class="from_group">
<input type="text" placeholder="Give the subject..." name="inp_subject" required>
<label>Subject: </label>
</div>
<div class="from_group">
<textarea name="textarea_body" rows="10" cols="30">
</textarea>
</div>
<button name="button_send"> Send </button>
</form>
</div>
<?php
}
echo $_GET['action'] ();
}else{
functionNotfound();
}
}
?>
<?php
}else{
notLoggedin();
}
?>
Already thanks for the help.
I would like each message(body, from and subject) to be in a separate table. And that the message id and to(and if there are multiple recipients that it creates multiple rows.) come in another table.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 days ago.
Improve this question
i am creating simple registation using php mysql.when i click the save button record need to add into the database table.but couldn't i didn't get any error but record not addedd.
php isset method is not working.
Form Design
<form action="add.php" method="post">
<label>Name</label></br>
<input type="text" name="name" id="name" class="form-control"></br>
<label>Address</label></br>
<input type="text" name="address" id="address" class="form-control"></br>
<label>Mobile</label></br>
<input type="text" name="mobile" id="mobile" class="form-control"></br>
<input type="submit" value="Save" class="btn btn-success"></br>
</form>
Php Code
<?php
$conn = mysqli_connect("localhost","root","");
$db = mysqli_select_db($conn,"bcrud");
$errors = "";
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$address = $_POST['address'];
$phone = $_POST['mobile'];
if(! $errors)
{
if(mysqli_errno($conn))
{
echo "Errr " , mysqli_errno($conn);
}
$sql = "insert into register(name,address,mobile)values('$name','$address','$phone')";
if(mysqli_query($conn,$sql))
{
echo "addedd";
}
else
{
echo "Errr " , mysqli_error($conn);
}
}
}
?>
So I have a file called Names.html.php that displays the data from the table in my sql table easily. It has an edit and delete button. The edit button allows users to edit the text in the "notes" column of the table which is longtext value (but did start as text).
The edit button sends the ID of the record that was chosen to the EditNote.php where it then opens that record using the function in databasefunctions.php and displays it using the EditNote.html.php.
My issue comes when I change the text in the Textarea box and click Save no errors appear but the text is not updated in the table. I know the ID value is being passed correctly but I am wondering whether there could be an issue with the Textarea posting not refreshing? Or having 2 post values from the same form causing some issues? Either way I am not sure how to fix either issue so some help would be greatly appreciated :)
Names.html.php
<blockquote>
<p>
<?=htmlspecialchars($Names['Name'], ENT_QUOTES, 'UTF-8')?>
<?=htmlspecialchars($Names['Notes'], ENT_QUOTES, 'UTF-8')?>
<?=htmlspecialchars($Names['Punch_IN_Time'], ENT_QUOTES, 'UTF-8')?>
<?=htmlspecialchars($Names['Status'], ENT_QUOTES, 'UTF-8')?>
Edit
<form action="DeleteEntry.php" method = "post">
<input type="hidden" name="ids" value="<?=$Names['Punch_ID']?>">
<input type="submit" value="Delete">
</form>
</p>
</blockquote>
<?php endforeach; ?>
EditNote.php
<?php
include '_DIR_' . '/../../Include/DatabaseConnection.php';
include '_DIR_' . '/../../Include/DatabaseFunctions.php';
try {
if (isset($_POST['NotePage'])) {
$note = (string)$_POST['NotePage'];
$IDs = (int)$_POST['Pid'];
UpdateNotes($pdo, $IDs, $note);
header('location: Punchinoutlist.php');
}else{
$Note = getPunchLine($pdo, $_GET['idss']);
$title = 'Edit Note';
ob_start();
include '_DIR_' . '/../../Templates/EditNote.html.php';
$output = ob_get_clean();
}
} catch (PDOException $e) {
$title = 'An error has occurred';
$output = 'Database error: ' . $e->getMessage() . ' in ' .$e->getFile() . ':' . $e->getLine();
}
include '_DIR_' . '/../../Templates/Layout.html.php';
?>
EditNote.html.php
<form action="" method="post">
<input type="hidden" name"Pid" value="<?=$Note['Punch_ID'];?>">
<label for = "NotePage">Type your new note here:
</label>
<textarea id = "NotePage" name="NotePage"
rows="3" cols ="40"><?=$Note['Notes']?>
</textarea>
<input type="submit" value="Save">
</form>
DatabaseFunctions.php
// Main query function that all fucntions refer //
function query($pdo, $sql, $parameters = []){
$query = $pdo->prepare($sql);
$query->execute($parameters);
return $query;
}
//update function for updating the note column of a certain record in the punch_in_out table //
function UpdateNotes($pdo, $id, $Notes){
$parameters = [':Notes' => $Notes, ':id' => $id];
$query = 'UPDATE `punch_in_out` SET `Notes` = :Notes WHERE `Punch_ID` = :id';
query($pdo, $query, $parameters);
}
?>
It doesn't look like you're getting your ID when you POST the text update because you're missing an = after the name in your HTML.
// you have
<input type="hidden" name"Pid" value="<?=$Note['Punch_ID'];?>">
// you should have
<input type="hidden" name="Pid" value="<?=$Note['Punch_ID'];?>">
This question already exists:
PHP's white screen of death [duplicate]
Closed 6 years ago.
I'm having a problem where my form is submitting the values but they aren't getting entered into the database?
I have tried echo'ing the $_POST to see what is getting posted and everything is posting as it should but its failing at the point of entering into the database.
Here is my code
if(isset ($_POST["update_detail"])) {
foreach($_POST["id"] AS $id) {
$name = mysqli_real_escape_string($_POST["name"][$id]);
$age = mysqli_real_escape_string($_POST["age"][$id]);
$update1 = "UPDATE `booked_peoples` SET `name` = '$name',`age` = '$age' WHERE `booked_peoples`.`id` = ".$id;
$update2 = mysqli_query($con,$update1);
if($update2){
echo '<script>window.location.href="add_passengers.php?book_id='.$book_id.'";</script>';
}
else {
echo 'OOPS';
} } }
and here is the php form code
if(isset($_GET['book_id']) and $_GET['action']=='edit')
{
$sq_edit_ps = "select * from booked_peoples where booking_id = ".$book_id;
$qr_edit_ps = mysqli_query($con,$sq_edit_ps);
while($rw_edit_ps = mysqli_fetch_array($qr_edit_ps))
{
$ps_id = $rw_edit_ps['id'];
echo '<form action="" method="POST" role="form">';
echo '<div class="row">
<div class="col-sm-9">
<label>Name</label>
<input class="form-control" type="text" name="name['.$ps_id.']" value="'.$rw_edit_ps['name'].'"/>
</div>
<div class="col-sm-3">
<label>Age</label>
<input class="form-control" type="text" name="age['.$ps_id.']" value="'.$rw_edit_ps['age'].'"/>
<input type="hidden" name="id[]" value="'.$ps_id.'"/>
</div>
</div>';
}
echo '
<button class="btn btn-info btn-flat" type="submit" name="update_detail" >Update</button>
</form>
</div>';
}
Im getting code blind.......:(
It was the mysql_real_escape_string that was stopping it form working.
It needed to be $name = mysqli_real_escape_string($con, $_POST["name"][$id]);
Thank you to the poster above for pointing it out :)
Wanted to post the solution in case anyone else comes across the same problem
I am having trouble updating the posts table of my database when a user updates a blog post they have made.
Flow of events - user makes a blog post, its saved to DB then they can go back and edit it. Edit brings up a pre-filled html form populated with data from the posts table. Then the user can change the title and content and when they press update the posted values from the form should replace the title and content of the original post in posts DB all other columns remain unchanged.
Currently my database just doesn't seem to update, not sure why. Using a combination of html/php/sql/pdos to execute sql statements - getting very complex for my novice experience and any help is appreciated.
Code (UPDATE statement is at bottom and most problematic):
// begin edit post
if(isset($_GET['editPost'])) {
$editPostId = $_GET['editPost'];
$sqlEditPostCheck = <<<EOD
SELECT author, id FROM posts WHERE author = '$currentUserId'
EOD;
$stmtEditPostCheck = $pdo->prepare($sqlEditPostCheck);
$stmtEditPostCheck->execute();
$ableToEdit = false;
while ($row = $stmtEditPostCheck->fetch(PDO::FETCH_ASSOC)) {
if($editPostId === $row['id'] && $currentUserId === $row['author']) { $ableToEdit = true; }
}
if($ableToEdit === true) {
$editPost_Title = "";
$editPost_Content = "";
$sqlEditPostPreFills = <<<EOD
SELECT id, post_title, content FROM posts WHERE id="$editPostId"
EOD;
$stmtEditPost = $pdo->prepare($sqlEditPostPreFills);
$stmtEditPost->execute();
while ($row = $stmtEditPost->fetch(PDO::FETCH_ASSOC)) {
$editPost_Title = $row['post_title'];
$editPost_Content = $row['content'];
$editPostId = $row['id'];
}
$content = <<<EOD
<form action="?profile&editPost="$editPostId" method="post">
<h1>Edit Post</h1>
<div class="form-group">
<input name="Epost_title" type="text" id="Epost_title" value="$editPost_Title" class="form-control">
</div>
<div class="form-group">
<textarea class="form-control" name="Epost_content" id="Epost_content" value="" rows="6">$editPost_Content</textarea>
</div>
<div style="text-align: right;">
<button type="submit" name="update" style="width: 30%;" class="btn btn-success btn-lg">Update</button>
</div>
</form>
<hr />
EOD;
} // end IF ableToEdit
$updatedContent = "";
if(isset($_POST['Epost_content'])) { $updatedContent = $_POST['Epost_content']; }
$updatedTitle = "";
if(isset($_POST['Epost_title'])) { $updatedTitle = $_POST['Epost_title']; }
if(isset($_POST['Epost_content']) && isset($_POST['Epost_title'])) {
$sqlUpdatePost = <<<EOD
UPDATE posts SET post_title='$updatedTitle', content='$updatedContent' WHERE posts.id='$editPostId' AND posts.author='$currentUserId';
EOD;
$stmtUpdate = $pdo->prepare($sqlUpdatePost);
$stmtUpdate->execute();
}
}
// end edit post
This line look bad for me
<form action="?profile&editPost="$editPostId" method="post">
try to change it to
<form action="?profile&editPost=\"$editPostId\" method=\"post\">"