Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,527 members, 7,801,468 topics. Date: Thursday, 18 April 2024 at 03:42 PM

Php Gurus Help Me Out: What Is Wrong With My Code?? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Php Gurus Help Me Out: What Is Wrong With My Code?? (1522 Views)

Please Help Look At My Code (what is wrong with my code ) / PHP Gurus - Please Help With A Form. Thank You / Please Php Gurus, Help Me (2) (3) (4)

(1) (Reply) (Go Down)

Php Gurus Help Me Out: What Is Wrong With My Code?? by emmanuelatas(m): 4:08am On Feb 28, 2016
<form action="test.php" method="POST" enctype="multipart/form-data">
<input name="image" type="file">
<input name="submit" type="submit">
</form>

<?php
$submit = $_POST['submit'];
$image = $_FILES["image"]["tmp_name"];
$imageData = addslashes(file_get_contents($image));

if (isset($submit)) {
$upload = mysql_query("INSERT INTO `images` VALUES ('$imageData')"wink;
}


if ($upload == true) {
echo "Image: $imageName uploaded";
};
?>
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by emmanuelatas(m): 4:09am On Feb 28, 2016
I NEED URGENT HELP THE FILE IS NOT UPLOADING
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by Nobody: 4:48am On Feb 28, 2016
Your images table has to be a 'blob' type, by the way it is saner and more resourceful to upload to a filesystem and just save the link in the database
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by FrankLampard: 6:39am On Feb 28, 2016
Check how to use move_uploaded_file() on PHP documentation
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by Nobody: 7:25am On Feb 28, 2016
@op, I can see that you know how to submit regular form fields into database, but image is more complicated than that.
Make sure that your image is not greater than your maximum upload or maximum post size, otherwise it will not even upload in the first place, talkless of inserting into database.
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by seunoni34(m): 10:13am On Feb 28, 2016
emmanuelatas:
<form action="test.php" method="POST" enctype="multipart/form-data">
<input name="image" type="file">
<input name="submit" type="submit">
</form>

<?php
$submit = $_POST['submit'];
$image = $_FILES["image"]["tmp_name"];
$imageData = addslashes(file_get_contents($image));

if (isset($submit)) {
$upload = mysql_query("INSERT INTO `images` VALUES ('$imageData')"wink;
}


if ($upload == true) {
echo "Image: $imageName uploaded";
};
?>
Why not encode with base64 then use mysql_real_escape_string to remove sql characters instead of using addslashes alone? And are you sure in the "images" table, the field you're storing the image has a blob data type?
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by seunoni34(m): 10:15am On Feb 28, 2016
It's also better to store image in a local file system and store the image filename in your database table.
You will most likely run into encoding and file corruption issues this way you're doing it.
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by emmanuelatas(m): 12:41pm On Feb 28, 2016
seunoni34:

Why not encode with base64 then use mysql_real_escape_string to remove sql characters addslashes alone? And are you sure in the "images" table, the field you're storing the image has a blob data type?
A

Thanks alot but I'm pretty new to this language, php. How do I go about encoding it with base64?
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by emmanuelatas(m): 2:12pm On Feb 28, 2016
Thanks to everybody for your immediate replies. I have been able to resolve the issue. thanks alot and God bless you all in your endeavors.
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by cbrass(m): 6:45pm On Feb 28, 2016
emmanuelatas:
Thanks to everybody for your immediate replies. I have been able to resolve the issue. thanks alot and God bless you all in your endeavors.

Stop storing images inside the db next time, just save the image part in the db and move the image to a separate folder on the server wink
Re: Php Gurus Help Me Out: What Is Wrong With My Code?? by emmanuelatas(m): 7:42pm On Feb 28, 2016
cbrass:


Stop storing images inside the db next time, just save the image part in the db and move the image to a separate folder on the server wink
emmanuelatas:
Thanks to everybody for your immediate replies. I have been able to resolve the issue. thanks alot and God bless you all in your endeavors.
cbrass:


Stop storing images inside the db next time, just save the image part in the db and move the image to a separate folder on the server wink

(1) (Reply)

Abuja Programmers / Who Else Is Experiencing This **whogohost** Is Down And My Domains Not Active / Biometric Data Capture Software

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.