How to get the id while uploading a file
this is my gallery.php;
<br>
<center><form action="galleryuploadxd.php" method="post" enctype="multipart/form-data">
Category
<select>
<option value="">Select...</option>
<option id_image="1" value="1">Admin Images</option>
<option id_image="2" value="2">User Images</option>
</select>
<br><br>
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></center>
So i want the option tag id_images
to be written in my database. I did something like this.
galleryuploadxd.php;
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>
<?php
include "db.php";
$id = $_GET['id_image'];
$target_file2 = "random-dir/";
$target_dir = "randomdir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>";
echo "<br>";
echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
$uploadOk = 1;
} else {
echo "<br>";
echo "<h1><center>File is not an image.</center></h1>";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "<br>";
echo "<h1><center>Sorry, file already exists.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<br>";
echo "<h1><center>Sorry, your file is too large.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>";
echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "<br>";
echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
echo " <meta http-equiv="refresh" content="5;url=gallery-edit.php" />";
echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
$sql = "INSERT INTO categories (id,image_link) VALUES (:id,:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$stmt->bindValue(':id', $id);
$result = $stmt->execute();
} else {
echo "<br>";
echo "<center>Sorry, there was an error uploading your file.</center>";
echo " <center><a href = gallery-edit.php>Go back </a></center>";
}
}
?>
So in the galleryuploadxd.php i say in the beginning $id = $_GET['id_image'];
and after in the end
$sql = "INSERT INTO categories (id,image_link) VALUES (:id,:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$stmt->bindValue(':id', $id);
$result = $stmt->execute();
i get the error that id cannot be null why doesn't it get the id can anyone help me?
the error;
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null in C:xampphtdocsxxxxxxx-admingalleryuploadxd.php:75 Stack trace: #0 C:xampphtdocsxxxxxxx-admingalleryuploadxd.php(75): PDOStatement->execute() #1 {main} thrown in C:xampphtdocsxxxxxxx-admingalleryuploadxd.php on line 75
It tells me I can't get the id
. how can I get the id on the option thats all? I need i'm trying to categorize the uploads thats why i'm doing something like this.
Thanks for the helps!
php forms pdo
|
show 9 more comments
this is my gallery.php;
<br>
<center><form action="galleryuploadxd.php" method="post" enctype="multipart/form-data">
Category
<select>
<option value="">Select...</option>
<option id_image="1" value="1">Admin Images</option>
<option id_image="2" value="2">User Images</option>
</select>
<br><br>
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></center>
So i want the option tag id_images
to be written in my database. I did something like this.
galleryuploadxd.php;
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>
<?php
include "db.php";
$id = $_GET['id_image'];
$target_file2 = "random-dir/";
$target_dir = "randomdir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>";
echo "<br>";
echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
$uploadOk = 1;
} else {
echo "<br>";
echo "<h1><center>File is not an image.</center></h1>";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "<br>";
echo "<h1><center>Sorry, file already exists.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<br>";
echo "<h1><center>Sorry, your file is too large.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>";
echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "<br>";
echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
echo " <meta http-equiv="refresh" content="5;url=gallery-edit.php" />";
echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
$sql = "INSERT INTO categories (id,image_link) VALUES (:id,:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$stmt->bindValue(':id', $id);
$result = $stmt->execute();
} else {
echo "<br>";
echo "<center>Sorry, there was an error uploading your file.</center>";
echo " <center><a href = gallery-edit.php>Go back </a></center>";
}
}
?>
So in the galleryuploadxd.php i say in the beginning $id = $_GET['id_image'];
and after in the end
$sql = "INSERT INTO categories (id,image_link) VALUES (:id,:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$stmt->bindValue(':id', $id);
$result = $stmt->execute();
i get the error that id cannot be null why doesn't it get the id can anyone help me?
the error;
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null in C:xampphtdocsxxxxxxx-admingalleryuploadxd.php:75 Stack trace: #0 C:xampphtdocsxxxxxxx-admingalleryuploadxd.php(75): PDOStatement->execute() #1 {main} thrown in C:xampphtdocsxxxxxxx-admingalleryuploadxd.php on line 75
It tells me I can't get the id
. how can I get the id on the option thats all? I need i'm trying to categorize the uploads thats why i'm doing something like this.
Thanks for the helps!
php forms pdo
The message seems very self explanatory to me. I would say that$id
has no value
– RiggsFolly
Nov 20 at 19:25
1
You need aname="something"
in the<select>
tag and not in the<option>
tag
– RiggsFolly
Nov 20 at 19:26
If you POST data you will find it in the$_POST
array and not the$_GET
array
– RiggsFolly
Nov 20 at 19:27
@RiggsFolly but i need every select tag with different id how can i do that?
– andrew
Nov 20 at 19:29
<select name="user_type">
then $_POST['user_type']` hold the ONE option selected.
– RiggsFolly
Nov 20 at 19:31
|
show 9 more comments
this is my gallery.php;
<br>
<center><form action="galleryuploadxd.php" method="post" enctype="multipart/form-data">
Category
<select>
<option value="">Select...</option>
<option id_image="1" value="1">Admin Images</option>
<option id_image="2" value="2">User Images</option>
</select>
<br><br>
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></center>
So i want the option tag id_images
to be written in my database. I did something like this.
galleryuploadxd.php;
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>
<?php
include "db.php";
$id = $_GET['id_image'];
$target_file2 = "random-dir/";
$target_dir = "randomdir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>";
echo "<br>";
echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
$uploadOk = 1;
} else {
echo "<br>";
echo "<h1><center>File is not an image.</center></h1>";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "<br>";
echo "<h1><center>Sorry, file already exists.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<br>";
echo "<h1><center>Sorry, your file is too large.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>";
echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "<br>";
echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
echo " <meta http-equiv="refresh" content="5;url=gallery-edit.php" />";
echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
$sql = "INSERT INTO categories (id,image_link) VALUES (:id,:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$stmt->bindValue(':id', $id);
$result = $stmt->execute();
} else {
echo "<br>";
echo "<center>Sorry, there was an error uploading your file.</center>";
echo " <center><a href = gallery-edit.php>Go back </a></center>";
}
}
?>
So in the galleryuploadxd.php i say in the beginning $id = $_GET['id_image'];
and after in the end
$sql = "INSERT INTO categories (id,image_link) VALUES (:id,:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$stmt->bindValue(':id', $id);
$result = $stmt->execute();
i get the error that id cannot be null why doesn't it get the id can anyone help me?
the error;
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null in C:xampphtdocsxxxxxxx-admingalleryuploadxd.php:75 Stack trace: #0 C:xampphtdocsxxxxxxx-admingalleryuploadxd.php(75): PDOStatement->execute() #1 {main} thrown in C:xampphtdocsxxxxxxx-admingalleryuploadxd.php on line 75
It tells me I can't get the id
. how can I get the id on the option thats all? I need i'm trying to categorize the uploads thats why i'm doing something like this.
Thanks for the helps!
php forms pdo
this is my gallery.php;
<br>
<center><form action="galleryuploadxd.php" method="post" enctype="multipart/form-data">
Category
<select>
<option value="">Select...</option>
<option id_image="1" value="1">Admin Images</option>
<option id_image="2" value="2">User Images</option>
</select>
<br><br>
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></center>
So i want the option tag id_images
to be written in my database. I did something like this.
galleryuploadxd.php;
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>
<?php
include "db.php";
$id = $_GET['id_image'];
$target_file2 = "random-dir/";
$target_dir = "randomdir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>";
echo "<br>";
echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
$uploadOk = 1;
} else {
echo "<br>";
echo "<h1><center>File is not an image.</center></h1>";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "<br>";
echo "<h1><center>Sorry, file already exists.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<br>";
echo "<h1><center>Sorry, your file is too large.</center></h1>";
echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>";
echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "<br>";
echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
echo " <meta http-equiv="refresh" content="5;url=gallery-edit.php" />";
echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
$sql = "INSERT INTO categories (id,image_link) VALUES (:id,:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$stmt->bindValue(':id', $id);
$result = $stmt->execute();
} else {
echo "<br>";
echo "<center>Sorry, there was an error uploading your file.</center>";
echo " <center><a href = gallery-edit.php>Go back </a></center>";
}
}
?>
So in the galleryuploadxd.php i say in the beginning $id = $_GET['id_image'];
and after in the end
$sql = "INSERT INTO categories (id,image_link) VALUES (:id,:image_link)";
$stmt = $db->prepare($sql);
$stmt->bindValue(':image_link', $target_file3);
$stmt->bindValue(':id', $id);
$result = $stmt->execute();
i get the error that id cannot be null why doesn't it get the id can anyone help me?
the error;
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null in C:xampphtdocsxxxxxxx-admingalleryuploadxd.php:75 Stack trace: #0 C:xampphtdocsxxxxxxx-admingalleryuploadxd.php(75): PDOStatement->execute() #1 {main} thrown in C:xampphtdocsxxxxxxx-admingalleryuploadxd.php on line 75
It tells me I can't get the id
. how can I get the id on the option thats all? I need i'm trying to categorize the uploads thats why i'm doing something like this.
Thanks for the helps!
php forms pdo
php forms pdo
edited Nov 20 at 19:34
Funk Forty Niner
80.5k1247100
80.5k1247100
asked Nov 20 at 19:22
andrew
32
32
The message seems very self explanatory to me. I would say that$id
has no value
– RiggsFolly
Nov 20 at 19:25
1
You need aname="something"
in the<select>
tag and not in the<option>
tag
– RiggsFolly
Nov 20 at 19:26
If you POST data you will find it in the$_POST
array and not the$_GET
array
– RiggsFolly
Nov 20 at 19:27
@RiggsFolly but i need every select tag with different id how can i do that?
– andrew
Nov 20 at 19:29
<select name="user_type">
then $_POST['user_type']` hold the ONE option selected.
– RiggsFolly
Nov 20 at 19:31
|
show 9 more comments
The message seems very self explanatory to me. I would say that$id
has no value
– RiggsFolly
Nov 20 at 19:25
1
You need aname="something"
in the<select>
tag and not in the<option>
tag
– RiggsFolly
Nov 20 at 19:26
If you POST data you will find it in the$_POST
array and not the$_GET
array
– RiggsFolly
Nov 20 at 19:27
@RiggsFolly but i need every select tag with different id how can i do that?
– andrew
Nov 20 at 19:29
<select name="user_type">
then $_POST['user_type']` hold the ONE option selected.
– RiggsFolly
Nov 20 at 19:31
The message seems very self explanatory to me. I would say that
$id
has no value– RiggsFolly
Nov 20 at 19:25
The message seems very self explanatory to me. I would say that
$id
has no value– RiggsFolly
Nov 20 at 19:25
1
1
You need a
name="something"
in the <select>
tag and not in the <option>
tag– RiggsFolly
Nov 20 at 19:26
You need a
name="something"
in the <select>
tag and not in the <option>
tag– RiggsFolly
Nov 20 at 19:26
If you POST data you will find it in the
$_POST
array and not the $_GET
array– RiggsFolly
Nov 20 at 19:27
If you POST data you will find it in the
$_POST
array and not the $_GET
array– RiggsFolly
Nov 20 at 19:27
@RiggsFolly but i need every select tag with different id how can i do that?
– andrew
Nov 20 at 19:29
@RiggsFolly but i need every select tag with different id how can i do that?
– andrew
Nov 20 at 19:29
<select name="user_type">
then $_POST['user_type']` hold the ONE option selected.– RiggsFolly
Nov 20 at 19:31
<select name="user_type">
then $_POST['user_type']` hold the ONE option selected.– RiggsFolly
Nov 20 at 19:31
|
show 9 more comments
2 Answers
2
active
oldest
votes
why you don't set the name of your select input
<select name="id_image">
<option value="">Select...</option>
<option value="1">Admin Images</option>
<option value="2">User Images</option>
</select>
use this as $id = $_POST['id_image'];
No error this time but i choose admin images and upload an image i don't see it in my table i have id and image_link i need the value 1 when i choose admin images to be id in my table that's all
– andrew
Nov 20 at 19:43
did u changed the value of $id
– Mahfuzar Rahman
Nov 20 at 19:45
i need the id to upon choosing from the options if they choose admin images the value will be 1 and user images needs to be 2
– andrew
Nov 20 at 19:49
change $id = $_GET['id_image']; to $id = $_POST['id_image'];
– Mahfuzar Rahman
Nov 20 at 19:51
is your categories table have only (id,image_link)
– Mahfuzar Rahman
Nov 20 at 19:52
|
show 6 more comments
In your form the method is POST and you try to retreive the records with
$id = $_GET['id_image'];
you should do:
$id = $_POST['id_image'];
i tried that too same fatal error.
– andrew
Nov 20 at 19:28
Would be useful to add what I said in my comment about where thename=""
attribute belongs to make this a complete answer
– RiggsFolly
Nov 20 at 19:28
But beware the code vampire, code this bad will normally require a complete rewrite and the OP wont credit you until you have fixed all their errors
– RiggsFolly
Nov 20 at 19:29
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400107%2fhow-to-get-the-id-while-uploading-a-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
why you don't set the name of your select input
<select name="id_image">
<option value="">Select...</option>
<option value="1">Admin Images</option>
<option value="2">User Images</option>
</select>
use this as $id = $_POST['id_image'];
No error this time but i choose admin images and upload an image i don't see it in my table i have id and image_link i need the value 1 when i choose admin images to be id in my table that's all
– andrew
Nov 20 at 19:43
did u changed the value of $id
– Mahfuzar Rahman
Nov 20 at 19:45
i need the id to upon choosing from the options if they choose admin images the value will be 1 and user images needs to be 2
– andrew
Nov 20 at 19:49
change $id = $_GET['id_image']; to $id = $_POST['id_image'];
– Mahfuzar Rahman
Nov 20 at 19:51
is your categories table have only (id,image_link)
– Mahfuzar Rahman
Nov 20 at 19:52
|
show 6 more comments
why you don't set the name of your select input
<select name="id_image">
<option value="">Select...</option>
<option value="1">Admin Images</option>
<option value="2">User Images</option>
</select>
use this as $id = $_POST['id_image'];
No error this time but i choose admin images and upload an image i don't see it in my table i have id and image_link i need the value 1 when i choose admin images to be id in my table that's all
– andrew
Nov 20 at 19:43
did u changed the value of $id
– Mahfuzar Rahman
Nov 20 at 19:45
i need the id to upon choosing from the options if they choose admin images the value will be 1 and user images needs to be 2
– andrew
Nov 20 at 19:49
change $id = $_GET['id_image']; to $id = $_POST['id_image'];
– Mahfuzar Rahman
Nov 20 at 19:51
is your categories table have only (id,image_link)
– Mahfuzar Rahman
Nov 20 at 19:52
|
show 6 more comments
why you don't set the name of your select input
<select name="id_image">
<option value="">Select...</option>
<option value="1">Admin Images</option>
<option value="2">User Images</option>
</select>
use this as $id = $_POST['id_image'];
why you don't set the name of your select input
<select name="id_image">
<option value="">Select...</option>
<option value="1">Admin Images</option>
<option value="2">User Images</option>
</select>
use this as $id = $_POST['id_image'];
answered Nov 20 at 19:36
Mahfuzar Rahman
14919
14919
No error this time but i choose admin images and upload an image i don't see it in my table i have id and image_link i need the value 1 when i choose admin images to be id in my table that's all
– andrew
Nov 20 at 19:43
did u changed the value of $id
– Mahfuzar Rahman
Nov 20 at 19:45
i need the id to upon choosing from the options if they choose admin images the value will be 1 and user images needs to be 2
– andrew
Nov 20 at 19:49
change $id = $_GET['id_image']; to $id = $_POST['id_image'];
– Mahfuzar Rahman
Nov 20 at 19:51
is your categories table have only (id,image_link)
– Mahfuzar Rahman
Nov 20 at 19:52
|
show 6 more comments
No error this time but i choose admin images and upload an image i don't see it in my table i have id and image_link i need the value 1 when i choose admin images to be id in my table that's all
– andrew
Nov 20 at 19:43
did u changed the value of $id
– Mahfuzar Rahman
Nov 20 at 19:45
i need the id to upon choosing from the options if they choose admin images the value will be 1 and user images needs to be 2
– andrew
Nov 20 at 19:49
change $id = $_GET['id_image']; to $id = $_POST['id_image'];
– Mahfuzar Rahman
Nov 20 at 19:51
is your categories table have only (id,image_link)
– Mahfuzar Rahman
Nov 20 at 19:52
No error this time but i choose admin images and upload an image i don't see it in my table i have id and image_link i need the value 1 when i choose admin images to be id in my table that's all
– andrew
Nov 20 at 19:43
No error this time but i choose admin images and upload an image i don't see it in my table i have id and image_link i need the value 1 when i choose admin images to be id in my table that's all
– andrew
Nov 20 at 19:43
did u changed the value of $id
– Mahfuzar Rahman
Nov 20 at 19:45
did u changed the value of $id
– Mahfuzar Rahman
Nov 20 at 19:45
i need the id to upon choosing from the options if they choose admin images the value will be 1 and user images needs to be 2
– andrew
Nov 20 at 19:49
i need the id to upon choosing from the options if they choose admin images the value will be 1 and user images needs to be 2
– andrew
Nov 20 at 19:49
change $id = $_GET['id_image']; to $id = $_POST['id_image'];
– Mahfuzar Rahman
Nov 20 at 19:51
change $id = $_GET['id_image']; to $id = $_POST['id_image'];
– Mahfuzar Rahman
Nov 20 at 19:51
is your categories table have only (id,image_link)
– Mahfuzar Rahman
Nov 20 at 19:52
is your categories table have only (id,image_link)
– Mahfuzar Rahman
Nov 20 at 19:52
|
show 6 more comments
In your form the method is POST and you try to retreive the records with
$id = $_GET['id_image'];
you should do:
$id = $_POST['id_image'];
i tried that too same fatal error.
– andrew
Nov 20 at 19:28
Would be useful to add what I said in my comment about where thename=""
attribute belongs to make this a complete answer
– RiggsFolly
Nov 20 at 19:28
But beware the code vampire, code this bad will normally require a complete rewrite and the OP wont credit you until you have fixed all their errors
– RiggsFolly
Nov 20 at 19:29
add a comment |
In your form the method is POST and you try to retreive the records with
$id = $_GET['id_image'];
you should do:
$id = $_POST['id_image'];
i tried that too same fatal error.
– andrew
Nov 20 at 19:28
Would be useful to add what I said in my comment about where thename=""
attribute belongs to make this a complete answer
– RiggsFolly
Nov 20 at 19:28
But beware the code vampire, code this bad will normally require a complete rewrite and the OP wont credit you until you have fixed all their errors
– RiggsFolly
Nov 20 at 19:29
add a comment |
In your form the method is POST and you try to retreive the records with
$id = $_GET['id_image'];
you should do:
$id = $_POST['id_image'];
In your form the method is POST and you try to retreive the records with
$id = $_GET['id_image'];
you should do:
$id = $_POST['id_image'];
answered Nov 20 at 19:26
m.Sarto
395
395
i tried that too same fatal error.
– andrew
Nov 20 at 19:28
Would be useful to add what I said in my comment about where thename=""
attribute belongs to make this a complete answer
– RiggsFolly
Nov 20 at 19:28
But beware the code vampire, code this bad will normally require a complete rewrite and the OP wont credit you until you have fixed all their errors
– RiggsFolly
Nov 20 at 19:29
add a comment |
i tried that too same fatal error.
– andrew
Nov 20 at 19:28
Would be useful to add what I said in my comment about where thename=""
attribute belongs to make this a complete answer
– RiggsFolly
Nov 20 at 19:28
But beware the code vampire, code this bad will normally require a complete rewrite and the OP wont credit you until you have fixed all their errors
– RiggsFolly
Nov 20 at 19:29
i tried that too same fatal error.
– andrew
Nov 20 at 19:28
i tried that too same fatal error.
– andrew
Nov 20 at 19:28
Would be useful to add what I said in my comment about where the
name=""
attribute belongs to make this a complete answer– RiggsFolly
Nov 20 at 19:28
Would be useful to add what I said in my comment about where the
name=""
attribute belongs to make this a complete answer– RiggsFolly
Nov 20 at 19:28
But beware the code vampire, code this bad will normally require a complete rewrite and the OP wont credit you until you have fixed all their errors
– RiggsFolly
Nov 20 at 19:29
But beware the code vampire, code this bad will normally require a complete rewrite and the OP wont credit you until you have fixed all their errors
– RiggsFolly
Nov 20 at 19:29
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400107%2fhow-to-get-the-id-while-uploading-a-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
The message seems very self explanatory to me. I would say that
$id
has no value– RiggsFolly
Nov 20 at 19:25
1
You need a
name="something"
in the<select>
tag and not in the<option>
tag– RiggsFolly
Nov 20 at 19:26
If you POST data you will find it in the
$_POST
array and not the$_GET
array– RiggsFolly
Nov 20 at 19:27
@RiggsFolly but i need every select tag with different id how can i do that?
– andrew
Nov 20 at 19:29
<select name="user_type">
then $_POST['user_type']` hold the ONE option selected.– RiggsFolly
Nov 20 at 19:31