php - I require assistance with a SQL syntax error -
i writing code register , login system, , when testing receiving errors, there one:
"you have error in sql syntax; check manual corresponds mariadb server version right syntax use near 'where username = ''' @ line 1"
could please tell me means , solve it. here code in update-profile.php
<?php session_start(); ini_set("display_errors",1); $temp=$_session['username']; if(isset($_post)){ require 'database1.php'; $destination = 'background-images'; if(!isset($_files['backgroundimagefile']) || !is_uploaded_file($_files['backgroundimagefile']['tmp_name'])){ $backgroundnewimagename= 'background.jpg'; move_uploaded_file($_files['backgroundimagefile']['tmp_name'], "$destination/$backgroundnewimagename"); } else{ $randomnum = rand(0, 9999999999); $imagename = str_replace(' ','-',strtolower($_files['backgroundimagefile']['name'])); $imagetype = $_files['backgroundimagefile']['type']; $imageext = substr($imagename, strrpos($imagename, '.')); $imageext = str_replace('.','',$imageext); $imagename = preg_replace("/\.[^.\s]{3,4}$/", "", $imagename); $backgroundnewimagename = $imagename.'-'.$randomnum.'.'.$imageext; move_uploaded_file($_files['backgroundimagefile']['tmp_name'], "$destination/$backgroundnewimagename"); } $sql1="update users set backgroundpicture='$backgroundnewimagename' username = '$temp'"; $sql2="insert users (backgroundpicture) values ('$backgroundnewimagename') username = '$temp'"; $result = mysqli_query($database,"select * users username = '$temp'"); if( mysqli_num_rows($result) > 0) { if(!empty($_files['backgroundimagefile']['name'])){ mysqli_query($database,$sql1)or die(mysqli_error($database)); header("edit-profile.php?username=$temp"); } } else { mysqli_query($database,$sql2)or die(mysqli_error($database)); header("edit-profile.php?username=$temp"); } $destination = 'avatars'; if(!isset($_files['imagefile']) || !is_uploaded_file($_files['imagefile']['tmp_name'])){ $newimagename= 'default.png'; move_uploaded_file($_files['imagefile']['tmp_name'], "$destination/$newimagename"); } else{ $randomnum = rand(0, 9999999999); $imagename = str_replace(' ','-',strtolower($_files['imagefile']['name'])); $imagetype = $_files['imagefile']['type']; $imageext = substr($imagename, strrpos($imagename, '.')); $imageext = str_replace('.','',$imageext); $imagename = preg_replace("/\.[^.\s]{3,4}$/", "", $imagename); $newimagename = $imagename.'-'.$randomnum.'.'.$imageext; move_uploaded_file($_files['imagefile']['tmp_name'], "$destination/$newimagename"); } $sql5="update users set avatar='$newimagename' username = '$temp'"; $sql6="insert users (avatar) values ('$newimagename') username = '$temp'"; $result = mysqli_query($database,"select * users username = '$temp'"); if( mysqli_num_rows($result) > 0) { if(!empty($_files['imagefile']['name'])){ mysqli_query($database,$sql5)or die(mysqli_error($database)); header("location:edit-profile.php?username=$temp"); } } else { mysqli_query($database,$sql6)or die(mysqli_error($database)); header("location:edit-profile.php?username=$temp"); } $user_firstname=$_request['firstname']; $user_lastname=$_request['lastname']; $user_email=$_request['email']; $user_password=$_request['password']; $user_shortbio=$_request['bio']; $user_dob=$_request['dob']; $user_gender=$_request['gender']; $sql3="update user sets firstname='$firstname',lastname='$lastname',email='$email',password='$password',bio='$bio',dob='$dob',gender='$gender', username = '$temp'"; mysqli_query($database,$sql3)or die(mysqli_error($database)); header("edit-profile.php?username=$temp&request=profile-update&status=success"); }
in insert syntax, have used where
$sql6="insert users (avatar) values ('$newimagename') username = '$temp'";
should
$sql6="insert users (avatar) values ('$newimagename')"; $sql2="insert users (backgroundpicture) values ('$backgroundnewimagename')";
also
$sql3="update user sets firstname='$firstname',lastname='$lastname',email='$email',password='$password',bio='$bio',dob='$dob',gender='$gender', username = '$temp'";
should below, remove ,
before where
$sql3="update user set firstname='$firstname',lastname='$lastname',email='$email',password='$password',bio='$bio',dob='$dob',gender='$gender' username = '$temp'";
and suggest read basic document
Comments
Post a Comment