<form action="gonder.php" method="post">
<fieldset>
<label for="ad">Ad:</label>
<input type="text" id="ad" placeholder="Tam Adınızı Giriniz" />
<label for="soyad">Soyad:</label>
<input type="text" id="soyad" placeholder="Soyadınızı Giriniz" />
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Email Adresinizi Giriniz" />
<label for="mesaj">Mesaj:</label>
<textarea id="mesaj" placeholder="Mesajınız"></textarea>
<center></center>
<center><input type="submit" value="Onaya Gönder" /></center>
</fieldset>
</form>
This one is my post form and this one ise gonder.php
<?php
$con=mysqli_connect("localhost","root","","yeniziyaretci");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO mesajlar (ad, soyad, email, mesaj)
VALUES ('$_POST[ad]','$_POST[soyad]','$_POST[email]','$_POST[mesaj]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "";
mysqli_close($con);
header("location:index.php?cmd=1");
?>
When I tried to post. They dont give eny error but they send it to mysql as a empty . Like this.
Your input elements have no name attributes.
Also, please read up on the thing called 'sql injection'.
You must select the inputs by name not by id.
change
<input type="text" id="ad" placeholder="Tam Adınızı Giriniz" />
to
<input type="text" name="ad" id="ad" placeholder="Tam Adınızı Giriniz" />
You're using wrong and insecure way to query your database. To get the one you have working, just change your $sql declaration as follows:
$sql = sprintf('INSERT INTO mesajlar (ad, soyad, email, mesaj) VALUES ("%s", "%s", "%s", "%s")', $_POST['ad'], $_POST['soyad'], $_POST['email'], $_POST['mesaj']);
But I would suggest you to learn ways to avoid mysql injection.
EDIT
And yes, you're missing "name" attributes on your form.
Put this, it will work:
<form action="gonder.php" method="post">
<fieldset>
<label for="ad">Ad:</label>
<input type="text" id="ad" name=="ad" placeholder="Tam Adınızı Giriniz" />
<label for="soyad">Soyad:</label>
<input type="text" id="soyad" name="soyad" placeholder="Soyadınızı Giriniz" />
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Email Adresinizi Giriniz" />
<label for="mesaj">Mesaj:</label>
<textarea id="mesaj" name="mesaj" placeholder="Mesajınız"></textarea>
<center></center>
<center><input type="submit" value="Onaya Gönder" /></center>
</fieldset>
</form>
Either try
$sql="INSERT INTO mesajlar (ad, soyad, email, mesaj)
VALUES
('".$_POST[ad]."','".$_POST[soyad]."','".$_POST[email]."','".$_POST[mesaj]."')";
or
$sql="INSERT INTO mesajlar (ad, soyad, email, mesaj)
VALUES
('{$_POST[ad]}','{$_POST[soyad]}','{$_POST[email]}','{$_POST[mesaj]}')";
EDIT
Sorry I didn't notice but there is an issue in your html form too
you need to have name="" attributes into you form elements as suggested by Ø Hanky Panky Ø
<form action="gonder.php" method="post">
<fieldset>
<label for="ad">Ad:</label>
<input type="text" id="ad" name="ad" placeholder="Tam Adınızı Giriniz" />
</fieldset>
</form>
Related
I'm trying to get the information from this form into a database but get an error as below
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
<form action= "" method= "POST">
<label for="title">Job title</label> <input type="text" name="title" /> <br>
<label for="refcode">Reference Code</label> <input type="text" name="refcode" /> <br>
<label for="salary">Salary</label> <input type="text" name="salary" /><br>
<label for="location">Location</label> <input type="text" name="location" /><br>
<label for="description"> Job description<textarea name="description" /> </textarea><br>
<input type="submit" value="Submit" name="submit" />
</form>
My PHP file
<?php
$stmt = $pdo->prepare('INSERT INTO jobs (title, refcode, salary, location, description)
VALUES(:title,:refcode,:salary,:location, :description) ');
$stmt-> execute($_POST);
?>
I think this is happen with the submit value of post variable, Didn't you try unset the element submit by post request.
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 8 years ago.
I am using wamp server and trying to create simple sign up page with html forms and php script; but the problem is whenever I am hitting on submit button on html page, it is directly showing the entire content of php file in next browser instead of executing the php file.
the following is my form code(index.php)
<form id="login" action="register.php" method="post">
<p>
<label for="first name" >First Name</label>
<input type="text" name="fname" value="" />
</p>
<p>
<label for="last name" >Last Name</label>
<input type="text" name="lname" value="" class="radius2" />
</p>
<p>
<label for="gender" >Gender</label>
<input type="text" name="gender" />
</p>
<p>
<label for="username" >Email</label>
<input type="text" name="username" />
</p>
<p>
<label for="password" >Password</label>
<input type="password" name="password" />
</p>
<p>
<input type="submit" name="submit">Login</input>
</p>
</form>
the following is my php code
$bd = mysqli_connect("localhost", "root","yash1991","shaunak") or die("Could not connect database");
echo" hello1";
mysqli_query($bd,"INSERT INTO users (fname, lname, gender, email_id, username, password) VALUES ("$fname", "$lname", "$gender", "$username", "$password")");
mysqli_close($bd);
?>
I suppose that you running WAMP server, and stored your files (index.php & register.php) in folder inside "C:\wamp\www\" and you access your index page using url "127.0.0.1/stack/index.php"
Check your index.php file with the following code:
<form id="login" action="register.php" method="post">
<p>
<label for="First Name">First Name</label>
<input type="text" name="fname" value="" />
</p>
<p>
<label for="last Name">Last Name</label>
<input type="text" name="lname" value="" class="radius2" />
</p>
<p>
<label for="gender">Gender</label>
<input type="text" name="gender" />
</p>
<p>
<label for="username">Email</label>
<input type="text" name="username" />
</p>
<p>
<label for="password">Password</label>
<input type="password" name="password" />
</p>
<p>
<input type="submit" name="submit" value="Login" />
</p>
</form>
Check your register.php file with the following code:
<?php
session_start();
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$gender=$_POST['gender'];
$username=$_POST['username'];
$password=$_POST['password'];
echo "hello ";
$bd= mysqli_connect("localhost","root","yash1991","shaunak") or die ("Could not connect DB");
$try = mysqli_query($bd, "INSERT INTO users (`fname`, `lname`, `gender`, `email_id`, `password`) VALUES ('$fname', '$lname', '$gender', '$username', '$password')");
if($try === false)
{
echo '<br />error - ';
echo mysqli_error($bd);
} else {
echo '<br />all good';
}
mysqli_close($bd);
?>
When I send my form to another page it says: Notice: Undefined index: gebruikersnaamRegistreren in on line 55
this for every name of the inputs
HTML Code
<form action="RegistrerenSucces.php" method="POST">
<fieldset id="inputs">
<input id="gebruikersnaam" type="text" name="gebruikersnaamRegistreren" placeholder="Gebruikersnaam " required />
<input id="paswoord" type="password" name="paswoordRegistreren" placeholder="Paswoord" required />
<input id="voornaam" type="text" name="voornaamRegistreren" placeholder="Voornaam" required />
<input id="achternaam" type="text" name="achternaamRegistreren" placeholder="Achternaam" required />
<input id="email" type="email" name="emailRegistreren" placeholder="E-mail adres" required />
<input id="straat" type="text" name="straatRegistreren" placeholder="Straatnaam en huisnummer" required />
<input id="postcode" type="text" name="postcodeRegistreren" placeholder="Postcode" required />
<input id="gemeente" type="text" name="gemeenteRegistreren" placeholder="Gemeente" required />
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" value="Registreren" />
</fieldset>
</form>
PHP Code
<?php
$dbhost='localhost';
$dbuser='root';
$dbpassword='usbw';
$dbdatabase='computingstore';
$paswoordEncrypted = hash('sha512',$_POST['paswoordRegistreren']);
print_r($_POST);
/*Database verbinden*/
$link = mysqli_connect($dbhost , $dbuser ,$dbpassword , $dbdatabase);
$query = ("INSERT INTO gebruiker (gebruikersnaam, paswoord, voornaam, achternaam, e-mail, straatnaam, postcode, gemeente)
VALUES
('".$_POST['gebruikersnaamRegistreren']."',
'".$paswoordEncrypted."',
'".$_POST['voornaamRegistreren']."',
'".$_POST['achternaamRegistreren']."',
'".$_POST['emailRegistreren']."',
'".$_POST['straatnaamRegistreren']."',
".$_POST['postcodeRegistreren'].",
'".$_POST['gemeenteRegistreren']."')");
mysqli_query($link,$query);
/*Verbing afsluiten*/
mysqli_close($link);
?>
How can i fix this error i have been looking for it for 2 days now.
Try to use isset to determine if the index is defined and assign an empty value if it is not, and see if the problem resolves.
For example, use the following in the second page:
isset($_POST['gebruikersnaamRegistreren']) ? $_POST['gebruikersnaamRegistreren'] : "";
instead of
$_POST['gebruikersnaamRegistreren']
repeat this for all the fields for which you are having problem .
Everything seems to work perfectly. Try to use prepare for your queries though. Nevertheless I recommend you to check for any javascript issues.
I am trying to save the value of the radio buttons in my database table choice. I get the message Data saved successfully but no value is stored in the table.
Form:
<form id="myForm" method="post" action="">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<center<legend>Choose in which category you'd like to be included</legend></center>
<p><input type="radio" name="choice[]" value="player" id="player" class="custom" />
<label for="player">Player</label>
<input type="radio" name="choice[]" value="coach" id="coach" class="custom" />
<label for="coach">Coach</label>
<input type="radio" name="choice[]" value="supporter" id="supporter" class="custom" />
<label for="supporter">Supporter</label>
<input type="radio" name="choice[]" value="sponsor" id="sponsor" class="custom" />
<label for="sponsor">Sponsor</label>
<input type="radio" name="choice[]" value="alumni" id="alumni" class="custom" />
<label for="alumni">Alumni</label>
<input type="radio" name="choice[]" value="other" id="o" class="custom" />
<label for="o">Other</label>
</fieldset>
</div>
<div data-role="fieldcontain">
<label for="name">Please enter your name:</label>
<input type="text" name="name" id="name" class="required" value="" autocomplete="off" /><br />
<label for="email">Please enter your e-mail:</label>
<input type="text" name="email" id="email" value="" class="required" autocomplete="off" /><br />
<label for="phone">Please enter your phone number:</label>
<input type="number" name="phone" id="phone" value="" class="required" autocomplete="off" />
<br><br>
<label for="other">Other comments</label>
<textarea name="other" id="other" autocomplete="off" placeholder="Anything else you'd like to add?">
</textarea>
<p><strong id="error"></strong></p>
<br><br>
<input type="submit" id="save" name="save" value="Submit Form" />
<p id="response"></p>
</form>
</body>
</html>
PHP:
<?php
$mysqli = new mysqli('localhost', 'root', '', 'E-mail list');
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if(isset($_POST['save']))
{
$name = $mysqli->real_escape_string($_POST['name']);
$email = $mysqli->real_escape_string($_POST['email']);
$phone = $mysqli->real_escape_string($_POST['phone']);
$other = $mysqli->real_escape_string($_POST['other']);
$choice = $mysqli->real_escape_string($_POST['choice']);
$query = "INSERT INTO Players (`name`,`email`,`phone`,`other`,`choice`) VALUES ('".$name."','".$email."','".$phone."','".$other."','".$choice."')";
if($mysqli->query($query))
{
echo 'Data Saved Successfully.';
}
else
{
echo 'Cannot save data.';
}
}
?>
var_dump($_POST) to sere what data flooding in.
One thing more to check if its save or submit ? in $_POST['save']
EDIT
After getting your full form - the error lies in your center tag
Change <center<legend> TO <center><legend>
The error - ↑ in this tag
I would like to get some user data using a php form and store it in a mysql database , trouble is, the page simply refreshes when I submit the form.
Here is my php form:
<form id="companyform" name="companyform" method="post" action="index3.php" data-ajax="false">
<b>To enlist your business fill in the form below:</b>
<p>
<label for="name">Company Name:</label>
<input type="text" name="companyname" id="companyname" data-mini="true"/>
</p>
<p>
<label for="name">Company Address:</label>
<input type="text" name="companynaddress" id="companynaddress" data-mini="true"/>
</p>
<p>
<label for="textfield">Tel No.:</label>
<input type="text" name="tel" id="tel" data-mini="true"/>
</p>
<p>
<label for="textfield">Fax No.:</label>
<input type="text" name="fax" id="fax" data-mini="true"/>
</p>
<p>
<label for="textfield">Email:</label>
<input type="text" name="email" id="email" data-mini="true"/>
</p>
<p>
<label for="textfield">Website Address:</label>
<input type="text" name="website" id="website" data-mini="true"/>
</p>
<p>
<label for="textfield">Contact Person Name:</label>
<input type="text" name="contactname" id="contactname" data-mini="true"/>
</p>
<p>
<label for="textfield">Contact Person Number:</label>
<input type="text" name="contactnumber" id="contactnumber" data-mini="true"/>
</p>
<p>
<label for="textfield">Contact Person Email:</label>
<input type="text" name="contactemail" id="contactemail" data-mini="true"/>
</p>
<p>
<input name="submit" type="submit" id="submit" value="Submit" />
</p>
</form>
and here is my database connection code:
<?php
if (array_key_exists('submit', $_POST)) {
$con = mysql_connect("host", "user", "pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("botswanasearchdb", $con);
$companyname = $_POST['companyname'];
$companyaddress = $_POST['companyaddress'];
$tel = $_POST['tel'];
$fax = $_POST['fax'];
$emailid = $_POST['emailid'];
$website = $_POST['website'];
$contactname = $_POST['contactname'];
$contactnumber = $_POST['contactnumber'];
$contactemail = $_POST['contactemail'];
// prepare the SQL query
$sql = "INSERT INTO businessuser (companyname, companyaddress, tel, fax, emailid, website, contactname, contactnumber, contactemail) VALUES ('$companyname', '$companyaddress', '$tel', '$fax', '$emailid', '$website', '$contactname', '$contactnumber', '$contactemail')";
mysql_close($con);
}
?>
This is your form tag:
<form id="companyform" name="companyform" method="post" action="index3.php" data-ajax="false">
So you are submitting the form to index3.php (the action attribute). According to your comment index3.php contains your form and that is why the form refreshes when you submit it. You are basically reloading your form on form submit.
You need to submit the form to your php script that contains the php code you posted.
Edit: If everything is on the same page, you can do something like:
if (array_key_exists('submit', $_POST))
{
// your code
// show thank you message
}
else
{
// show form
}
Another edit: As you are using the deprecated mysql_* functions and not escaping the data, you have an sql injection whole and a ' character in your data will break your query. You should switch to PDO / mysqli and prepared statements. And always add error handling.