html - Update MySQL entry through PHP form -


i writing script right update mysql data entry through php form. know there lots of tutorials , lot of answers here on stackoverflow. problem "updated data successfully" message data not updated inside database. maybe find error or can tell me did wrong , have change. here needed code:

form:

<?php  session_start();  if(empty($_session)) // if session not yet started    session_start();  if(!isset($_session['email'])) { //if not yet logged in    header("location: login.php");// send login page    exit; }  include 'header.php';  $get = "select * user email email = '".$_session['email']."'";  $result_get = mysqli_query($connect, $get);  $_session['data'] = mysqli_fetch_assoc($result_get);  ?>     <form method="post" action="update_profile.php" class="form-horizontal form-label-left">      <div class="form-group">     <label class="control-label col-md-3 col-sm-3 col-xs-12">vorname:</label>     <div class="col-md-9 col-sm-9 col-xs-12">     <input type="text" name="firstname_parent" class="form-control" value="<?php echo $_session['data']['firstname_parent']; ?>">     </div>     </div>     <button type="submit" name="update" value="update" class="btn btn-warning btn-lg btn-block">profil vervollstÄndigen</button>    </form> 

update_profile.php:

    <?php session_start(); // create connection credentials $db_host = 'localhost'; $db_name = 'dbname'; $db_user = 'dbuser'; $db_pass = 'dbpass';  // create mysqli object $connect = new mysqli ($db_host, $db_user, $db_pass, $db_name);  // error handler if ($connect->connect_error) {     printf ("connection failed: %s\n", $connect->connect_error);     exit(); }     // check if form submitted if (isset ($_post['update'])) {     $update_firstname_parent = mysqli_real_escape_string ($connect, $_post['firstname_parent'] ); }   $sql = mysqli_query ($connect, "update `user` set       firstname_parent='".$update_firstname_parent."'  email = '".$_session['email']."'";  if (mysqli_affected_rows($connect) == 0) //<-- {     die('could not update data: ' . mysql_error()); } else {     echo "updated data successfully\n"; } mysql_close($connect);   ?> 

edit: changed update_profile.php due comments here. not "updated data successfully" message, blank page , no data updated inside database.

thanks, chris

your update query wrong. change it

$sql = mysqli_query ($connect, "update `user` email = '".$_session['email']."' (`firstname_parent`)          values ('$update_firstname_parent')"); 

to

$sql = mysqli_query ($connect, "update `user` set       firstname_parent='".$update_firstname_parent."'  email = '".$_session['email']."'"); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -