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.
Related
I have a large amount of input fields. How can I pass the values into an array so I can pass the array from one page to another?
example:
<input type="text" value=<?php $arry = "compName" ?> placeholder="Company Name" />
Is this legal? How can I do this properly?
EDIT:
In my page, I have "add" and "delete" buttons that will add/delete more input fields. I also have a "preview" button at the bottom. User will add/delete before hitting preview. Preview will collect all input and will call the next page. So the amount of field is unknown.
Here's what my code/markup looks like:
<div class="panel" style="width: 98%; margin:0 auto">
<div class="row">
<div class="large-6 columns">
Advertiser Info: <hr>
<input type="text" value="compName" placeholder="Company Name" />
<input type="text" value= "adEmail" placeholder="Email" />
<input type="text" value="adContName" placeholder="Contact Name" />
<input type="text" value="adPhone" placeholder="Phone # (NO DASHES)" />
<input type="text" value="adStreet" placeholder="Street Address" />
<input type="text" value="adCity" placeholder="City" />
<input type="text" value="adState" placeholder="State/Provice" />
<input type="text" value="adZip" placeholder="Zip/Postal Code" />
<input type="text" value="adCountry" placeholder="Country" />
</div>
<div class="large-6 columns">
Billing Info: <hr>
<input type="text" value="bEmail" placeholder="Email" />
<input type="text" value="bContName" placeholder="Contact Name" />
<input type="text" value="bPhone" placeholder="Phone # (NO DASHES)" />
<input type="text" value="bStreet" placeholder="Street Address" />
<input type="text" value="bCity" placeholder="City" />
<input type="text" value="bState" placeholder="State/Provice" />
<input type="text" value="bZip" placeholder="Zip/Postal Code" />
<input type="text" value="bCountry" placeholder="Country" />
</div>
</div>
</div>
So when the user hits add and EXACT copy of above code will be made.
With that said, I want to be able to use PHP arrays for html values to pass. How can I set my inputs so that I can do this?
You can do some tweaks like:
Using input type elements as array elements.
So that:
<input type="text" name="elem[name]" value="<?php echo $YOUR_VALUE;?>"
<input type="text" name="elem[class]" value="<?php echo $YOUR_VALUE;?>"
<input type="text" name="elem[marks]" value="<?php echo $YOUR_VALUE;?>"
So that the variables are you are posting should be less.
In this case, you are posting only one variable instead of three.
Use Jquery to get all the values of input fields and make a json object of {input_name:value} or array variable of key value and then pass it in argument.
var key_value = {};
$('input').each(function(){
key_value[$(this).attr('name')]= $(this).val();
})
alert(JSON.stringify(key_value));
Now you have an object with field name as key and its value.
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.
<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>
I am currently developing an app and i am getting difficulties on IE8.
I have the following code:
<form class="fillClaimForm" name="fillClaimForm" method="POST" enctype="multipart/form-data" action="<?php print BASE_URL; ?>?action=insertBlogger" >
<label for="fblogName">Blog's name: </label>
<input type="text" name="fblogName" id="fblogName" class="cfInput" placeholder ="Complex" required />
<label for="fblogUrl">URL: </label>
<input type="text" name="fblogUrl" id="fblogUrl" class="cfInput" placeholder ="www.complex.com" required />
<label>Blog's logo: </label>
<div class="upload-file-container"><span>UPLOAD</span>
<input type="file" name="fblogLogo" id="fblogLogo"/>
<p class="ErrLoad error" style="display:none;">Please load your logo</p>
</div>
<label for="fEmail">Email adresse: </label>
<input type="email" name="fEmail" id="fEmail" class="cfInput" required />
<label for="frNum">Phone number: </label>
<input type="tel" name="frNum" id="frNum" class="cfInput" required />
<input type="hidden" name="idVid" id ="idVid" value=""/>
<input type="hidden" name="idRubrique" id ="idRubrique" value=""/>
<button id="sendClaim" class="sendClaim">SEND</button>
Consequently, I am doing a form submission using jquery:
......submit(function(){
validate=false;
formInfo = validateForm(validate,$thisLi);
if(formInfo.validate){
**fillClaimForm.submit();**
}
return false;
});
It is working on all browsers except IE8
Can someone kindly help me.
Thanks
Close your form.
Also give the same name as the id for your form and use
$("#formId").submit();
Code
<form class="fillClaimForm" name="fillClaimForm" method="POST" enctype="multipart/form-data" action="<?php print BASE_URL; ?>?action=insertBlogger" >
<label for="fblogName">Blog's name: </label>
<input type="text" name="fblogName" id="fblogName" class="cfInput" placeholder ="Complex" required />
<label for="fblogUrl">URL: </label>
<input type="text" name="fblogUrl" id="fblogUrl" class="cfInput" placeholder ="www.complex.com" required />
<label>Blog's logo: </label>
<div class="upload-file-container"><span>UPLOAD</span>
<input type="file" name="fblogLogo" id="fblogLogo"/>
<p class="ErrLoad error" style="display:none;">Please load your logo</p>
</div>
<label for="fEmail">Email adresse: </label>
<input type="email" name="fEmail" id="fEmail" class="cfInput" required />
<label for="frNum">Phone number: </label>
<input type="tel" name="frNum" id="frNum" class="cfInput" required />
<input type="hidden" name="idVid" id ="idVid" value=""/>
<input type="hidden" name="idRubrique" id ="idRubrique" value=""/>
<button id="sendClaim" class="sendClaim">SEND</button>
</form>
$("#sendClaim").click(function(){
validate=false;
formInfo = validateForm(validate,$thisLi);
if(formInfo.validate){
$("#fillClaimForm").submit();
}
return false;
});
Try this:
document.forms.fillClaimForm.submit();
Or if the ...... in your code represents creating of a submit handler on that same form you can probably just say this.submit().
How may I get data of this form to be received in an email?
<form class="pa">
<fieldset>
<label>Name <em>*</em></label>
<input type="text" placeholder="">
<label>Email <em>*</em></label>
<input type="text" placeholder="">
<label>Age <em>*</em></label>
<input type="text" placeholder="">
<label>Phone <em>*</em></label>
<input type="text" placeholder="">
<label>Zip Code <em>*</em></label>
<input type="text" placeholder="">
<a class="submit pa" href="#"><img src="wp-content/themes/child/img/submit.png"</a>
</fieldset>
</form>
You'll need a server-side script to accept the form data, and send an email with it. You can do this PHP and several other languages. Judging by your sample code you have WordPress, so you might look into the ContactForm plugin.
wrap your input's with something like
<form class="pa" action="yourscript.php" method="post">
.
.
<label for="name">Name <em>*</em></label>
<input type="text" placeholder="" id="name" name="name">
.
<input type="submit" value="Submit" />
<!-- remove the a tag because that won't submit your form data or use type="image" -->
<input type="image" src="wp-content/themes/child/img/submit.png" />
</form>
then use $_POST['name'] to retrieve the value
you have to add name='' to each inputs to have them sent to your script eg <input type="text" id="name" name="name"> and they have to be different otherwise they might get overridden.
also your labels will need the for= to be useable which uses the id of the input eg <label for="name">Name <em>*</em></label>