I cant make my upload image work

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Martind
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Jan 02, 2017 7:21 am

Mon Jan 02, 2017 7:24 am

Hey, im doing a php scripted website via sql and i need to make a upload button and i have done so but it tells me unexpected if on line 4
Here is the code and i would appreciate any help!

<?php
$msg =""
//if upload button is pressed//
if (isset($_POST['up'])) {
$target = "images/". basename($_FILES['image']['name']);

//connect to database
$db=mysqli_connect("localhost","root","","photos");

//get all the sumbitted data from the form
$image = $_FILES['image']['name'];
$text = $_POST['text'];

$sql = "INSERT INTO images (image,text) VALUES ('$image',''$text')";
mysqli_query($db,$sql)//lagre vores data i databasen

//bevæg dataene
if(move_uploaded_file)($FILES['tmp_name']['name'],$target)){
$msg ="Uploaded!";
}else{
$msg ="Der var et problem"
}
}

AdoptiveSolution
New php-forum User
New php-forum User
Posts: 163
Joined: Wed Jun 15, 2016 8:35 am

Mon Jan 02, 2017 7:53 am

Please use the code button if you paste code. It's easier to read.

Next, I notice a missing ; at the end of some lines.

AdoptiveSolution
New php-forum User
New php-forum User
Posts: 163
Joined: Wed Jun 15, 2016 8:35 am

Mon Jan 02, 2017 7:55 am

Also, the quotes are wrong :

Code: Select all

$sql = "INSERT INTO images (image,text) VALUES ('$image',''$text')";

Martind
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Jan 02, 2017 7:21 am

Mon Jan 02, 2017 9:53 am

you cant possible imagine how emberrased i am right now sorry for wasting your time

php4blog
New php-forum User
New php-forum User
Posts: 6
Joined: Thu Feb 16, 2017 12:57 am

Thu Mar 02, 2017 1:03 am

You are going wrong Bro. Image Upload is Easy You can Try AJAX Image Upload Without Refresh or You can also Try simple Image Upload. It will help You Lot. Because I am every time using that You can also try it out.
Thanks

Post Reply