gpt4 book ai didi

php - 简单的 Mysqli 更新查询不起作用

转载 作者:行者123 更新时间:2023-11-30 23:45:49 25 4
gpt4 key购买 nike

<分区>

我只是 php 的初学者。我正在为这个简单的表单更新而绞尽脑汁。首先我用 prepare 语句来做这件事,最后我用简单的 mysqli 查询解决了这个问题。我不知道哪里出了问题。任何帮助都会很棒。

配置文件.php

   <?php
session_start();
include 'db.php';
if (!isset($_SESSION['id'])) {
header("location:login.php");
}

//echo $_SESSION['id'].$_SESSION['username'];

?>

<!DOCTYPE HTML>
<!--
Landed by HTML5 UP
html5up.net | @n33co
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Profile</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="stylesheet" href="homeass/assets/css/main.css" />

</head>
<body>
<div id="page-wrapper">

<!-- Header -->
<header id="header">
<h1 id="logo"><a href="profile.html">Profile</a></h1>
<nav id="nav">
<ul>
<li><a href="home.php">Home</a></li>
<li>
<a href="#">News Feed</a>
</li>

</ul>
</li>
<li><a href="profile.php">Profile</a></li>
<li><a href="logout.php" class="button special">Log Out</a></li>
</ul>
</nav>
</header>

<!-- Main -->
<div id="main" class="wrapper style1">
<div class="container">
<header class="major">
<h2>Profile</h2>
<p>Edit your stored information</p>
</header>




<!-- Form -->
<section>

<?php
$uid = $_SESSION['id'];
$getdata = "SELECT name,email,bloodgroup,mobile,relative_mob1,relative_mob2,message FROM users WHERE id = ?";
$stmtget = $con->prepare($getdata);
$stmtget->bind_param("i",$uid);
$stmtget->execute();
$stmtget->bind_result($gname,$gemail,$gbloodgroup,$gmobile,$gremob1,$gremob2,$gmes);

$stmtget->fetch();
$stmtget->store_result();
$stmtget->close();
//echo $gname;

?>
<?php
if (isset($_POST['btn-upload'])) {
// echo $_SESSION['username'];
$file = $_SESSION['username']."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$folder="uploads/";
if (move_uploaded_file($file_loc,$folder.$file)){
$sql = "UPDATE users SET pic = ? WHERE id = ?";
$stmti = $con->prepare($sql);
$stmti->bind_param("si",$file,$uid);
$stmti->execute();



}

}
$get = "SELECT pic FROM users WHERE id = ?";
$stmtg = $con->prepare($get);
$stmtg->bind_param("i",$uid);
$stmtg->execute();
$stmtg->bind_result($img);
$stmtg->fetch();
//echo '<img src="uploads/'.$img.'" width="50" height="50"/>';

?>
<section>
<h3>Image</h3>
<h4>Profile Pic</h4>
<div class="box alt">
<div class="4u 6u(xsmall)"><span class="image fit"><?php echo '<img src="uploads/'.$img.'" width="100" height="200"/>'; ?></span></div>

</div>
</div>
</section>
<div class="probut">
<form action="profile.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<button type="submit" name="btn-upload">upload</button>
</form>
</div>

<form method="post" action="profile.php">
<div class="row uniform 50%">

<!-- <div class="6u 12u$(xsmall)"><input type="file" name="file"/></div> -->

<h4>Name</h4>

<div class="6u 12u$(xsmall)">
<input type="text" name="name" value="<?php echo $gname ?>" placeholder="Name" />

</div>
<h4>Email</h4>
<div class="6u$ 12u$(xsmall)">
<input type="email" name="email" id="email" value="<?php echo $gemail ?>" placeholder="Email" />
</div>
<h4>Blood Group</h4>
<div class="6u$ 12u$(xsmall)">
<input type="text" name="bloodgroup" id="name" value="<?php echo $gbloodgroup ?>" placeholder="Blood Group" />
</div>
<h4>Your Mobile number</h4>
<div class="6u 12u$(xsmall)">
<input type="tel" name="mobile" id="name" value="<?php echo $gmobile ?>" placeholder="Mobile Number" />
</div>

<h4>Relatives Mob number 1</h4>
<div class="6u 12u$(xsmall)">
<input type="tel" name="remob1" id="name" value="<?php echo $gremob1 ?>" placeholder="Mobile Number" />
</div>

<h4>Relatives Mob number 2</h4>
<div class="6u 12u$(xsmall)">
<input type="tel" name="remob2" id="name" value="<?php echo $gremob2 ?>" placeholder="Mobile Number" />
</div>

<h4>Default Message</h4>
<div class="12u$">
<!-- <textarea name="message" id="name" value="value" placeholder="" rows="6"></textarea> -->
<input type="tel" name="message" id="name" value="<?php echo $gmes ?>" placeholder="Message" />



</div>
<div class="12u$">
<ul class="actions">
<li><input type="submit" name="submitttt" value="Save" class="special" /></li>

<li><input type="reset" value="Reset" /></li>
</ul>
</div>
</div>
</form>
<?php



if (isset($_POST['submitttt'])) {
$nameu = $_POST['name'];
$bloodgroupu = $_POST['bloodgroup'];
$mobileu = $_POST['mobile'];
$remob1u = $_POST['remob1'];
$remob2u = $_POST['remob2'];
$messageu = $_POST['message'];





$newsql = "UPDATE users SET name = '".$nameu."',bloodgroup = '".$bloodgroupu."',mobile = '".$mobileu."',relative_mob1 = '".$remob1u."',relative_mob2 = '".$remob2u."',message = '".$messageu."' WHERE id = ".$uid."" ;
if (mysqli_query($con,$newsql)) {
echo "Updated";
} else{
echo "Not updated";
echo "query failed: (" . $con->errno . ") " . $con->error;
}
echo '<h1>'.$uid.'</h1>';
echo $newsql;
/*$up = "UPDATE users SET name = ?,bloodgroup = ?,mobile = ?,relative_mob1 = ?,relative_mob2 = ?,message = ? WHERE id = ?";
$stmtuppp = $con->prepare($up);
$stmtuppp->bind_param("ssssssi",$nameu,$bloodgroupu,$mobileu,$remob1u,$remob2u,$messageu,$uid);
$stmtuppp->execute();
echo '<script>alert("updated")</script>';
echo "<meta http-equiv='refresh' content='0'>";*/

/*echo $nameu.'<br>';
echo $bloodgroupu;
echo $mobileu;
echo $remob1u;
echo $remob2u;
echo $messageu;*/

}


?>

</section>


</div>
</div>


<!-- Footer -->
<footer id="footer">
<ul class="icons">
<li><a href="#" class="icon alt fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon alt fa-facebook"><span class="label">Facebook</span></a></li>

<li><a href="#" class="icon alt fa-envelope"><span class="label">Email</span></a></li>
</ul>
<ul class="copyright">
<li>&copy; Yelp Mee. All rights reserved.</li><li>Design: <a>3rd Year CSE</a></li>
</ul>
</footer>
</div>

<!-- Scripts -->
<script src="homeass/assets/js/jquery.min.js"></script>
<script src="homeass/assets/js/jquery.scrolly.min.js"></script>
<script src="homeass/assets/js/jquery.dropotron.min.js"></script>
<script src="homeass/assets/js/jquery.scrollex.min.js"></script>
<script src="homeass/assets/js/skel.min.js"></script>
<script src="homeass/assets/js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="homeass/assets/js/main.js"></script>

</body>
</html>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com