mysql - Php UPDATE row function -


i trying allow users upload profile image site. file upload part works fine (although there nothing deterring them form uploading non-image file). can't update "profile" row in mysql database. think has $_session['user_id'] i'm not sure. ideas why wont update row?

<?php if(isset($_post['submit'])){ $temp = explode(".",$_files["file"]["name"]); $newfilename = ('profileimage') . rand(1,99999) . '.' .end($temp); move_uploaded_file($_files['file']['tmp_name'],"images/profile/" . $newfilename);             $con = mysqli_connect("localhost","root","","testsite");             $q = mysqli_query($con,"update user set profile = '".$newfilename."' username = '".$_session['user_id']."'"); }  ?>          <form action="" method="post" enctype="multipart/form-data" name="">                     <input type="file" name="file" required>                     <input type="submit" name="submit" value="update image">              </form> 

just in case need see this, "functions.php" page $_session['user_id'] defined:

<?php  @session_start();  function loggedin(){ if(isset($_session['user_id']) && !empty($_session['user_id'])){ return true; } else { return false; } }  function getuser($id, $field){ $query = mysql_query("select $field user userid='$id'"); $run = mysql_fetch_array($query); return $run[$field];  }  ?> 

i assuming error here:

$q = mysqli_query($con,"update user set profile = '".$newfilename."' username = '".$_session['user_id']."'"); 

and should this:

$q = mysqli_query($con,"update user set profile = '".$newfilename."' userid = '".$_session['user_id']."'"); 

looks switched out userid username.

when comes page supposedly setting $_session['user_id'], code displayed here no such thing.

it defines 2 functions, not call them, , not assign value user_id.

so first, update query shown above, var_dump of $_session, see if have stored in it. if not need go few steps, , make sure set session variables.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -