Insert | updating photo problem

hello
152 Replies
NIMA
NIMA3w ago
$file_name = $_FILES['image']['name'];
$tempname = $_FILES['image']['tmp_name'];
$folder = 'images/'.$file_name;
$query = mysqli_query($conn , "UPDATE user SET user_image='$file_name' WHERE user_id='$name_update_id'");
$file_name = $_FILES['image']['name'];
$tempname = $_FILES['image']['tmp_name'];
$folder = 'images/'.$file_name;
$query = mysqli_query($conn , "UPDATE user SET user_image='$file_name' WHERE user_id='$name_update_id'");
when i want to update my profile user photo { there is no insert photo beffor } nothing will happen and only name will chenge to data base and nothing gonna add to my photos folder and when i try this
$file_name = $_FILES['image']['name'];
$tempname = $_FILES['image']['tmp_name'];
$folder = 'images/'.$file_name;

$query = mysqli_query($con , "INSERT INTO user (user_image) values ('$file_name')");
$file_name = $_FILES['image']['name'];
$tempname = $_FILES['image']['tmp_name'];
$folder = 'images/'.$file_name;

$query = mysqli_query($con , "INSERT INTO user (user_image) values ('$file_name')");
it will make new tabel with empty stuff and only with photo how can i add photo when im updating it and now inserting
ἔρως
ἔρως3w ago
use upload_file_move() after validating it is an actual image
NIMA
NIMA3w ago
it will work in updating ? and add to photos folder?
ἔρως
ἔρως3w ago
no, it will move the file to the folder
NIMA
NIMA3w ago
let me test and see what will happen
ἔρως
ἔρως3w ago
you have to validate the file first try to read it try to resize it try to save that copy to the folder you want, with a random name
NIMA
NIMA3w ago
i cut all part cuse in first it should work and then i add them agine
ἔρως
ἔρως3w ago
alright and you should use prepared statements
NIMA
NIMA3w ago
nice it work if(move_uploaded_file($tempname,$folder)){ echo 'file uplode fix'; } else{ echo 'file not fix !!!!!!!'; } tnx for help i was stuck in this part for long time
ἔρως
ἔρως3w ago
you're welcome but this is extremely unsafe and you can kill the server easily
NIMA
NIMA3w ago
i dont add it to website yet and now its working i need to add the limits and prepared statements ...
ἔρως
ἔρως3w ago
which server do you use? apache? nginx? something else? dont know?
NIMA
NIMA3w ago
linux :linux:
ἔρως
ἔρως3w ago
no, the server software
NIMA
NIMA3w ago
hmm BISTON i think
ἔρως
ἔρως3w ago
biston?
NIMA
NIMA3w ago
i think yes i buy it from parshost
NIMA
NIMA3w ago
پارس هاست
پارس هاست - خرید هاست, ثبت دامنه, سرور مجازی و اختصاصی ایران
ثبت دامنه و خرید هاست لینوکس و ویندوز با قیمت ارزان وسرعت بالا. خرید هاست نامحدود, وردپرس, دامنه و سرور مجازی, اختصاصی - خرید هاست با پشتیبانی 24/7.
ἔρως
ἔρως3w ago
i tried to read that, but chrome translated it to a burchered portuguese-like mess :/ do you have an .htaccess file in your host?
NIMA
NIMA3w ago
i dont think so i have cpannel
ἔρως
ἔρως3w ago
i know, you showed it the other day
NIMA
NIMA3w ago
No description
ἔρως
ἔρως3w ago
and you have any files?
NIMA
NIMA3w ago
yes
NIMA
NIMA3w ago
No description
ἔρως
ἔρως3w ago
no htaccess file if you create one and type gibberish, does the site stop working?
NIMA
NIMA3w ago
ha ? i cant undestand i make a file name htaccess ?
ἔρως
ἔρως3w ago
.htaccess and type something inaide inside any nonsense
NIMA
NIMA3w ago
i cant create it
ἔρως
ἔρως3w ago
thats fine
NIMA
NIMA3w ago
what is thath ? what it will do ?
ἔρως
ἔρως3w ago
.htaccess files are used by apache, to configure it the idea is to set the folder with images to only allow images to be served, and anything that might end up there will be sent as text
NIMA
NIMA3w ago
ohh its only in apache ?
ἔρως
ἔρως3w ago
yes
NIMA
NIMA3w ago
its nice option
ἔρως
ἔρως3w ago
yeah, if it worked this is an important security option, as it prevents that an image.jpeg.php is executed
NIMA
NIMA3w ago
is it good now for saifty ?
if($row["user_ip"] == $user_ip){

$res = mysqli_query($conn, "SELECT user_image FROM user where user_id = '$name_update_id'");
while($row = mysqli_fetch_assoc($res) ){


$xxxx = $row["user_image"];
if( $xxxx == 'profile_pic_defult.png'){
unlink('images/');
$conn->query($sql) ;
}else{
unlink('images/'.$xxxx);
$conn->query($sql) ;
}



}

$file_name = $_FILES['image']['name'];
$tempname = $_FILES['image']['tmp_name'];
$folder = 'images/'.$file_name;
$imageFileType = strtolower(pathinfo($file_name,PATHINFO_EXTENSION));
if ($_FILES["image"]["size"] > 500000) {
header("Location: index.php");
exit();
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
header("Location: index.php");
exit();
}

$stmt = $conn->prepare("UPDATE user SET user_image=(?) WHERE user_id='$name_update_id'");
$stmt->bind_param("s", $file_name);
$$file_name = $file_name;
$stmt->execute();
if(move_uploaded_file($tempname,$folder)){
echo 'file uplode fix';
} else{
echo 'file not fix !!!!!!!';
}
}
if($row["user_ip"] == $user_ip){

$res = mysqli_query($conn, "SELECT user_image FROM user where user_id = '$name_update_id'");
while($row = mysqli_fetch_assoc($res) ){


$xxxx = $row["user_image"];
if( $xxxx == 'profile_pic_defult.png'){
unlink('images/');
$conn->query($sql) ;
}else{
unlink('images/'.$xxxx);
$conn->query($sql) ;
}



}

$file_name = $_FILES['image']['name'];
$tempname = $_FILES['image']['tmp_name'];
$folder = 'images/'.$file_name;
$imageFileType = strtolower(pathinfo($file_name,PATHINFO_EXTENSION));
if ($_FILES["image"]["size"] > 500000) {
header("Location: index.php");
exit();
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
header("Location: index.php");
exit();
}

$stmt = $conn->prepare("UPDATE user SET user_image=(?) WHERE user_id='$name_update_id'");
$stmt->bind_param("s", $file_name);
$$file_name = $file_name;
$stmt->execute();
if(move_uploaded_file($tempname,$folder)){
echo 'file uplode fix';
} else{
echo 'file not fix !!!!!!!';
}
}
ἔρως
ἔρως3w ago
not really, no
NIMA
NIMA3w ago
😳
ἔρως
ἔρως3w ago
you have a mix of snake oil with an almost ok attempt at validating a file if($row["user_ip"] == $user_ip){ <-- this is horrible
NIMA
NIMA3w ago
No
ἔρως
ἔρως3w ago
yes, very
NIMA
NIMA3w ago
i mean
ἔρως
ἔρως3w ago
in terms of safety, it does absolutely nothing at all, and just causes problems for the users
NIMA
NIMA3w ago
i do this so who care a profile can only edit it with the same ip
ἔρως
ἔρως3w ago
here's how to change my ip in 3 seconds: - have a phone - turn off wifi
NIMA
NIMA3w ago
ye ye i know thath but cuse i dont add login and register i just add this for test so other people dont remove other people post i dont make it for total security
ἔρως
ἔρως3w ago
why aren't you developing locally?
NIMA
NIMA3w ago
what u mean
ἔρως
ἔρως3w ago
develop locally, not in an hosted server online
NIMA
NIMA3w ago
for now yes i dont put in the host cuse im updating it after it finished i put it in my host
ἔρως
ἔρως3w ago
ok, but that's still just a case of cheeto security
NIMA
NIMA3w ago
what that mean the security is bad for the ip thing ?
ἔρως
ἔρως3w ago
No description
NIMA
NIMA3w ago
🤣
ἔρως
ἔρως3w ago
it looks safe, but it does nothing
NIMA
NIMA3w ago
u mean the ip part or the uplode part
ἔρως
ἔρως3w ago
yes that does absolutely nothing
NIMA
NIMA3w ago
ye but other people cant remove each other post but if their ip chenge they cant get acces to their page too
ἔρως
ἔρως3w ago
people can't remove their own post in this case, image which makes it pretty horrible in terms of usability
NIMA
NIMA3w ago
No description
NIMA
NIMA3w ago
the blue background mean this is match to ur ip and u can edit or dealet it
ἔρως
ἔρως3w ago
also, what if you need to delete or edit someone else's image?
NIMA
NIMA3w ago
u cant only me i can from data base or the user with hes ip [ the ip when he create hes user ]
ἔρως
ἔρως3w ago
for example, someone puts rounchy images as the profile image as a platform provider, by the european law, you're required to moderate it
NIMA
NIMA3w ago
i will dealet it very fast from data base i realy cant do anything about it until i chenge it to login and register system or i make report button for it if 5 people with diffrent ip report the photo it get dealet and only photo get dealet not the user this is only thing i can do for now with ip system
ἔρως
ἔρως3w ago
that's why it's absolutely horrible you, as the owner, should have the possibility to do anything you need to do
NIMA
NIMA3w ago
ye even if the user ip get cheange he cant acces to hes page anymore ...
ἔρως
ἔρως3w ago
an user, a lowly one, should be allowed to only edit the profile of that user regardlress of the ip
NIMA
NIMA3w ago
do u think is good to put the report button ?
ἔρως
ἔρως3w ago
why? you made it so you can't edit anything
NIMA
NIMA3w ago
u can edit ur own profile but people cant like other soical apps like instagram and ... the owner of page can but other people cant
ἔρως
ἔρως3w ago
that is how it should work forget ip verification and bs you can use it to check the country and for logs, that's very important
NIMA
NIMA3w ago
ye thats why no one use this ip system
ἔρως
ἔρως3w ago
yes, because it sucks it's not safe, it's not user friendly, it's just ... a cheeto
NIMA
NIMA3w ago
ye i bulid this project for test cuse i never do any other porject with php
ἔρως
ἔρως3w ago
i noticed you arent using any session variables
NIMA
NIMA3w ago
i only use POST
ἔρως
ἔρως3w ago
how do you know the user is allowed to upload? how do you know the user exists at all? how do you know the user is logged in?
NIMA
NIMA3w ago
i dont put any of this
ἔρως
ἔρως3w ago
which is what you should have done
NIMA
NIMA3w ago
if someone dealet the page it gonna gone for ever and dealet from tabel and all stuff
ἔρως
ἔρως3w ago
that's not what im saying
NIMA
NIMA3w ago
i put a serch button u can serch the id of the page if its not looding anything its mean its dealted or wrong
ἔρως
ἔρως3w ago
im saying you're not validating if the user is logged in and which user uploaded the image
NIMA
NIMA3w ago
and there is no login if u come to my page with the ip u create the user u can see ur profile with blue back ground
ἔρως
ἔρως3w ago
you're not listening to me point me to the line where you update the image of the user that is logged in
NIMA
NIMA3w ago
No description
NIMA
NIMA3w ago
is ip match and click in edit button he come in this page
ἔρως
ἔρως3w ago
so, the script is just for you, and not for the user itself?
NIMA
NIMA3w ago
it is if user ip = the old ip at the first create of account = u can enter this page for update ONLY ur account
ἔρως
ἔρως3w ago
then this is missing code
NIMA
NIMA3w ago
i will finish the part and put in the website
ἔρως
ἔρως3w ago
no, at the top there's code missing
NIMA
NIMA3w ago
YES its long i think i cant send it hear let me try
ἔρως
ἔρως3w ago
you can split it into multiple messages
NIMA
NIMA3w ago
ok
ἔρως
ἔρως3w ago
or send the file
ἔρως
ἔρως3w ago
that's a mess and a security nightmare because you're receiving the user id from POST
NIMA
NIMA3w ago
🤣 i put very IF i need use sesions right ?
ἔρως
ἔρως3w ago
yes, you do
NIMA
NIMA3w ago
i totaly forget about it can people chenge the value and put sql injecshen code at my code rn ? cuse it getting for input
ἔρως
ἔρως3w ago
probably
NIMA
NIMA3w ago
i think thats the only part i need to put sessions cuse other part user need to send
ἔρως
ἔρως3w ago
the first query has security issues you don't use prepared statements
NIMA
NIMA3w ago
ohhh even SELECT need prepared statements ?
ἔρως
ἔρως3w ago
EVERYTHING
NIMA
NIMA3w ago
i only use them for INSERT i will cheange all of them to prepared statements
ἔρως
ἔρως3w ago
you know what i can do? '"; drop table user; this this is enough to ruin your website
NIMA
NIMA3w ago
😭 in all inputs?
ἔρως
ἔρως3w ago
in the id
NIMA
NIMA3w ago
or only the qurry with no prepared statements
ἔρως
ἔρως3w ago
any and every single query you didn't use protected statements
NIMA
NIMA3w ago
ohhh the id will be connect to data base
ἔρως
ἔρως3w ago
anything you put into the query, is a possible hole
NIMA
NIMA3w ago
ye i just understand it if i put session and protected statements it will be good for now ?
ἔρως
ἔρως3w ago
no, not even close
NIMA
NIMA3w ago
what other thing u can recommend to fix
ἔρως
ἔρως3w ago
fix this, then we talk
NIMA
NIMA3w ago
Aright tnx for helping
ἔρως
ἔρως3w ago
you're welcome by the way, why did you do ... this:
$name_update_id = $_POST['name_update_id'];

$username_update = $_POST['username_update'];
$userage_update = $_POST['userage_update'];
$userphone_update = $_POST['userphone_update'];

$usergmail_update = $_POST['usergmail_update'];
$usercountry_update = $_POST['usercountry_update'];

$usercountry_job = $_POST['usercountry_job'];

$telgram_user = $_POST['telgram_user'];
$instagram_user = $_POST['instagram_user'];
$twiter_user = $_POST['twiter_user'];
$website_user = $_POST['website_user'];
$name_update_id = $_POST['name_update_id'];

$username_update = $_POST['username_update'];
$userage_update = $_POST['userage_update'];
$userphone_update = $_POST['userphone_update'];

$usergmail_update = $_POST['usergmail_update'];
$usercountry_update = $_POST['usercountry_update'];

$usercountry_job = $_POST['usercountry_job'];

$telgram_user = $_POST['telgram_user'];
$instagram_user = $_POST['instagram_user'];
$twiter_user = $_POST['twiter_user'];
$website_user = $_POST['website_user'];
NIMA
NIMA3w ago
hmm so i can use them
ἔρως
ἔρως3w ago
🤦 you can use them already you also misspelled telegram and twitter
NIMA
NIMA3w ago
its will be eazyer
ἔρως
ἔρως3w ago
also, why do you have separated fields for each social network?
NIMA
NIMA3w ago
No description
NIMA
NIMA3w ago
there is a eye button it will direct people at this page and they can see more stuff about the user
ἔρως
ἔρως3w ago
that's not what i mean
NIMA
NIMA3w ago
oh
ἔρως
ἔρως3w ago
why isn't it in a different table? some people don't have any some people have 1 or 2 some people have others
NIMA
NIMA3w ago
they can put it empty
ἔρως
ἔρως3w ago
that's not the point
NIMA
NIMA3w ago
i put all the stuff only in 1 tabel
ἔρως
ἔρως3w ago
the point is ... in 5 years, you will have 5000 columns for every single social network and that doesn't work normalize the table, and create 2 tables: social_networks and user_social_networks
NIMA
NIMA3w ago
im thnking about remove all and add more photo of each soical networks so people can select each one they want
ἔρως
ἔρως3w ago
inside social_network, you put all the information about the networks: logo, name, label, something else inside user_social_networks, you put the user id, the social network id and the url and that is how you do a proper normalization of the social networks for users
NIMA
NIMA3w ago
ye i should do thath cuse there is soo many stuff in only 1 tabel rn
NIMA
NIMA3w ago
No description
ἔρως
ἔρως3w ago
you're putting too much because you're not following the normalization rules for the database
NIMA
NIMA3w ago
at first it was only 4 row and then i add more and i dont add more tabel only put all in 1
ἔρως
ἔρως3w ago
do you need to store the ip there? the ip should be in a log, not there
NIMA
NIMA3w ago
in log ?
ἔρως
ἔρως3w ago
image, job, country, phone, age and name can be in a separate table
NIMA
NIMA3w ago
ye i will fix all after i fix the prepared statements
ἔρως
ἔρως3w ago
alright
NIMA
NIMA3w ago
i store the first ip [ the ip user create the first page ] and ip wont updated
ἔρως
ἔρως3w ago
that is even worse, and doesn't belong there
NIMA
NIMA3w ago
if i put the $user_id in session i wont need prepared statements anymore ? cuse it wont get anything from input anymore
ἔρως
ἔρως3w ago
yes, you do let me explain this straight prepared statements are NOT optional
NIMA
NIMA3w ago
:agree:
ἔρως
ἔρως3w ago
if you don't send any inputs, or manually enter the input, then you may skip prepared statements by the way, you really should use pdo
Want results from more Discord servers?
Add your server