Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
this is my html code
<?php include('process.php') ?>
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<from action="index.php.php" method="post">
<?php include('errors.php'); ?>
<lable> name </lable>
<input type="text" name="name" placeholder="enter your name">
<lable>location</lable>
<input type="text" name="location" placeholder="enter your location">
<button type="submit" name="save_btn" >update</button>
</from>
</body>
</html>
this is my php code
<?php
session_start();
// initializing variables
$name="";
$location="";
// connect to the database
$db = mysqli_connect('localhost', 'newuser', 'password', 'curd');
// REGISTER USER
if (isset($_POST['save_btn'])) {
// receive all input values from the form
$name = mysqli_real_escape_string($db, $_POST['name']);
$location = mysqli_real_escape_string($db, $_POST['location']);
$query = "INSERT INTO data (name, location) VALUES('$name', '$location')";
mysqli_query($db, $query);
}
why its not store in data base? data base name correct and i have 3 tables
id (ai)
name (var 200)
location (var 200)
in my browser i can locate index.php but when i click button nothing happen any one can explain why its not working?
Fine, it seems that the problem is caused by 2 important typos:
<from action="index.php.php" method="post"> should be <form action="index.php" method="post">.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
i download 2 php file, one is index. php for input form, and other is insert.php. i have put them on the same folder.
when i click submit it execute insert.php file it work fine and it insert form data into my database. but the question is: how it is called? no code line on the index.php calling the insert.php file.
here is a code of index.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>GFG- Store Data</title>
</head>
<body>
<center>
<h1>Storing Form data in Database</h1>
<form action="insert.php" method="post">
<p>
<label for="firstName">Name:</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="lastName">Branch:</label>
<input type="text" name="branch" id="branch">
</p>
<p>
<label for="Gender">Roll Number:</label>
<input type="text" name="roll_no" id="roll_no">
</p>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
here is the code of insert.php
<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
</head>
<body>
<center>
<?php
$conn = mysqli_connect("localhost", "root", "", "test");
// Check connection
if($conn === false){
die("ERROR: Could not connect. "
. mysqli_connect_error());
}
// Taking all 3 values from the form data(input)
$name = $_REQUEST['name'];
$branch = $_REQUEST['branch'];
$roll_no = $_REQUEST['roll_no'];
// Performing insert query execution
// here our table name is college
$sql = "INSERT INTO student VALUES ('$name','$branch','$roll_no')";
if(mysqli_query($conn, $sql)){
echo "<h3>data stored in a database successfully."
. " Please browse your localhost php my admin"
. " to view the updated data</h3>";
}
else{
echo "ERROR: Hush! Sorry $sql. "
. mysqli_error($conn);
}
// Close connection
mysqli_close($conn);
?>
</center>
</body>
</html>
insert.php is calling after clicking on submit button by "action" attribute which you have used in tag.
<form action="insert.php" method="post">
You can set another path as well as if you want to keep insert.php on any other folder location.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
when i'm trying to run my code i come across a blank site and i don't know how to fix it
i guess my calculations aren't working
here's the codes:
<html>
<head>
<meta charset="utf-8">
<title>Kalkulator spalania paliwa</title>
</head>
<body align="center">
<h1>Kalkulator spalania paliwa.</h1><br>
<form action="get_info.php" method="get">
Podaj spalone paliwo: <input type="text" name="sp"> l<br>
Podaj przejechaną odległość: <input type="text" name="km"> km<br>
<input type="submit">
</form>
</body>
and
<html>
<body>
<?php
function spalanie(){
$sp = $_GET["sp"];
$km = $_GET["km"];
$wynik = $sp * 100 / $km;
echo $wynik;
}
?>
</body>
You have defined the function but haven't called it. Call it like this below the function like
spalanie();
beacause your input tag has no value...
<input type="text" name="km" value="km">
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to insert the values from my form after clicking an option from my drop down list. However, it keeps telling me that my LINE 4 and LINE 5 of my submit.php has error. I do not know what is wrong with my $_POST statement.
Please enlighten me, I am very new to PHP and HTML.
Below is my code for my drop down list.
<!DOCTYPE HTML>
<html>
<head>
<title> Search by Development </title>
<meta http-equiv="Content-Type" content ="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" action="submit.php" method="post">
<label type='text'> Name:</label>
<select name ='userID'>
<?php
$conn1 = new mysqli('localhost', 'root','','carpark_project');
$result1 = $conn1->query("select userid from user");
while($row =$result1->fetch_assoc())
{ ?>
<option value="<? php echo $row['userid']; ?>">
<?php echo $row['userid']; ?>
</option>
<?php
} ?>
</select>
<br>
<label type='text'> Development:</label>
<select name ='Development'>
<?php
$conn = new mysqli('localhost', 'root','','carpark_project');
$result = $conn->query("select development from carpark");
while($row =$result->fetch_assoc())
{ ?>
<option value="<? php echo $row['development']; ?>">
<?php echo $row['development']; ?>
</option>
<?php
} ?>
</select>
<br>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
Below is the action PHP file.
<?php
$con = new mysqli('localhost','root','','carpark_project');
$development = $_POST['Development'];
$userid = $_POST['userid'];
$inserthistory = "Insert into history (userid, development) values ('$userid','$development')";
$result=mysqli_query($con,$inserthistory);
if($result)
{
header("refresh:5; url=history.php");
}
else
{
echo "Not Updated";
}
?>
Please help, thank you!
You have a typo. It should be $userid = $_POST['userID'];
Also use prepared statements here to prevent sql injection attacks
$inserthistory = "Insert into history (userid, development) values (? , ?)"; #create sql string with placeholders to prevent sql injection
$sql = $con->prepare($inserthistory); #prepare the query.this line returns true or false
$sql->bind_param('ss' , $userid, $development); #now specify that the variables are strings and then add the variables
if ($sql->execute() === true){ #execute it
#query successful
} else {
#error
echo $con->error;
}
Also just an important observation. You should have one file containing the database connection. Currently you are creating a new database connection for every form input which is bad.. Create a file and then establish the connection there. Then all you do is include that file where you need.
Change <select name ='userID'> to <select name ='userid'>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm very new to this, I made a php to test the connection with the database and it seems fine, but writing information to a table isn't working.
Heres the index.php (where the signup form is)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form action="signup.php" method="POST">
<input type="text" name="firstname" placeholder="Firstname"><br>
<input type="text" name="lastname" placeholder="Lastname"><br>
<input type="text" name="uid" placeholder="Username"><br>
<input type="text" name="pwd" placeholder="Password"><br>
<input type="submit">
</form>
</body>
</html>
Heres the signup.php (which is what i think might be broken)
<?php
include 'dbh.php';
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
$sql = "INSERT INTO useraccounts (firstname, lastname, uid, pwd)
VALUES ('$firstname', '$lastname', '$uid', '$pwd')";
$result = mysqli_query($conn, $sql);
header("Location: index.php");
?>
and heres the dbh.php which connects to mysql
<?php
$conn = mysql_connect("hostname", "username", "password", "databasename");
if (!$conn) {
die("Connection failed: ".mysql_connect_error());
}
?>
I'm sure there's already a load of questions like mine out there but I'm so new to this I'm finding it hard to learn from the answers I've come across
In your signup.php you use the following line (mysqli):
mysqli_query($conn, $sql);
However in your dbh.php you use (mysql):
mysql_connect("hostname", "username", "password", "databasename");
And
mysql_connect_error());
Other than that I can't see anything else what could be wrong.
Your query seems correct and you declare your post data.
I suggest you try to look for error messages if the solution above doesnt provide anything.
Try quote you columns with => `
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Hey I have a database that contains information about different countries. I also have a html page where you can submit information about countries. Can someone help me to write a code that says that the information has been stored in the database instead of it just redirecting to a blank page?
Here is my html page where you submit information:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Sett inn land</title>
</head>
<body>
<form action="geoinn.php" method="get">
Land: <input type="text" name="navn"> <br>
Hovedstad: <input type="text" name="hovedstad"> <br>
Areal: <input type="text" name="areal"> <br>
Folketall: <input type="text" name="folketall"> <br>
<input type="submit" value="Legg inn informasjon">
</form>
</body>
</html>
And here is the page that you are redirected to when you click submit on the other page. This is the page where I want to have a code saying either that "The information has been stored in our database" or that it has not:
<?php
$tjener = "localhost";
$brukernavn = "root";
$passord ="";
$database ="Geografi";
$kobling = mysqli_connect($tjener,$brukernavn,$passord,$database);
$kobling->set_charset("utf8");
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Geografi</title>
</head>
<body>
<?php
$land = $_GET["navn"];
$hovedstad = $_GET["hovedstad"];
$areal = $_GET["areal"];
$folketall = $_GET["folketall"];
$sql ="INSERT INTO land (navn,hovedstad, areal, folketall) VALUES('$land','$hovedstad','$areal', '$folketall')";
mysqli_query($kobling, $sql);
mysqli_close($kobling);
?>
</body>
</html>
Add some output and you will get some output. The blank page you get is the page that does the updates. You add the basic HTML page tags but do not output anything inside the <body>
$sql ="INSERT INTO land
(navn,hovedstad, areal, folketall)
VALUES('$land','$hovedstad','$areal', '$folketall')";
$result = mysqli_query($kobling, $sql);
if ( $result === FALSE ) {
echo '<p>FAILED MESSAGE</p>';
} else {
echo '<p>SUCCESS MESSAGE</p>';
}
echo "<p>Land = $land</p>";
echo "<p>hovedstad = $hovedstad</p>";
// and so on
mysqli_close($kobling);
As Jay says,
Your script is at risk for SQL Injection Attacks. Learn about prepared statements for MySQLi.