pass data from html to database [closed]
I created a form in which user must fill out details about a doggy they found or they lost. When I am pressing the submit button it looks to work. I have my form empty again, but my data is not in the database. When I am trying to refresh the page it shows me a warning that my data may be lost. It seems that the server is trying to pass my data in the database but for some reason it can't. Can anyone help me? My code is below:
<?php
if (isset($_POST['submit'])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
$image = $_FILES['image']['tmp_name'];
$imgContent = addslashes(file_get_contents($image));
$host = "xx";
$user = "xx";
$pass= "xx";
$dbname = "xx";
$conn = new mysqli($host,$user,$pass, $dbname );
// image file directory
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); //SQL I
if ($conn->connect_error) {
die("Connection failed : ".$conn->connect_error); //fixme
} else {
echo "Connected successfully";
}
}
if (isset($_POST['status1'])) {
$sql = "INSERT INTO foundDogs( dname ,breed,colour,description,datefound,location,picture,posterID) VALUES
('" . $_POST["dname"] . "','" . $_POST["breed"] . "','" . $_POST["colour"] . "','" . $_POST["description"] . "','" . $_POST["date"] . "','" . $_POST["location"] . "','$image',NULL)";
} else {
$sql = "INSERT INTO lostDogs( dname ,breed,colour,description,datefound,location,picture,posterID) VALUES
('" . $_POST["dname"] . "','" . $_POST["breed"] . "','" . $_POST["colour"] . "','" . $_POST["description"] . "','" . $_POST["date"] . "','" . $_POST["location"] . "','$image',NULL)";
}
// echo $sql;
// if ($conn->query($sql) == TRUE) {
// echo "<p> Insert successful </p>";
// } else {
// die("error on insert" . $conn->error);
// }
$conn->close();
}
?>
<div id="container">
<div class="content">
<h2>Fill out the form below</h2>
<div class="subTable">
<form action="post_dog.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td><smth>Collar Name:</smth></td>
</td>
<tr>
<td><input type="text" name="dname" placeholder="Only enter if you know"><br></td>
</tr>
<tr>
<td><smth>Colour Description:</smth></td>
<tr>
<td><input type="text" name="colour" placeholder="Enter some brief description of the dog"><br></td>
</tr>
<tr>
<td><smth>Breed:</smth></td>
</tr>
<tr>
<td><input type="text" name="breed" placeholder="Only enter if you know"><br></td>
</tr>
<tr>
<td><smth>Date lost/found:</smth></td>
</tr>
<tr>
<td><input id="datefield" type="date" name="date"><br></td>
</tr>
<tr>
<td><smth>Location lost/found:</smth></td>
</tr>
<tr>
<td><input type="text" name="location" placeholder="Please enter the location"><br></td>
</tr>
<tr>
<td><smth>Doggo Description:</smth></td>
</tr>
<tr>
<td><textarea type="text" name="description" rows="5" cols="30" placeholder="Describe the doggy as best as you can!!"></textarea></td>
</tr>
<tr>
<td><smth>Missing:</smth><input type="checkbox" name="status" value="missing"><smth> Found:</smth><input type="checkbox" name="status1" value="found"></td>
</tr>
<tr>
<td><smth>Image:</smth> <input type="file" name="image"></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
** My connection details im sure that are correct.
php html mysql database
closed as off-topic by Nick, Vickel, Mustafa Ekici, UVM, Brian Rogers Dec 15 at 7:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Nick, Vickel, Mustafa Ekici, UVM, Brian Rogers
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I created a form in which user must fill out details about a doggy they found or they lost. When I am pressing the submit button it looks to work. I have my form empty again, but my data is not in the database. When I am trying to refresh the page it shows me a warning that my data may be lost. It seems that the server is trying to pass my data in the database but for some reason it can't. Can anyone help me? My code is below:
<?php
if (isset($_POST['submit'])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
$image = $_FILES['image']['tmp_name'];
$imgContent = addslashes(file_get_contents($image));
$host = "xx";
$user = "xx";
$pass= "xx";
$dbname = "xx";
$conn = new mysqli($host,$user,$pass, $dbname );
// image file directory
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); //SQL I
if ($conn->connect_error) {
die("Connection failed : ".$conn->connect_error); //fixme
} else {
echo "Connected successfully";
}
}
if (isset($_POST['status1'])) {
$sql = "INSERT INTO foundDogs( dname ,breed,colour,description,datefound,location,picture,posterID) VALUES
('" . $_POST["dname"] . "','" . $_POST["breed"] . "','" . $_POST["colour"] . "','" . $_POST["description"] . "','" . $_POST["date"] . "','" . $_POST["location"] . "','$image',NULL)";
} else {
$sql = "INSERT INTO lostDogs( dname ,breed,colour,description,datefound,location,picture,posterID) VALUES
('" . $_POST["dname"] . "','" . $_POST["breed"] . "','" . $_POST["colour"] . "','" . $_POST["description"] . "','" . $_POST["date"] . "','" . $_POST["location"] . "','$image',NULL)";
}
// echo $sql;
// if ($conn->query($sql) == TRUE) {
// echo "<p> Insert successful </p>";
// } else {
// die("error on insert" . $conn->error);
// }
$conn->close();
}
?>
<div id="container">
<div class="content">
<h2>Fill out the form below</h2>
<div class="subTable">
<form action="post_dog.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td><smth>Collar Name:</smth></td>
</td>
<tr>
<td><input type="text" name="dname" placeholder="Only enter if you know"><br></td>
</tr>
<tr>
<td><smth>Colour Description:</smth></td>
<tr>
<td><input type="text" name="colour" placeholder="Enter some brief description of the dog"><br></td>
</tr>
<tr>
<td><smth>Breed:</smth></td>
</tr>
<tr>
<td><input type="text" name="breed" placeholder="Only enter if you know"><br></td>
</tr>
<tr>
<td><smth>Date lost/found:</smth></td>
</tr>
<tr>
<td><input id="datefield" type="date" name="date"><br></td>
</tr>
<tr>
<td><smth>Location lost/found:</smth></td>
</tr>
<tr>
<td><input type="text" name="location" placeholder="Please enter the location"><br></td>
</tr>
<tr>
<td><smth>Doggo Description:</smth></td>
</tr>
<tr>
<td><textarea type="text" name="description" rows="5" cols="30" placeholder="Describe the doggy as best as you can!!"></textarea></td>
</tr>
<tr>
<td><smth>Missing:</smth><input type="checkbox" name="status" value="missing"><smth> Found:</smth><input type="checkbox" name="status1" value="found"></td>
</tr>
<tr>
<td><smth>Image:</smth> <input type="file" name="image"></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
** My connection details im sure that are correct.
php html mysql database
closed as off-topic by Nick, Vickel, Mustafa Ekici, UVM, Brian Rogers Dec 15 at 7:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Nick, Vickel, Mustafa Ekici, UVM, Brian Rogers
If this question can be reworded to fit the rules in the help center, please edit the question.
2
is the query($sql) bit actually commented out in the code you're running? That's the bit that will update the database
– Kelvin
Nov 21 at 0:34
1
i got 'dname' => string 'asdf' (length=4) 'colour' => string 'asdf' (length=4) 'breed' => string 'asdf' (length=4) 'date' => string '2018-11-21' (length=10) 'location' => string 'asdf' (length=4) 'description' => string 'sdf' (length=3) 'status' => string 'missing' (length=7) 'submit' => string 'Submit' (length=6) (my inputs) @JustinSchwimmer
– user10641451
Nov 21 at 0:37
omg yes..i feel stupid thank you xD @Kelvin
– user10641451
Nov 21 at 0:39
add a comment |
I created a form in which user must fill out details about a doggy they found or they lost. When I am pressing the submit button it looks to work. I have my form empty again, but my data is not in the database. When I am trying to refresh the page it shows me a warning that my data may be lost. It seems that the server is trying to pass my data in the database but for some reason it can't. Can anyone help me? My code is below:
<?php
if (isset($_POST['submit'])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
$image = $_FILES['image']['tmp_name'];
$imgContent = addslashes(file_get_contents($image));
$host = "xx";
$user = "xx";
$pass= "xx";
$dbname = "xx";
$conn = new mysqli($host,$user,$pass, $dbname );
// image file directory
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); //SQL I
if ($conn->connect_error) {
die("Connection failed : ".$conn->connect_error); //fixme
} else {
echo "Connected successfully";
}
}
if (isset($_POST['status1'])) {
$sql = "INSERT INTO foundDogs( dname ,breed,colour,description,datefound,location,picture,posterID) VALUES
('" . $_POST["dname"] . "','" . $_POST["breed"] . "','" . $_POST["colour"] . "','" . $_POST["description"] . "','" . $_POST["date"] . "','" . $_POST["location"] . "','$image',NULL)";
} else {
$sql = "INSERT INTO lostDogs( dname ,breed,colour,description,datefound,location,picture,posterID) VALUES
('" . $_POST["dname"] . "','" . $_POST["breed"] . "','" . $_POST["colour"] . "','" . $_POST["description"] . "','" . $_POST["date"] . "','" . $_POST["location"] . "','$image',NULL)";
}
// echo $sql;
// if ($conn->query($sql) == TRUE) {
// echo "<p> Insert successful </p>";
// } else {
// die("error on insert" . $conn->error);
// }
$conn->close();
}
?>
<div id="container">
<div class="content">
<h2>Fill out the form below</h2>
<div class="subTable">
<form action="post_dog.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td><smth>Collar Name:</smth></td>
</td>
<tr>
<td><input type="text" name="dname" placeholder="Only enter if you know"><br></td>
</tr>
<tr>
<td><smth>Colour Description:</smth></td>
<tr>
<td><input type="text" name="colour" placeholder="Enter some brief description of the dog"><br></td>
</tr>
<tr>
<td><smth>Breed:</smth></td>
</tr>
<tr>
<td><input type="text" name="breed" placeholder="Only enter if you know"><br></td>
</tr>
<tr>
<td><smth>Date lost/found:</smth></td>
</tr>
<tr>
<td><input id="datefield" type="date" name="date"><br></td>
</tr>
<tr>
<td><smth>Location lost/found:</smth></td>
</tr>
<tr>
<td><input type="text" name="location" placeholder="Please enter the location"><br></td>
</tr>
<tr>
<td><smth>Doggo Description:</smth></td>
</tr>
<tr>
<td><textarea type="text" name="description" rows="5" cols="30" placeholder="Describe the doggy as best as you can!!"></textarea></td>
</tr>
<tr>
<td><smth>Missing:</smth><input type="checkbox" name="status" value="missing"><smth> Found:</smth><input type="checkbox" name="status1" value="found"></td>
</tr>
<tr>
<td><smth>Image:</smth> <input type="file" name="image"></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
** My connection details im sure that are correct.
php html mysql database
I created a form in which user must fill out details about a doggy they found or they lost. When I am pressing the submit button it looks to work. I have my form empty again, but my data is not in the database. When I am trying to refresh the page it shows me a warning that my data may be lost. It seems that the server is trying to pass my data in the database but for some reason it can't. Can anyone help me? My code is below:
<?php
if (isset($_POST['submit'])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
$image = $_FILES['image']['tmp_name'];
$imgContent = addslashes(file_get_contents($image));
$host = "xx";
$user = "xx";
$pass= "xx";
$dbname = "xx";
$conn = new mysqli($host,$user,$pass, $dbname );
// image file directory
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); //SQL I
if ($conn->connect_error) {
die("Connection failed : ".$conn->connect_error); //fixme
} else {
echo "Connected successfully";
}
}
if (isset($_POST['status1'])) {
$sql = "INSERT INTO foundDogs( dname ,breed,colour,description,datefound,location,picture,posterID) VALUES
('" . $_POST["dname"] . "','" . $_POST["breed"] . "','" . $_POST["colour"] . "','" . $_POST["description"] . "','" . $_POST["date"] . "','" . $_POST["location"] . "','$image',NULL)";
} else {
$sql = "INSERT INTO lostDogs( dname ,breed,colour,description,datefound,location,picture,posterID) VALUES
('" . $_POST["dname"] . "','" . $_POST["breed"] . "','" . $_POST["colour"] . "','" . $_POST["description"] . "','" . $_POST["date"] . "','" . $_POST["location"] . "','$image',NULL)";
}
// echo $sql;
// if ($conn->query($sql) == TRUE) {
// echo "<p> Insert successful </p>";
// } else {
// die("error on insert" . $conn->error);
// }
$conn->close();
}
?>
<div id="container">
<div class="content">
<h2>Fill out the form below</h2>
<div class="subTable">
<form action="post_dog.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td><smth>Collar Name:</smth></td>
</td>
<tr>
<td><input type="text" name="dname" placeholder="Only enter if you know"><br></td>
</tr>
<tr>
<td><smth>Colour Description:</smth></td>
<tr>
<td><input type="text" name="colour" placeholder="Enter some brief description of the dog"><br></td>
</tr>
<tr>
<td><smth>Breed:</smth></td>
</tr>
<tr>
<td><input type="text" name="breed" placeholder="Only enter if you know"><br></td>
</tr>
<tr>
<td><smth>Date lost/found:</smth></td>
</tr>
<tr>
<td><input id="datefield" type="date" name="date"><br></td>
</tr>
<tr>
<td><smth>Location lost/found:</smth></td>
</tr>
<tr>
<td><input type="text" name="location" placeholder="Please enter the location"><br></td>
</tr>
<tr>
<td><smth>Doggo Description:</smth></td>
</tr>
<tr>
<td><textarea type="text" name="description" rows="5" cols="30" placeholder="Describe the doggy as best as you can!!"></textarea></td>
</tr>
<tr>
<td><smth>Missing:</smth><input type="checkbox" name="status" value="missing"><smth> Found:</smth><input type="checkbox" name="status1" value="found"></td>
</tr>
<tr>
<td><smth>Image:</smth> <input type="file" name="image"></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
** My connection details im sure that are correct.
php html mysql database
php html mysql database
edited Nov 21 at 5:19
Jack Stoller
470110
470110
asked Nov 21 at 0:28
user10641451
12
12
closed as off-topic by Nick, Vickel, Mustafa Ekici, UVM, Brian Rogers Dec 15 at 7:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Nick, Vickel, Mustafa Ekici, UVM, Brian Rogers
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Nick, Vickel, Mustafa Ekici, UVM, Brian Rogers Dec 15 at 7:22
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Nick, Vickel, Mustafa Ekici, UVM, Brian Rogers
If this question can be reworded to fit the rules in the help center, please edit the question.
2
is the query($sql) bit actually commented out in the code you're running? That's the bit that will update the database
– Kelvin
Nov 21 at 0:34
1
i got 'dname' => string 'asdf' (length=4) 'colour' => string 'asdf' (length=4) 'breed' => string 'asdf' (length=4) 'date' => string '2018-11-21' (length=10) 'location' => string 'asdf' (length=4) 'description' => string 'sdf' (length=3) 'status' => string 'missing' (length=7) 'submit' => string 'Submit' (length=6) (my inputs) @JustinSchwimmer
– user10641451
Nov 21 at 0:37
omg yes..i feel stupid thank you xD @Kelvin
– user10641451
Nov 21 at 0:39
add a comment |
2
is the query($sql) bit actually commented out in the code you're running? That's the bit that will update the database
– Kelvin
Nov 21 at 0:34
1
i got 'dname' => string 'asdf' (length=4) 'colour' => string 'asdf' (length=4) 'breed' => string 'asdf' (length=4) 'date' => string '2018-11-21' (length=10) 'location' => string 'asdf' (length=4) 'description' => string 'sdf' (length=3) 'status' => string 'missing' (length=7) 'submit' => string 'Submit' (length=6) (my inputs) @JustinSchwimmer
– user10641451
Nov 21 at 0:37
omg yes..i feel stupid thank you xD @Kelvin
– user10641451
Nov 21 at 0:39
2
2
is the query($sql) bit actually commented out in the code you're running? That's the bit that will update the database
– Kelvin
Nov 21 at 0:34
is the query($sql) bit actually commented out in the code you're running? That's the bit that will update the database
– Kelvin
Nov 21 at 0:34
1
1
i got 'dname' => string 'asdf' (length=4) 'colour' => string 'asdf' (length=4) 'breed' => string 'asdf' (length=4) 'date' => string '2018-11-21' (length=10) 'location' => string 'asdf' (length=4) 'description' => string 'sdf' (length=3) 'status' => string 'missing' (length=7) 'submit' => string 'Submit' (length=6) (my inputs) @JustinSchwimmer
– user10641451
Nov 21 at 0:37
i got 'dname' => string 'asdf' (length=4) 'colour' => string 'asdf' (length=4) 'breed' => string 'asdf' (length=4) 'date' => string '2018-11-21' (length=10) 'location' => string 'asdf' (length=4) 'description' => string 'sdf' (length=3) 'status' => string 'missing' (length=7) 'submit' => string 'Submit' (length=6) (my inputs) @JustinSchwimmer
– user10641451
Nov 21 at 0:37
omg yes..i feel stupid thank you xD @Kelvin
– user10641451
Nov 21 at 0:39
omg yes..i feel stupid thank you xD @Kelvin
– user10641451
Nov 21 at 0:39
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
is the query($sql) bit actually commented out in the code you're running? That's the bit that will update the database
– Kelvin
Nov 21 at 0:34
1
i got 'dname' => string 'asdf' (length=4) 'colour' => string 'asdf' (length=4) 'breed' => string 'asdf' (length=4) 'date' => string '2018-11-21' (length=10) 'location' => string 'asdf' (length=4) 'description' => string 'sdf' (length=3) 'status' => string 'missing' (length=7) 'submit' => string 'Submit' (length=6) (my inputs) @JustinSchwimmer
– user10641451
Nov 21 at 0:37
omg yes..i feel stupid thank you xD @Kelvin
– user10641451
Nov 21 at 0:39