Jump to content

inserting data into a users row in mysql


graham23s

Recommended Posts

Hi Guys,

 

i'm not sure if this is possible but this is what i'm attempting to do:

 

1)I Have made a registration page for a user to fill in and submit <-- ok

 

2)Once they do they can login to thier account <-- ok

 

3)the minute they are in thier account they can upload a photo/avatar and it submits the path/filename e.g to the database "grahamspicture.jpg" for example.

 

but what i'm not sure about is HOW to post that logged in users data back into the mysql database, once that particular user logs in how to make mysql know to post the path in grahams mysql row under photo (i hope that made sense)

 

heres a basic mock up of my_account.php

 

<?php 
     // Start the session...///////////////////////////////////////////////////////////// 
     session_start(); 
      
     // Register the session...////////////////////////////////////////////////////////// 
     if(!session_is_registered("username")) { 
     header("location:login.php"); 
     } 

     //Includes... ////////////////////////////////////////////////////////////////////// 
     include("includes/db_connection.php"); 
     include("includes/constants.php"); 
     include("includes/header.php"); 
     include("includes/loginnav.php"); 
?> 
<p align="left">Welcome, <b><font color="red"><? echo $_SESSION['username']; ?></font></b>! (<a href="logout.php">Logout</a>)</p> 
<form enctype="multipart/form-data" action="<?php echo $PHP_SELF; ?>" method="POST"> 
Photo: <input type="file" name="photo"><br> 
<input type="submit" value="Add"> 
</form> 
<?php 
  //This is the directory where images will be saved 
  $target = "members/"; 
  $target = $target . basename( $_FILES['photo']['name']); 

  //This gets all the other information from the form 
  $pic=($_FILES['photo']['name']); 

  // Connects to your Database   
  mysql_connect("localhost", "root", "milkybar") or die(mysql_error()); 
  mysql_select_db("cdm") or die(mysql_error()); 

  //Writes the information to the database   
  mysql_query("INSERT INTO `membership` VALUES ('$pic')"); 

  //Writes the photo to the server 
  if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))  {   

  //Tells you if its all ok 
  echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 

  } else {   //Gives and error if its not 
  echo "Sorry, there was a problem uploading your file.";   
}   
?> 
<?php 

     include("includes/footer.php") 
?> 

 

thanks

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/44257-inserting-data-into-a-users-row-in-mysql/
Share on other sites

If I was making this script, I'd doing something like:

 

Get Grahams ID into a session when he logs in. Then when he wants to upload a file, edit the mysql row that matches his ID.

 

Somebody here will be able to explain better, but thats a start.

 

From,

Jack

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.