A little php coding help needed

lorand

Regular Member
Joined
Apr 26, 2010
Messages
489
Reaction score
98
Can someone help my with a little php coding?
I just want to verify if an entry exist (username) in database before uploading a photo, and redirect to a page if exist and upload if not.
Thanks!
 
Fatal error: Can't use method return value in write context in /..//test/upload.php on line 18
 
this is the original code, i am interested to check if "$fname=$_POST['first_name'];" exist :
PHP:
<?php

require_once ('db.php');

if (isset($_POST['Submit'])) {
// echo "";
// }else{
// $file=$_FILES['image']['tmp_name'];
// $image = $_FILES["image"] ["name"];
// $image_name= addslashes($_FILES['image']['name']);
// $size = $_FILES["image"] ["size"];
// $error = $_FILES["image"] ["error"];
//
// if ($error > 0){
// die("Error uploading file! Code $error.");
// }else{
//     if($size > 10000000) //conditions for the file
//     {
//     die("Format is not allowed or file size is too big!");
//     }
//    
// else
//     {
move_uploaded_file($_FILES["image"]["tmp_name"],"uploads/" . $_FILES["image"]["name"]);          
$location=$_FILES["image"]["name"];
$fname=$_POST['first_name'];
$lname=$_POST['last_name'];

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO tbl_image (first_name, last_name, image_location)
VALUES ('$fname', '$lname', '$location')";

$conn->exec($sql);
echo "<script>alert('Successfully Added!!!'); window.location='index.php'</script>";
// }
}
// }
?>
 
this is the original code, i am interested to check if "$fname=$_POST['first_name'];" exist :

if the server has mysqli enabled use the following example (if it does not have mysqli enabled, change mysqli with mysql):
PHP:
$result = mysqli_query($conn, "SELECT * FROM tableName WHERE user='$fname'")
if (mysqli_num_rows ($result) > 0)
{
//do what you want here
}
 
Code:
if (isset($fname)) {
   $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   $sql = "INSERT INTO tbl_image (first_name, last_name, image_location)
   VALUES ('$fname', '$lname', '$location')";

   $conn->exec($sql);
   echo "<script>alert('Successfully Added!!!'); window.location='index.php'</script>";
} else {
   echo "Firstname not set"
}
 
It's not working :(
 
Back
Top