Why image is not saved to the database?Why don't self-closing script elements work?Why is using “for…in” with array iteration a bad idea?What is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?PHP $_POST get data arrayPreview an image before it is uploadedWhy does ++[[]][+[]]+[+[]] return the string “10”?PHP5 $_SESSION not working while register_globals is offWhat is TypeScript and why would I use it in place of JavaScript?Why shouldn't I use mysql_* functions in PHP?

UX writing: When to use "we"?

Why are prop blades not shaped like household fan blades?

Can I shorten this filter, that finds disk sizes over 100G?

What Marvel character has this 'W' symbol?

Were there any unmanned expeditions to the moon that returned to Earth prior to Apollo?

Prepare a user to perform an action before proceeding to the next step

Why is “deal 6 damage” a legit phrase?

Should students have access to past exams or an exam bank?

How to litter train a cat if both my husband and I work away from home all day?

What is the oxidation state of Mn in HMn(CO)5?

If the Moon were impacted by a suitably sized meteor, how long would it take to impact the Earth?

Why didn't General Martok receive discommendation in Star Trek: Deep Space Nine?

Avoiding Implicit Conversion in Constructor. Explicit keyword doesn't help here

A conjectural trigonometric identity

Coworker mumbles to herself when working, how to ask her to stop?

How to innovate in OR

What is the range of a Drunken Monk's Redirect attack?

Applications of pure mathematics in operations research

Why was the Lobbying Transparency and Accountability Act of 2006 deemed too weak?

How to prevent a single-element caster from being useless against immune foes?

Numerically Stable IIR filter

Easy way to get process information from a window

Should 2FA be enabled on service accounts?

GDPR Compliance - notification of data breach



Why image is not saved to the database?


Why don't self-closing script elements work?Why is using “for…in” with array iteration a bad idea?What is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?PHP $_POST get data arrayPreview an image before it is uploadedWhy does ++[[]][+[]]+[+[]] return the string “10”?PHP5 $_SESSION not working while register_globals is offWhat is TypeScript and why would I use it in place of JavaScript?Why shouldn't I use mysql_* functions in PHP?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I am trying to do a register page where a user must fill up its details and upload a picture of its choice. When i pressed the registered button, i have the following errors : "( ! ) Notice: Undefined index: image in /strath-cis/2018/SmartCommute/php/register.php " and "( ! ) Warning: file_get_contents(): Filename cannot be empty in /strath-cis/2018/SmartCommute/php/register.php "
On my database I do have a field called "image" of type BLOB.
I am sure that my details to connect with my database are correct.
Do anyone have a clue why this is happening?



Bellow is my code:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>

<link rel="stylesheet" type="text/css" href="../css/normalize.css"/>
<link rel="stylesheet" type="text/css" href="../css/register_css.css"/>
<title>Smart Commute</title>
</head>
<body>
<header id="headerBar">Smart Commute - Register</header>
<form class="needs-validation" novalidate action="" method="post">
<p><input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none;"></p>
<p><label for="file" style="cursor: pointer;">Upload Image</label></p>
<p><img id="output" width="200" /></p>

<script>
var loadFile = function(event)
var image = document.getElementById('output');
image.src = URL.createObjectURL(event.target.files[0]);
;
</script>

<p>Name: <input type="text" class="form-control" name="name" id="name" placeholder="John Doe" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['name']; ?>" required></p>
<p>Email: <input type="text" class="form-control" name="email" id="email" placeholder="fake@mail.com" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['email']; ?>" required></p>
<p>Password: <input type="password" class="form-control" name="password" id="password" placeholder="Enter password" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['password']; ?>" required></p>
<br><br>
<!-- <input type="submit" value="Submit" name="Register">-->
<button name="Register">Register</button>
</form>
</body>
</html>


<?php

session_start();

if (isset($_POST['Register']) && isset($_POST["image"]) )
?>









share|improve this question



















  • 4





    Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Mar 26 at 22:39











  • Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.

    – Dharman
    Mar 26 at 22:39

















-1















I am trying to do a register page where a user must fill up its details and upload a picture of its choice. When i pressed the registered button, i have the following errors : "( ! ) Notice: Undefined index: image in /strath-cis/2018/SmartCommute/php/register.php " and "( ! ) Warning: file_get_contents(): Filename cannot be empty in /strath-cis/2018/SmartCommute/php/register.php "
On my database I do have a field called "image" of type BLOB.
I am sure that my details to connect with my database are correct.
Do anyone have a clue why this is happening?



Bellow is my code:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>

<link rel="stylesheet" type="text/css" href="../css/normalize.css"/>
<link rel="stylesheet" type="text/css" href="../css/register_css.css"/>
<title>Smart Commute</title>
</head>
<body>
<header id="headerBar">Smart Commute - Register</header>
<form class="needs-validation" novalidate action="" method="post">
<p><input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none;"></p>
<p><label for="file" style="cursor: pointer;">Upload Image</label></p>
<p><img id="output" width="200" /></p>

<script>
var loadFile = function(event)
var image = document.getElementById('output');
image.src = URL.createObjectURL(event.target.files[0]);
;
</script>

<p>Name: <input type="text" class="form-control" name="name" id="name" placeholder="John Doe" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['name']; ?>" required></p>
<p>Email: <input type="text" class="form-control" name="email" id="email" placeholder="fake@mail.com" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['email']; ?>" required></p>
<p>Password: <input type="password" class="form-control" name="password" id="password" placeholder="Enter password" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['password']; ?>" required></p>
<br><br>
<!-- <input type="submit" value="Submit" name="Register">-->
<button name="Register">Register</button>
</form>
</body>
</html>


<?php

session_start();

if (isset($_POST['Register']) && isset($_POST["image"]) )
?>









share|improve this question



















  • 4





    Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Mar 26 at 22:39











  • Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.

    – Dharman
    Mar 26 at 22:39













-1












-1








-1








I am trying to do a register page where a user must fill up its details and upload a picture of its choice. When i pressed the registered button, i have the following errors : "( ! ) Notice: Undefined index: image in /strath-cis/2018/SmartCommute/php/register.php " and "( ! ) Warning: file_get_contents(): Filename cannot be empty in /strath-cis/2018/SmartCommute/php/register.php "
On my database I do have a field called "image" of type BLOB.
I am sure that my details to connect with my database are correct.
Do anyone have a clue why this is happening?



Bellow is my code:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>

<link rel="stylesheet" type="text/css" href="../css/normalize.css"/>
<link rel="stylesheet" type="text/css" href="../css/register_css.css"/>
<title>Smart Commute</title>
</head>
<body>
<header id="headerBar">Smart Commute - Register</header>
<form class="needs-validation" novalidate action="" method="post">
<p><input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none;"></p>
<p><label for="file" style="cursor: pointer;">Upload Image</label></p>
<p><img id="output" width="200" /></p>

<script>
var loadFile = function(event)
var image = document.getElementById('output');
image.src = URL.createObjectURL(event.target.files[0]);
;
</script>

<p>Name: <input type="text" class="form-control" name="name" id="name" placeholder="John Doe" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['name']; ?>" required></p>
<p>Email: <input type="text" class="form-control" name="email" id="email" placeholder="fake@mail.com" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['email']; ?>" required></p>
<p>Password: <input type="password" class="form-control" name="password" id="password" placeholder="Enter password" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['password']; ?>" required></p>
<br><br>
<!-- <input type="submit" value="Submit" name="Register">-->
<button name="Register">Register</button>
</form>
</body>
</html>


<?php

session_start();

if (isset($_POST['Register']) && isset($_POST["image"]) )
?>









share|improve this question














I am trying to do a register page where a user must fill up its details and upload a picture of its choice. When i pressed the registered button, i have the following errors : "( ! ) Notice: Undefined index: image in /strath-cis/2018/SmartCommute/php/register.php " and "( ! ) Warning: file_get_contents(): Filename cannot be empty in /strath-cis/2018/SmartCommute/php/register.php "
On my database I do have a field called "image" of type BLOB.
I am sure that my details to connect with my database are correct.
Do anyone have a clue why this is happening?



Bellow is my code:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>

<link rel="stylesheet" type="text/css" href="../css/normalize.css"/>
<link rel="stylesheet" type="text/css" href="../css/register_css.css"/>
<title>Smart Commute</title>
</head>
<body>
<header id="headerBar">Smart Commute - Register</header>
<form class="needs-validation" novalidate action="" method="post">
<p><input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none;"></p>
<p><label for="file" style="cursor: pointer;">Upload Image</label></p>
<p><img id="output" width="200" /></p>

<script>
var loadFile = function(event)
var image = document.getElementById('output');
image.src = URL.createObjectURL(event.target.files[0]);
;
</script>

<p>Name: <input type="text" class="form-control" name="name" id="name" placeholder="John Doe" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['name']; ?>" required></p>
<p>Email: <input type="text" class="form-control" name="email" id="email" placeholder="fake@mail.com" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['email']; ?>" required></p>
<p>Password: <input type="password" class="form-control" name="password" id="password" placeholder="Enter password" autocomplete="off" value="<?php if(isset($_POST['Register']))echo $_POST['password']; ?>" required></p>
<br><br>
<!-- <input type="submit" value="Submit" name="Register">-->
<button name="Register">Register</button>
</form>
</body>
</html>


