php - Using Update CONCAT to ADD data to already Existing data in Database -
i trying make program update inside database have 1 worry. when issue update statement mysql server, want add data mysql database, overwrites first data there , saves new data database. want add data database plus existing 1 there.
my code looks
<?php session_start(); require_once('inc/config.php'); if(!isset($_session['username'])){ header('location: signon.php'); } ?> <?php require_once('inc/config.php'); $con = mysqli_connect($host, $user,$pass, $db) or die ('cannot connect: '.mysqli_error()); //get parameters $inst_name = mysqli_real_escape_string($con,$_post['inst_name']); $inst_name2 = mysqli_real_escape_string($con,$_post['inst_name2']); $grade = mysqli_real_escape_string($con,$_post['grade']); $study_course = mysqli_real_escape_string($con,$_post['study_course']); $qualification = mysqli_real_escape_string($con,$_post['qualification']); $other_qualification = mysqli_real_escape_string($con,$_post['other_qualification']); $completion_year = mysqli_real_escape_string($con,$_post['completion_year']); $data ="inst_name = '".$inst_name."',inst_name2 = '".$inst_name2."',grade = '".$grade."', study_course = '".$study_course."',qualification = '".$qualification."',other_qualification = '".$other_qualification."',completion_year = '".$completion_year."'"; //$sql = "update user_info set inst_name = '".$inst_name."',inst_name2 = '".$inst_name2."',grade = '".$grade."', study_course = '".$study_course."',qualification = '".$qualification."',other_qualification = '".$other_qualification."',completion_year = '".$completion_year."' username = '".$_session['username']."'"; $sql = "update user_info set $data=concat($data,inst_name = '".$inst_name."',inst_name2 = '".$inst_name2."',grade = '".$grade."', study_course = '".$study_course."',qualification = '".$qualification."',other_qualification = '".$other_qualification."',completion_year = '".$completion_year."') username = '".$_session['username']."'"; mysqli_query($con,$sql) or die ('failed query: '.mysqli_error($con)); mysqli_close($con); header("refresh:0; url=edwe.php"); ?>
what apparently not doing correctly.
to create new record, rather updating existing one, try sql insert
statement rather using update
. insert
creates records , update
edits existing ones.
Comments
Post a Comment