Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am not that good in php however the below code was working before I changed thr host name. the echo is not showing when I load the url , neither the insert is being executed.

$con = mysqli_connect($host,$uname,$pwd,$db);
echo 'hi'
$description= $_GET['description'];
$categorie= $_GET['categorie'];
$image=$_POST['image'];
$imagename = uniqid("uploaded_images").".png";
$imageurl="http://justedhak.com/".$imagename;

     $binary=base64_decode($image);
    header('Content-Type: bitmap; charset=utf-8');
    $file = fopen($imagename, 'wb');
    fwrite($file, $binary);
    fclose($file);

$sql="INSERT INTO OBJECTS( NAME, TYOE, URL, CATEGORY, USERS_ID, HIDE_YN ) 
VALUES ('$imagename',  'IMAGE',  '$imageurl',  'CATEG' , 1,  'N')";

 if(mysqli_query($con,$sql)){
echo $sql
}
else{
echo 'failure';
  }
mysqli_close($con);

Errors

Warning: mysqli_connect(): (28000/1045): Access denied for user 'je_user'@'ip-160-153-162-16.ip.secureserver.net' (using password: YES) in /home/justdb/public_html/upload_image.php on line 7

Notice: Undefined index: description in /home/justdb/public_html/upload_image.php on line 9

Notice: Undefined index: categorie in /home/justdb/public_html/upload_image.php on line 10

Notice: Undefined index: image in /home/justdb/public_html/upload_image.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /home/justdb/public_html/upload_image.php:6) in /home/justdb/public_html/upload_image.php on line 16

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/justdb/public_html/upload_image.php on line 24

Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /home/justdb/public_html/upload_image.php on line 30

share|improve this question
    
Which hostname? the one which links the image? or the one which is $host for mysql? if it's $host Please can you post the code which defines $host and also provide information about your server setup. i.e. is the web server and mysql server hosted on a local machine? in the cloud on a server somewhere? Have you tried changing back what you changed and then investigating the problem from there? – Adam Copley 2 hours ago
    
You are vulnerable to sql injection attacks. and if the echo doesn't show up, then mysqli probably isn't enabled/installed, and you've got error_reporting/display_errors turned off. – Marc B 2 hours ago
1  
This sounds like a great opportunity for you to familiarize yourself with some debugging practices. Turn on error reporting, check the SQL query for errors, check the PHP and server logs, even put in some echo statements throughout the code to see what's happening when it executes. – David 2 hours ago
    
@AdamCopley godaddy hosting , and what do you mean by $host i didnt define anything for that , the server setup i guess was automaticaly set up with go daddy – Moudiz 2 hours ago
1  
@NanaPartykar good catch and sql error checking will catch that if that is the case; unknown column blah blah blah ;-) – Fred -ii- 1 hour ago

You are missing a ; from the end of echo hi and echo $sql

share|improve this answer
    
well still nothing showep up – Moudiz 1 hour ago
    
Also the line "echo $sql" is missing the ";" You should enable error reporting in PHP when developing. – Joose 1 hour ago

Foreword:

It has already been established that you have added the missing semi-colons for both echo 'hi' and echo $sql, so there's no need for my repeating it.

Seeing all of those undefined index notices, that could mean that your form's method may not be using the same as your GET/POST arrays, something you did not include in your original question; these are likely possible reasons.

Or, that you are using both your HTML and PHP inside the same file and that is the case, your HTML form may be on top of your PHP, in turn throwing the headers sent notice and that you need to use either isset() or empty() against your GET/POST arrays.

There should not be any output before header and that could also be caused by a cookie, a space before the <?php opening tag, or the file's encoding; which could also be a byte order mark.

Here are a few links that are directly related to the issues you are having.

Plus, it was already noted that your code is open to an SQL injection.

References:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.