<?php

session_start();

if (isset($_POST['Register']) && isset($_POST["image"]) )
?>






javascript php mysqli






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 22:34









PenelopePenelope

32 bronze badges




32 bronze badges










  • 4





    Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Mar 26 at 22:39











  • Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.

    – Dharman
    Mar 26 at 22:39












  • 4





    Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Mar 26 at 22:39











  • Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.

    – Dharman
    Mar 26 at 22:39







4




4





Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

– Dharman
Mar 26 at 22:39





Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

– Dharman
Mar 26 at 22:39













Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.

– Dharman
Mar 26 at 22:39





Warning: You are wide open to SQL Injections and should really use parameterized prepared statements instead of manually building your queries. They are provided by PDO or by MySQLi. Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, you are still in risk of corrupting your data.

– Dharman
Mar 26 at 22:39












1 Answer
1






active

oldest

votes


















0














When you are uploading a file, you need to include an enctype="multipart/form-data" attribute to the <form> tag. Have a quick read on the php's manual about file uploads.. You'll notice there is a Note section that explicitly mentions this.



So, for example:



<form enctype="multipart/form-data" class="needs-validation" novalidate action="" method="post">





share|improve this answer

























  • still doesnt work! basically now it doesnt even storing anything on the database

    – Penelope
    Mar 27 at 12:31












  • okay the problem was that in the database i need to change the type of image to longblob instead of blob. Thank you!!!

    – Penelope
    Mar 27 at 13:02











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367138%2fwhy-image-is-not-saved-to-the-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














When you are uploading a file, you need to include an enctype="multipart/form-data" attribute to the <form> tag. Have a quick read on the php's manual about file uploads.. You'll notice there is a Note section that explicitly mentions this.



So, for example:



<form enctype="multipart/form-data" class="needs-validation" novalidate action="" method="post">





share|improve this answer

























  • still doesnt work! basically now it doesnt even storing anything on the database

    – Penelope
    Mar 27 at 12:31












  • okay the problem was that in the database i need to change the type of image to longblob instead of blob. Thank you!!!

    – Penelope
    Mar 27 at 13:02
















0














When you are uploading a file, you need to include an enctype="multipart/form-data" attribute to the <form> tag. Have a quick read on the php's manual about file uploads.. You'll notice there is a Note section that explicitly mentions this.



So, for example:



<form enctype="multipart/form-data" class="needs-validation" novalidate action="" method="post">





share|improve this answer

























  • still doesnt work! basically now it doesnt even storing anything on the database

    – Penelope
    Mar 27 at 12:31












  • okay the problem was that in the database i need to change the type of image to longblob instead of blob. Thank you!!!

    – Penelope
    Mar 27 at 13:02














0












0








0







When you are uploading a file, you need to include an enctype="multipart/form-data" attribute to the <form> tag. Have a quick read on the php's manual about file uploads.. You'll notice there is a Note section that explicitly mentions this.



So, for example:



<form enctype="multipart/form-data" class="needs-validation" novalidate action="" method="post">





share|improve this answer













When you are uploading a file, you need to include an enctype="multipart/form-data" attribute to the <form> tag. Have a quick read on the php's manual about file uploads.. You'll notice there is a Note section that explicitly mentions this.



So, for example:



<form enctype="multipart/form-data" class="needs-validation" novalidate action="" method="post">






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 22:41









Jonathan KuhnJonathan Kuhn

14k2 gold badges25 silver badges40 bronze badges




14k2 gold badges25 silver badges40 bronze badges















  • still doesnt work! basically now it doesnt even storing anything on the database

    – Penelope
    Mar 27 at 12:31












  • okay the problem was that in the database i need to change the type of image to longblob instead of blob. Thank you!!!

    – Penelope
    Mar 27 at 13:02


















  • still doesnt work! basically now it doesnt even storing anything on the database

    – Penelope
    Mar 27 at 12:31












  • okay the problem was that in the database i need to change the type of image to longblob instead of blob. Thank you!!!

    – Penelope
    Mar 27 at 13:02

















still doesnt work! basically now it doesnt even storing anything on the database

– Penelope
Mar 27 at 12:31






still doesnt work! basically now it doesnt even storing anything on the database

– Penelope
Mar 27 at 12:31














okay the problem was that in the database i need to change the type of image to longblob instead of blob. Thank you!!!

– Penelope
Mar 27 at 13:02






okay the problem was that in the database i need to change the type of image to longblob instead of blob. Thank you!!!

– Penelope
Mar 27 at 13:02









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367138%2fwhy-image-is-not-saved-to-the-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현