When my PHP script creates a URL like: ..../recover.php?success then create an error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#testlogin.muhammadmasud.info to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
MY script `
?>
<p>Thanks, we have emailed you.</p>
<?php
}else{
$mode_allowd = array('username', 'password');
if(isset($_GET['mode']) === true && in_array($_GET['mode'], $mode_allowd) === true){
if(isset($_POST['email']) === true && empty($_POST['email']) === false){
if(email_exists($_POST['email']) === true){
Recover($_GET['mode'], $_POST['email']);
header('location: recover.php?success');
exit();
}else{
echo '<p style="color:red">Oops, we could not find that email address!</p>';
}
}
?>
<form action="" method="post">
<table style="boder:none">
<tr>
<td>Please enter your email address:</td>
</tr>
<tr>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td><input type="submit" value="Recover"></td>
</tr>
</table>
</form>
<?php
}else{
header('location: index.php');
exit();
}`
Related
i create custom plugin and i have table wp_customers , i try to select all things in my table but wordpress just show me Fatal error: Uncaught Error: Call to a member function get_results() on null in C:\xampp\htdocs\wordpress\wordpress\wp-content\plugins\rflredirection\public\showResult.php:4 Stack trace: #0 {main} thrown in C:\xampp\htdocs\wordpress\wordpress\wp-content\plugins\rflredirection\public\showResult.php on line 4
i see codex , i use some antoher codes for select but i just that massege , this is my codes to try
global $wpdb;
$results = $wpdb->get_results('SELECT * FROM $wpd->wp_customers DESC ');
and
$results = $wpdb->get_results('SELECT * FROM wp_customers');
and
$table_name = $wpdb->prefix . "wp_customers";
$results = $wpdb->get_results("SELECT code FROM ".$table_name");
and i try get version but nothing
$dbVersion = $wpdb->db_version();
if ($dbVersion) {
echo "Running MySQL " . $dbVersion;
} else {
echo "MySQL version unavailable.";
}
When you use The wpdb Class, there is no need to include wp_ in tables name.
should be just like this:
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM $wpdb->customers");
// ^ use without (wp_)
Edit #1:
you have an error on foreach loop:
you should write foreach($results as $rows) instead of your error : foreach($rows as $results)
and don't forget the semicolons when get values, echo $rows["id"]; and so on..
your code should like:
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM $wpdb->customers");
?>
<body>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Family</th>
<th>Numbers</th>
<th>Tell</th>
</tr>
<?php foreach($results as $rows){
?>
<tr>
<td>
<?php echo $rows["id"]; ?>
</td>
<td>
<?php echo $rows["name"]; ?>
</td>
<td>
<?php echo $rows["family"]; ?>
</td>
<td>
<?php echo $rows["numbers"]; ?>
</td>
<td>
<?php echo $rows["tell"]; ?>
</td>
<?php }?>
</tr>
</table>
Edit #2:
Copy all this lines and paste on top of your page to include wordpress package:
<?php
/**
* WordPress User Page
*
* Handles authentication, registering, resetting passwords, forgot password,
* and other user handling.
*
* #package WordPress
*/
// Make sure that the WordPress bootstrap has run before continuing.
require( dirname(__FILE__) . '/wp-load.php' );
// Now your page codes goes here ...
Hello Every one i have a form and i want to add reCAPTCHA to it.
This is my form
<form action="index.php" method="POST">
<div class="header"></div>
<div class="headerimg">
<img border="0" src="logo.png" alt="AUD Confession" width="auto" height="auto">
<div class="headertxt">Confession</div>
</div>
<table font-family="inherit">
<tr><td class="comm" colspan="2">Comment: </td></tr>
<tr><td colspan="5"><textarea name="comment" rows="5" cols="50" id="comments" class="common" autofocus></textarea></td></tr>
<tr><td><?php
require_once('recaptchalib.php');
$publickey = "6Lc1RewSAAAAAO2Emd1_ICM5qUssQdfqF0vRiCE9"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?></tr></td>
<tr><td colspan="2"><input type="submit" name="submit" class="myButton" value="SUBMIT"></td></tr>
</table>
</form>
The Problem is that reCAPTCHA check it on action="verify.php" and show whether it is correct or not but do not submit the form values on index.php.
Codes on verify.php
<?php
require_once('recaptchalib.php');
$privatekey = "6Lc1RewSAAAAAPBsu1AnNhJpIbS64XR0fLqEioVb";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
I want reCAPTCHA to check on the same page i:e; action="index.php".
Please Help.
Or suggest something similar.
I myself figured it out and got the solution.
All I have to do is add some codes in the place of
// Your code here to handle a successful verification
The php codes that insert User Data into database.
I am creating a job application form which has a drop down box that the user can select a city from and continue filling out the form. The objective here is depending on what city the user selected and then submits the form, it will be sent to an email address assigned to the value of that option. I have successfully been able to make this work on just simple form fields like "Name, email, and message". However since I have actually started creating the form and many more form fields it is no longer working. I have worked with a couple of tests, one using print_r($_POST);. After submitting the form it will display all of the form values that was sent, but not mail those results using mail() function. php code is below:
<?php
//Sanatize field inputs
if(isset($_POST['post'])) {
// check reCAPTCHA information
require_once('recaptchalib.php');
$privatekey = "6LcuhsgSAAAAAJ1Xlct4dmqOT2SnlhOuwAEImAXH ";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
// if CAPTCHA is correctly entered!
if ($resp->is_valid) {
$headers = "From: $email\r\n";
$headers = "Reply-To: $email\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers = "subject: Application\r\n";
$headers = "Content-Type: text/html; charset=utf-8\r\n";
$cities = $_POST['cities'];
$lastname = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING);
$firstname = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
$middle = filter_var($_POST['middle'], FILTER_SANITIZE_STRING);
$street = filter_var($_POST['street'], FILTER_SANITIZE_STRING);
$city = filter_var($_POST['city'], FILTER_SANITIZE_STRING);
$state = filter_var($_POST['state'], FILTER_SANITIZE_STRING);
$zip = filter_var($_POST['zip'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
$hphone = filter_var($_POST['hphone'], FILTER_SANITIZE_STRING);
$cphone = filter_var($_POST['cphone'], FILTER_SANITIZE_STRING);
$social = filter_var($_POST['social'], FILTER_SANITIZE_STRING);
$referral = filter_var($_POST['referral'], FILTER_SANITIZE_STRING);
$position = filter_var($_POST['position'], FILTER_SANITIZE_STRING);
$pay = filter_var($_POST['pay'], FILTER_SANITIZE_STRING);
$message = "
New mail from:<br><br>
Name: $firstname $lastname <br>
Email: $email <br>
Message: $position <br >
$pay";
//$to = "testing#website.com";
//Here I provide the email address for cities
$email1 = "testin1g#website.com";
$email2 = "testing2#website.com";
$email3 = "testing3#website.com";
//print_r($_POST);
// Logic for getting the value of drop down and then sending mail.
if ($cities == "NY"){
$sendMail = mail($email1, $message, $headers);
if($sendMail) {
echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
} else {
echo 'An error occured and the mail could not be sent.<br>
Please try again later.';
}
}
elseif ($cities == "NC"){
$sendMail = mail($email2, $message, $headers);
if($sendMail) {
echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
} else {
echo 'An error occured and the mail could not be sent.<br>
Please try again later.';
}
} elseif ($cities == "TX"){
$sendMail = mail($email3, $message, $headers);
if($sendMail) {
echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
} else {
echo 'An error occured and the mail could not be sent.<br>
Please try again later.';
}
} elseif ($cities == "ME"){
$sendMail = mail($email1, $message, $headers);
if($sendMail) {
echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
} else {
echo 'An error occured and the mail could not be sent.<br>
Please try again later.';
}
}
} else {
// handle the CAPTCHA being entered incorrectly
echo 'You Did not enter the CAPTCHA in correctly. Please go back and do so.';
}
}
session_destroy();
?>
As you can see above I have a couple of email addresses listed and then using the if statement I am telling php if the "cities = state" to send to that email address. However this is the part it is getting hung up on. It is going straight to my error message.
And my html form:
<form method="post" action="../sendemail.php">
<table cellpadding="0" cellspacing="0" width="900">
<tr>
<td width="800" bgcolor="White">
<div id="copyContainerwide">
<h1>NexxLinx Career Opportunities</h1>
<p>
Thank you for your interest in a career with NexxLinx! We have many different opportunities for employment, which may vary depending
upon which center you are interested in applying for. For more information on what positions we have available, please contact your local
NexxLinx centers, or visit us in person! </p>
<br/>
<p>To apply please select the center you would like to apply to:</p>
<select name="cities">
<option value="NY">Newburgh, NY</option>
<option value="NC">Jacksonville, NC</option>
<option value="TX" >Austin, TX</option>
<option value="ME">Orono, ME</option>
<option value="UT">South Jordan, UT</option>
</select>
<br/>
<p> TO THE APPLICANT: You must fully complete this application for it to be considered. Applications are active for ninety (90) days;
thereafter, you must personally renew the application to be considered for employment. We provide equal opportunities to all applicants
and employees without regard to race, color, religion, sex, national origin, age, or disability, in accordance with applicable federal
and state laws. Accommodation is available to applicants with a disabling condition, when applying, testing, or interviewing for a position.
Please contact the Human Resource Department to request accommodation.</p>
<fieldset>
<legend>General Information </legend>
<table>
<tr>
<td>Last Name:<br/>
<input name="lastname" type="text" size="30" /></td>
<td> First Name:<br/>
<input name="firstname" type="text" size="30"/></td>
<td> Middle Name:<br/>
<input name="middle" type="text" size="30"/></td>
</tr>
</table>
<table>
<tr>
<td>Street Address<br/>
<input name="street" type="text" size="50" /></td>
<td> City<br/>
<input name="city" type="text" size="30" /></td>
<td>State (abbr.)<br/>
<input name="state" type="text" size="7" /></td>
<td> Zip Code <br/>
<input name="zip" type="text" size="12" /></td>
</tr>
</table>
<table>
<tr>
<td>E-mail:<br/>
<input name="email" type="email" size="50" /></td>
<td>Home Phone:<br/>
<input name="hphone" type="tel" size="15" /></td>
<td>Cell Phone:<br/>
<input name="cphone" type="tel" size="15" /></td>
<td>Social Security Number<br/>
<input name="social" type="text" size="12" /></td>
</tr>
</table>
<table>
<tr>
<td>Referred By:</td>
<td><input name="agency" type="checkbox" />Agency</td>
<td><input name="advert" type="checkbox" />Advertisement</td>
<td><input name="employee" type="checkbox" />Empoloyee</td>
<td><input name="other" type="checkbox" />Other</td>
</tr>
<table>
<tr>
<td>Please list the name of the above agency, publication with the advertisement, employee, or other referall.<br/>
<input name="referral" type="text" size="60" /></td>
</tr>
</table>
<table>
<tr>
<td>Position Applied For:<br/>
<input name="position" type="text" size="50"/></td>
<td>Pay Desired:<br/>
$<input name="pay" type="text" size="20" /></td>
</tr>
<tr>
<td>
<?php
require_once('../recaptchalib.php');
$publickey = "6LcuhsgSAAAAAHtXF5i5f5XEAZmjyAtYvHGGQlhf ";
echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<tr>
<td>
<input type="submit" name="post" value="submit" />
</table>
</fieldset>
</div>
</td>
</tr>
</table>
</form>
Thanks for any advice you can give me!
UPDATE:
Finally have this working! Thank you everyone for the help. For what ever reason and please correct if this is not right, I moved my headers up at the top of all of my other variables and it now works like a charm. FYI: I was working on this locally with WAMP and had a dumby sendmail configured to send through my gmail account. It work with very simple forms but apparently this one was a little too advanced, so I finally uploaded and finished testing it on my live server.
Something extra that maybe someone can help me with is validating a social security number and show the * when someone inters in numbers. Can that be done with javascript?
why not assign the email address to the value of the area if you can always reverse if your going to insert it in the database it like
<select name="cities">
<option value="test1#yahoo.com">Newburgh, NY</option>
<option value="test2#yahoo.com">Jacksonville, NC</option>
<option value="test3#yahoo.com" >Austin, TX</option>
</select>
$to=$_POST['cities'];
mail('$to', '$subject', '$message);
if you need to insert the location in database just reverse it
if($citiies==test1#yahoo.com)
{
//insert into database NY
}
this code is shorter and looks cleaner but you will need to if else it again if your going to store the
location in the database
it will be shorter because you will not compare values just send it to what the value assign is
I'm new to Javascript and attempting form validation.
I don't know what i'm doing wrong here any tips ?
<HTML>
<HEAD>
<TITLE>Comment Form</TITLE>
<script type ="text/javascript">
function Validate() {
}
Message = ""
Message = Message + CheckName()
Message = Message + CheckEmail()
Message = Message + CheckComments()
if (Message =="") {
return true
}
else {
alert(Message)
return false
}
}
funtion CheckName()
UserName = document.f1.Name.value
if(UserName =="") {
Message ="Please enter your name"
}
else
Message=""
}
return Message
}
//Checking E-mail:
function CheckEmail() {
email = document.f1.Email.value
AtPos = email.indexOf("#")
StopPos = email.lastIndexOf(".")
Message = ""
if (email == "") {
Message = "Not a valid Email address" + "\n"
}
//if blank:
if (AtPos == -1 || StopPos == -1) {
Message = "Not a valid email address"
}
//if no # and no .
if (StopPos < AtPos) {
Message = "Not a valid email address"
}
//if . before #
if (StopPos - AtPos == 1) {
Message = "Not a valid email address"
}
return Message
}
Is there perhaps something missing from the section below the end script ?
Do I need to put something "" in the action field ? It is asking me to put more text only what am I meant to put here just to fill in space ? Are there alternative ways to achieving what i'm trying to do here ? Is this a dated method ?
</script>
</HEAD>
<BODY BGCOLOR = White>
<form name="f1" method="post" action="" onSubmit="return Validate()" enctype = text/plain>
<table width="672" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="142" valign="top" rowspan="4"> </td>
<td valign="top" height="45" colspan="4" align="center"> <b>Name:</b>
<input type="text" name="Name" size="30">
</td>
</tr>
<tr>
<td height="40" valign="top" colspan="4" align="center"><b>Email:
<input type="text" name="Email" size="30">
<td height="151" valign="top" colspan="4" align="center">
<textarea name="Comments" cols="40" rows="7">Add Your Comments here</textarea>
</td>
</tr>
</form>
</BODY>
</HTML>
Well first of all you immediately close your validate function
function Validate() {
}
So calling
OnSubmit=Validate()
will do absolutely nothing.
Start with removing the closing } and make sure that your Validate function actually contains the validation logic.
Please use the following link
Form Validation
and surly you can get your answer with description which thing is use for what ?
I have a contact form which is a template for pages on wordpress that I use if I need a contact form. All works fine but I want to add the capability of adding a file attachment so when the user fills in their name etc they can upload a photo and that photo will be sent to be me as an attachment.
I have a perfect working contact form and I only want to add that functionality to it. All my current code does all this it sends the name of the person their email address and their message to my email, all I'm missing is the attachment feature. I've been looking at alot of contact forms with this feature but to integrate that feature to my sendmail.php seems very hard as the coding style is completely different. Here is a demo of this in action. demo
This is my php file that has the form in it.
<?php get_header(); ?>
<script type="text/javascript">
$(document).ready(function(){
$('#contact').ajaxForm(function(data) {
if (data==1){
$('#success').fadeIn("slow");
$('#bademail').fadeOut("slow");
$('#badserver').fadeOut("slow");
$('#contact').resetForm();
}
else if (data==2){
$('#badserver').fadeIn("slow");
}
else if (data==3)
{
$('#bademail').fadeIn("slow");
}
});
});
</script>
<!-- begin colLeft -->
<div id="colLeft">
<!-- Begin .postBox -->
<div class="postBox">
<div class="postBoxTop"></div>
<div class="postBoxMid">
<div class="postBoxMidInner first clearfix">
<h1>Contact Us</h1>
<p><?php echo get_option('alltuts_contact_text')?></p>
<p id="success" class="successmsg" style="display:none;">Your email has been sent! Thank you!</p>
<p id="bademail" class="errormsg" style="display:none;">Please enter your name, a message and a valid email address.</p>
<p id="badserver" class="errormsg" style="display:none;">Your email failed. Try again later.</p>
<form id="contact" action="<?php bloginfo('template_url'); ?>/sendmail.php" method="post">
<label for="name">Your name: *</label>
<input type="text" id="nameinput" name="name" value=""/>
<label for="email">Your email: *</label>
<input type="text" id="emailinput" name="email" value=""/>
<label for="comment">Your message: *</label>
<textarea cols="20" rows="7" id="commentinput" name="comment"></textarea><br />
<input type="submit" id="submitinput" name="submit" class="submit" value="SEND MESSAGE"/>
<input type="hidden" id="receiver" name="receiver" value="<?php echo strhex(get_option('alltuts_contact_email'))?>"/>
</form>
</div>
</div>
<div class="postBoxBottom"></div>
</div>
<!-- End .postBox -->
</div>
<!-- end colleft -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
and here is the file that handles the sending of the mail.
<?php
if(isset($_POST['submit'])) {
error_reporting(E_NOTICE);
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*#([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)
{
$to = preg_replace("([\r\n])", "", hexstr($_POST['receiver']));
$from = preg_replace("([\r\n])", "", $_POST['email']);
$subject = "Website contact message from ".$_POST['name'];
$message = $_POST['comment'];
$match = "/(bcc:|cc:|content\-type:)/i";
if (preg_match($match, $to) ||
preg_match($match, $from) ||
preg_match($match, $message)) {
die("Header injection detected.");
}
$headers = "From: ".$from."\r\n";
$headers .= "Reply-to: ".$from."\r\n";
if(mail($to, $subject, $message, $headers))
{
echo 1; //SUCCESS
}
else {
echo 2; //FAILURE - server failure
}
}
else {
echo 3; //FAILURE - not valid email
}
}else{
die("Direct access not allowed!");
}
function hexstr($hexstr) {
$hexstr = str_replace(' ', '', $hexstr);
$hexstr = str_replace('\x', '', $hexstr);
$retstr = pack('H*', $hexstr);
return $retstr;
}
?>
Thanks!
You can read this simple tutorial to know what needs to be done to add file upload support to your current form:
http://www.tizag.com/phpT/fileupload.php
Hope it helps!
EDITED
After the upload process, you can do like this:
if (file_exists($_FILES['uploaded']['tmp_name'])) {
$mail->AddAttachment($_FILES['uploaded']['tmp_name'], $_FILES['uploaded']['name']);
}
What this does is to add an attachment to your email by calling the AddAttachment from PHPMailer, and using the file just uploaded from the TMP folder of your server... so no actual storage of the file is necessary.
You can use
http://wordpress.org/plugins/contact-form-7/
It has a option for Upload field as well as all validations, really easy to use.
You just need to enter shortcode and you can use the contact form anywhere you want.