I have a small question: I created a dynamic search bar until now it's ok. But the problem I have is that when I type the beginning of a letter or a number, I don't have a display limit it takes all the page someone already have a solution?
Thanks a lot
Here is the jQuery code:
$(document).ready(function () {
$('#search-stock').keyup(function (){
$('#result-search').html('');
var stock = $(this).val();
if (stock != "") {
$.ajax({
type: 'GET',
url: '../ajax/stock_search.php',
data: 'stocks=' + encodeURIComponent(stock),
success: function (data) {
if (data != "")
{
$('#result-search').append(data);
} else {
document.getElementById('result-search').innerHTML = "" + "<div style='font-size: 20px; text-align: center; margin-top: 10px'> Aucun élement trouver</div>"
}
}
});
}
});
});
Here is the php
<?php
session_start();
include('../include/bdd.php');
if(isset($_GET['stocks'])){
$stock_aema = (string) trim($_GET['stocks']);
$req = $bdd->prepare("SELECT * FROM stock_aema WHERE model LIKE :model LIMIT 10");
$req2 = $bdd->prepare("SELECT * FROM stock_aema WHERE id LIKE :id LIMIT 10");
$req3 = $bdd->prepare("SELECT * FROM stock_aema WHERE aema LIKE :aema LIMIT 10");
$req->execute(array('model' => "%$stock_aema%"));
$req = $req->fetchAll();
foreach ($req as $r){
?>
<div style="margin-top: 20px ; border-bottom: 2px solid #ccc">
<?= $r['id'] . " " . $r['model']. " " . $r['aema']?>
</div>
<?php
}
$req2->execute(array('id' => "%$stock_aema%"));
$req2 = $req2->fetchAll();
foreach ($req2 as $s){
?>
<div style="margin-top: 20px ; border-bottom: 2px solid #ccc">
<?= $s['id'] . " " . $s['model']. " " . $s['aema']?>
</div>
<?php
}
$req3->execute(array('aema' => strval("%$stock_aema%")));
$req3 = $req3->fetchAll();
foreach ($req3 as $x){
?>
<div style="margin-top: 20px ; border-bottom: 2px solid #ccc">
<?= $x['id'] . " " . $x['model']. " " . $x['aema']?>
</div>
<?php
}
}
?>
I am generating dynamic id's based on the results from MySQL and this is working ok. However, I need to get value of id and whatever i try, it either comes back undefined or blank. I would appreciate any help if someone could point out my error. Thanks
<?php
while ($inboxrow = mysqli_fetch_assoc($inboxresult)) {
$id = $inboxrow["id_frm"];
$message = $inboxrow["message_frm"];
$date = $inboxrow["date_frm"];
$date = strtotime( $date );
$date = date( 'd/m/Y H:i:s', $date );
$from = $inboxrow["from_frm"];
$subject = $inboxrow["subject_frm"];
echo '<div class="msgHdr" style="font-size: 13px; margin-right: 20px; margin-bottom: 10px; padding: 7px; border: 1px solid #ccc; height: auto; background: #fcfaf7">';
echo '<span style="font-weight: bold;">' . $from . '</span>';
echo '<br />';
echo "<a class='dynid' href='#' id='" .$id. "'>" .$subject. "</a>" . '<span style="float: right; font-size: 12px;">' .$date. '</span>';
echo '</div>';
?>
js
$(function() {
$(document).on('click', '.msgHdr', function() {
//console.log(id);
var anc = $(".dynid").find("#id").text();
console.log(anc);
});
});
Looking at your code you need
$(document).on('click', '.msgHdr', function() {
var $link = $(this).find(".dynid");
var subject = $link.text();
var id = $link.attr("id");
});
You should probably do something like:
$(function() {
$( ".msgHdr" ).click(function() {
var anc = $(this).find(".dynid").text();
console.log(anc);
});
});
I have developped this class and include inside my page but the return is always false. It seems the value $_POST of the recaptcha is not inserted process page.
Can you look ?
Thank
my class:
namespace Sites\Shop;
use Core\Registry;
use Core\HTML;
class GoogleRecaptcha {
const API = 'https://www.google.com/recaptcha/';
const SECRET_KEY = MODULES_CONTACT_US_GOOGLE_RECAPTCHA_SECRET_KEY;
const SITE_KEY = MODULES_CONTACT_US_GOOGLE_RECAPTCHA_SITE_KEY;
public function script() {
$Template = Registry::get('Template');
$footer ='<!-- contact_us google captcha end -->' . "\n";
$footer .= '<script src="' . self::API . 'api.js" async defer></script>' . "\n";
$footer .='<!-- contact_us google captcha end -->' . "\n";
return Template->addBlock($footer, 'footer_scripts');;
}
public function html($includeNoScript = false) {
$return = '<div class="g-recaptcha" data-sitekey="' . self::SITE_KEY . '"></div>';
if($includeNoScript == true) {
$return .= $this->noScript();
}
). "\n";
return $return;
}
private function noScript() {
$output = '<noscript>';
$output .= '<div style="width: 302px; height: 352px;">';
$output .='<div style="width: 302px; height: 352px; position: relative;">';
$output .= '<div style="width: 302px; height: 352px; position: absolute;">';
$output .= '<iframe src="' . self::API . 'api/fallback?k=' . self::SITE_KEY . '" frameborder="0" scrolling="no" style="width: 302px; height:352px; border-style: none;"></iframe>';
$output .= '</div>';
$output .= '<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;">';
$output .= HTML::textAreaField('g-recaptcha-response','', '250px', '80px', 'id="g-recaptcha-response" class="g-recaptcha-response" style="border: 1px solid #c1c1c1; margin: 0px; padding: 0px; resize: none;"');
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$output .= '</noscript>';
return $output;
}
public function check($response) {
$url = self::API . 'api/siteverify?secret=' . self::SECRET_KEY . '&response=' . $response . '&remoteip=' . $_SERVER['REMOTE_ADDR'];
$response = file_get_contents($url);
if($response->success===true) {
return true;
} else {
return false;
}
}
public function display() {
$output = '<!-- contact_us secret google captcha start -->'. "\n";
$output .= $this->script();
$output .= $this->html(true);
return $output;
}
}
my html page (simplified)
<?php
$GoogleRecaptcha = Registry::get('GoogleRecaptcha');
$contact_us_form .= $form;
$contact_us_form .= $OSCOM_GoogleRecaptcha->display();
$contact_us_form .= HTML::button(IMAGE_BUTTON_CONTINUE, null, null, 'primary', null, null, null, 'submit');
$contact_us_form .= $endform;
?>
result of my htmlpage
<form name="contact" action="http://boutique/index.php?Info&Contact&Process&action=process" method="post" id="contact"><input type="hidden" name="formid" value="a1e5d99fc7361f2c4ed4169a2ff6ae8b" />
<!-- contact_us secret google captcha start -->
<div class="g-recaptcha" data-sitekey=".................."></div>
<button id=submit type="submit" class="btn btn-primary">Continuer</button>
</form>
<!-- contact_us google captcha end -->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<!-- contact_us google captcha end -->
<!-- contact_us_form end -->
my process (simplified)
if (isset($_GET['action']) && ($_GET['action'] == 'process') && isset($_POST['formid']) && ($_POST['formid'] == $_SESSION['sessiontoken'])) {
$error = false;
$google_captcha = HTML::sanitize($_POST['g-recaptcha-response']);
var_dump($google_captcha);
var_dump($OSCOM_GoogleRecaptcha->check($google_captcha));
exit;
}
result of var_dump : string(0) "" bool(false)
This will return false in every case:
$response = file_get_contents($url);
if($response->success===true) {
return true;
} else {
return false;
}
You need to parse the Json Response from the Recaptcha API:
$response = file_get_contents($url);
$response = json_decode($response , true);
//reCaptcha success check
if($response ['success']){
return true;
} else {
return false;
}
http://php.net/manual/de/function.json-decode.php
I have an online application That is working but I am getting some double database entries. Not every submission creates a double entry but many are. If anyone sees the reason in my code and can tell me It would be appreciated:
<?php
#$upload_Name = $_FILES['Resume']['name'];
#$upload_Size = $_FILES['Resume']['size'];
#$upload_Temp = $_FILES['Resume']['tmp_name'];
#$upload_Mime_Type = $_FILES['Resume']['type'];
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
// Validation
// check only if file
if( $upload_Size > 0)
{
if( $upload_Size == 0)
{
header("Location: error.html");
}
if( $upload_Size >200000)
{
//delete file
unlink($upload_Temp);
header("Location: error.html");
}
if( $upload_Mime_Type != "application/msword" AND $upload_Mime_Type != "application/pdf" AND $upload_Mime_Type != "application/vnd.openxmlformats- officedocument.wordprocessingml.document")
{
unlink($upload_Temp);
header("Location: error.html");
}
}//end wrapper of no file
// Where the file is going to be placed
$target_path = “../../XXXX/uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['Resume']['name']);
if(move_uploaded_file($_FILES['Resume']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['Resume']['name']).
" has been uploaded";
} else{
echo "";
}
?><?php
if(isset($_POST['email'])) {
require_once 'Mail.php'; // PEAR Mail package
require_once 'Mail/mime.php';
$email_to = “name#yoursite.com”; //Enter the email you want to send the form to
$email_subject = "Employment Application"; // You can put whatever subject here
$host = "mail.yourdomain.com"; // The name of your mail server. (Commonly mail.yourdomain.com if your mail is hosted with xxx)
$username = "yoursite.com"; // A valid email address you have setup
$from_address = "name#yoursite.com"; // If your mail is hosted with Site this has to match the email address above
$password = “XXX”; // Password for the above email address
$reply_to = “XXX#yoursite.com"; //Enter the email you want customers to reply to
$port = "50"; // This is the default port. Try port 50 if this port gives you issues and your mail is hosted with Site
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// Validate expected data exists
if(!isset($_POST['Position_Applying']) || !isset($_POST['Position_type']) || !isset($_POST['First_name']) || !isset($_POST['Last_name']) || !isset($_POST['Street']) || !isset($_POST['City']) || !isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$hdw_id = $_POST['hdw_id'];
$hdw_Country = $_POST['hdw_Country'];
$hdw_IP = $_POST['hdw_IP'];
$hdw_Referer = $_POST['hdw_Referer'];
$hdw_ServerTime = $_POST['hdw_ServerTime'];
$hdw_Browser = $_POST['hdw_Browser'];
$hdw_UserAgent = $_POST['hdw_UserAgent'];
$Position_Applying = $_POST['Position_Applying'];
$Position_one = $_POST['Position_one'];
$Position_two = $_POST['Position_two'];
$Position_three = $_POST['Position_three'];
$Position_type = $_POST['Position_type'];
$Shift_type = $_POST['Shift_type'];
$First_name =$_POST['First_name'];
$Middle_name = $_POST['Middle_name'];
$Last_name = $_POST['Last_name'];
$Street = $_POST['Street'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$One_Phone = $_POST['One_Phone'];
$crlf = "n";
// required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid. <br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$First_name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Employment Application Details Below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Position Applying: ".clean_string($Position_Applying)."\n";
$email_message .= "Position Type: ".clean_string($Position_type)."\n";
$email_message .= "\n";
$email_message .= "First name: ".clean_string($First_name)."\n";
$email_message .= "Last Name: ".clean_string($Last_name)."\n";
$email_message .= "\n";
$email_message .= "Street: ".clean_string($Street)."\n";
$email_message .= "City: ".clean_string($City)."\n";
$email_message .= "State: ".clean_string($State)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "Phone: ".clean_string($One_Phone)."\n";
$email_message .= "\n";
$email_message .= "Referred By: ".clean_string($Referred_by )."\n";
$email_message .= "Older than 18: ".clean_string($eighteen )."\n";
$email_message .= "US Citizen: ".clean_string($US_citizen)."\n";
$email_message .= "Crime Conviction: ".clean_string($Crime_convict)."\n";
$email_message .= "NYS Professional License: ".clean_string($NYS_professional_lic)."\n";
$email_message .= "Other License: ".clean_string($Other_professional_lic)."\n";
$email_message .= "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($Resume,'application/pdf');
// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password);
$headers = array('From' => $from_address, 'To' => $email_to, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email_to, $headers, $email_message);
// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password);
$headers = array('From' => $from_address, 'To' => $email, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email, $headers, $email_message);
if (PEAR::isError($mail)) {?>
<!-- include your own failure message html here -->
Unfortunately, the message could not be sent at this time. Please try again later.
<!-- Uncomment the line below to see errors with sending the message -->
<!-- <?php echo("<p>". $mail->getMessage()."</p>"); ?> -->
<?php } else { ?>
<!-- include your own success message html here -->
<?php } } ?>
<style type="text/css">
<!--
.style2 {font-size: 14px}
.style3 { font-size: 14px;
font-family: Verdana;
}
-->
</style>
<link href=“XXXDatabaseB/js.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(XXXDatabaseB/images/green100px.jpg);
background-color: #FFF09F;
}
.style4 {color: #A20246}
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
font-weight: bold;
padding: 10px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
text-decoration: underline;
color: #FFF09F;
}
a:active {
text-decoration: none;
color: #FFFFFF;
}
.style5 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: small;
color: #FFFFFF;
}
.style6 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (xxx_square_slice.psd) -->
<table width="830" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" id="Table_01">
<tr valign="top">
<td height="258" colspan="2"><?php include 'header.php'; ?></td>
</tr>
<tr>
<td width="100%" valign="top">
<?php
$host = “xxxxx.net";
$username = “xxxxx”;
$password = “xxxxx”;
$dbname = “xxxxxx”;
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");
$hdw_id = $_POST['hdw_id'];
$hdw_Country = $_POST['hdw_Country'];
$hdw_IP = $_POST['hdw_IP'];
$hdw_Referer = $_POST['hdw_Referer'];
$hdw_Browser = $_POST['hdw_Browser'];
$hdw_UserAgent = $_POST['hdw_UserAgent'];
$Position_Applying = $_POST['Position_Applying'];
$Position_one = $_POST['Position_one'];
$Position_two = $_POST['Position_two'];
$Position_three = $_POST['Position_three'];
$Position_type = $_POST['Position_type'];
$Shift_type = $_POST['Shift_type'];
$First_name =$_POST['First_name'];
$sql = "INSERT INTO `new_app`(`hdw_id`, `hdw_Country`, `hdw_IP`, `hdw_Referer`, `hdw_ServerTime`, `hdw_Browser`, `hdw_UserAgent`, `Position_Applying`, `Position_one`, `Position_two`, `Position_three`, `Position_type`, `Shift_type`, `First_name`)
VALUES ('$hdw_id', '$hdw_Country', '$hdw_IP', '$hdw_Referer', CURRENT_TIMESTAMP, '$hdw_Browser', '$hdw_UserAgent', '$Position_Applying', '$Position_one', '$Position_two', '$Position_three', '$Position_type', '$Shift_type', '$First_name')";
$result=mysql_query($sql);
if($result){
echo "";
}
else {
echo "ERROR";
}
mysql_close();
?>
<table width="100%" height="508" border="0" align="left" cellpadding="20" cellspacing="5">
<tbody>
<tr>
<td colspan="2" valign="middle">
<h2>Thank you for your Application!</h2>
</p>
</td></tr></tbody></table></td>
</tr>
<tr>
<td colspan="2" valign="top"><?php include 'footer.php'; ?></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>
The code looks ok to me the insert is not executed twice and is no where near a loop of any kind. So it makes me wonder that maybe its user error. I would look at how the file upload section seems to allow the rest of the code to run even if it fails. If it fails the user will change something with the file and resubmit. This happens because you need to exit; after your headers.
I also like to end my insert statements with a LIMIT 1 just because it is limited to one - but I doubt that the problem.
I have made the changes I suggested in the code below:
<?php
#$upload_Name = $_FILES['Resume']['name'];
#$upload_Size = $_FILES['Resume']['size'];
#$upload_Temp = $_FILES['Resume']['tmp_name'];
#$upload_Mime_Type = $_FILES['Resume']['type'];
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
// Validation
// check only if file
if( $upload_Size > 0)
{
if( $upload_Size == 0)
{
header("Location: error.html");
exit;
}
if( $upload_Size >200000)
{
//delete file
unlink($upload_Temp);
header("Location: error.html");
exit;
}
if( $upload_Mime_Type != "application/msword" AND $upload_Mime_Type != "application/pdf" AND $upload_Mime_Type != "application/vnd.openxmlformats- officedocument.wordprocessingml.document")
{
unlink($upload_Temp);
header("Location: error.html");
exit;
}
}//end wrapper of no file
// Where the file is going to be placed
$target_path = “../../XXXX/uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['Resume']['name']);
if(move_uploaded_file($_FILES['Resume']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['Resume']['name']).
" has been uploaded";
} else{
echo "";
}
?><?php
if(isset($_POST['email'])) {
require_once 'Mail.php'; // PEAR Mail package
require_once 'Mail/mime.php';
$email_to = “name#yoursite.com”; //Enter the email you want to send the form to
$email_subject = "Employment Application"; // You can put whatever subject here
$host = "mail.yourdomain.com"; // The name of your mail server. (Commonly mail.yourdomain.com if your mail is hosted with xxx)
$username = "yoursite.com"; // A valid email address you have setup
$from_address = "name#yoursite.com"; // If your mail is hosted with Site this has to match the email address above
$password = “XXX”; // Password for the above email address
$reply_to = “XXX#yoursite.com"; //Enter the email you want customers to reply to
$port = "50"; // This is the default port. Try port 50 if this port gives you issues and your mail is hosted with Site
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// Validate expected data exists
if(!isset($_POST['Position_Applying']) || !isset($_POST['Position_type']) || !isset($_POST['First_name']) || !isset($_POST['Last_name']) || !isset($_POST['Street']) || !isset($_POST['City']) || !isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$hdw_id = $_POST['hdw_id'];
$hdw_Country = $_POST['hdw_Country'];
$hdw_IP = $_POST['hdw_IP'];
$hdw_Referer = $_POST['hdw_Referer'];
$hdw_ServerTime = $_POST['hdw_ServerTime'];
$hdw_Browser = $_POST['hdw_Browser'];
$hdw_UserAgent = $_POST['hdw_UserAgent'];
$Position_Applying = $_POST['Position_Applying'];
$Position_one = $_POST['Position_one'];
$Position_two = $_POST['Position_two'];
$Position_three = $_POST['Position_three'];
$Position_type = $_POST['Position_type'];
$Shift_type = $_POST['Shift_type'];
$First_name =$_POST['First_name'];
$Middle_name = $_POST['Middle_name'];
$Last_name = $_POST['Last_name'];
$Street = $_POST['Street'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$One_Phone = $_POST['One_Phone'];
$crlf = "n";
// required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid. <br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$First_name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Employment Application Details Below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Position Applying: ".clean_string($Position_Applying)."\n";
$email_message .= "Position Type: ".clean_string($Position_type)."\n";
$email_message .= "\n";
$email_message .= "First name: ".clean_string($First_name)."\n";
$email_message .= "Last Name: ".clean_string($Last_name)."\n";
$email_message .= "\n";
$email_message .= "Street: ".clean_string($Street)."\n";
$email_message .= "City: ".clean_string($City)."\n";
$email_message .= "State: ".clean_string($State)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "Phone: ".clean_string($One_Phone)."\n";
$email_message .= "\n";
$email_message .= "Referred By: ".clean_string($Referred_by )."\n";
$email_message .= "Older than 18: ".clean_string($eighteen )."\n";
$email_message .= "US Citizen: ".clean_string($US_citizen)."\n";
$email_message .= "Crime Conviction: ".clean_string($Crime_convict)."\n";
$email_message .= "NYS Professional License: ".clean_string($NYS_professional_lic)."\n";
$email_message .= "Other License: ".clean_string($Other_professional_lic)."\n";
$email_message .= "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($Resume,'application/pdf');
// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password);
$headers = array('From' => $from_address, 'To' => $email_to, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email_to, $headers, $email_message);
// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password);
$headers = array('From' => $from_address, 'To' => $email, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email, $headers, $email_message);
if (PEAR::isError($mail)) {?>
<!-- include your own failure message html here -->
Unfortunately, the message could not be sent at this time. Please try again later.
<!-- Uncomment the line below to see errors with sending the message -->
<!-- <?php echo("<p>". $mail->getMessage()."</p>"); ?> -->
<?php } else { ?>
<!-- include your own success message html here -->
<?php } } ?>
<style type="text/css">
<!--
.style2 {font-size: 14px}
.style3 { font-size: 14px;
font-family: Verdana;
}
-->
</style>
<link href=“XXXDatabaseB/js.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(XXXDatabaseB/images/green100px.jpg);
background-color: #FFF09F;
}
.style4 {color: #A20246}
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
font-weight: bold;
padding: 10px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
text-decoration: underline;
color: #FFF09F;
}
a:active {
text-decoration: none;
color: #FFFFFF;
}
.style5 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: small;
color: #FFFFFF;
}
.style6 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (xxx_square_slice.psd) -->
<table width="830" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" id="Table_01">
<tr valign="top">
<td height="258" colspan="2"><?php include 'header.php'; ?></td>
</tr>
<tr>
<td width="100%" valign="top">
<?php
$host = “xxxxx.net";
$username = “xxxxx”;
$password = “xxxxx”;
$dbname = “xxxxxx”;
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");
$hdw_id = $_POST['hdw_id'];
$hdw_Country = $_POST['hdw_Country'];
$hdw_IP = $_POST['hdw_IP'];
$hdw_Referer = $_POST['hdw_Referer'];
$hdw_Browser = $_POST['hdw_Browser'];
$hdw_UserAgent = $_POST['hdw_UserAgent'];
$Position_Applying = $_POST['Position_Applying'];
$Position_one = $_POST['Position_one'];
$Position_two = $_POST['Position_two'];
$Position_three = $_POST['Position_three'];
$Position_type = $_POST['Position_type'];
$Shift_type = $_POST['Shift_type'];
$First_name =$_POST['First_name'];
$sql = "INSERT INTO `new_app`(`hdw_id`, `hdw_Country`, `hdw_IP`, `hdw_Referer`, `hdw_ServerTime`, `hdw_Browser`, `hdw_UserAgent`, `Position_Applying`, `Position_one`, `Position_two`, `Position_three`, `Position_type`, `Shift_type`, `First_name`)
VALUES ('$hdw_id', '$hdw_Country', '$hdw_IP', '$hdw_Referer', CURRENT_TIMESTAMP, '$hdw_Browser', '$hdw_UserAgent', '$Position_Applying', '$Position_one', '$Position_two', '$Position_three', '$Position_type', '$Shift_type', '$First_name') LIMIT 1";
$result=mysql_query($sql);
if($result){
echo "";
}
else {
echo "ERROR";
}
mysql_close();
?>
<table width="100%" height="508" border="0" align="left" cellpadding="20" cellspacing="5">
<tbody>
<tr>
<td colspan="2" valign="middle">
<h2>Thank you for your Application!</h2>
</p>
</td></tr></tbody></table></td>
</tr>
<tr>
<td colspan="2" valign="top"><?php include 'footer.php'; ?></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>
I have a form with a button which opens a javascript/css popup window. On the popup window I have a textarea which will be used to add a comment to a database field. The problem is that I need to pass it a value from the main page (the one that calls the popup) which will identify which entry in the database to update. But I am stuck trying to get it to work. Here is my code. I need to have the variable sent to the update.php page. Please help.
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
if(isset($_GET['sort']) && isset($_GET['col']) ){
$order = $_GET['sort'];
$column = $_GET['col'];
}
else{
$order = 'ASC';
$column = 'cron_id';
}
$page = 'Testing Site';
require_once('includes/head.php');
require_once('includes/mysql.php');
require_once('includes/class.tdcron.php');
require_once('includes/class.tdcron.entry.php');
date_default_timezone_set('America/Los_Angeles');
$result = mysql_query("SELECT * FROM cron WHERE active=1 ORDER BY $column $order") or die (mysql_error());
mysql_close();
$pass = "<img src='images/Checked.png' alt='Pass' width='16' height='16'/>";
$fail = "<img src='images/Stop.png' alt='Failed' width='16' height='16'/>";
$warn = "<img src='images/Warning.png' alt='Warning' width='16' height='16' />";
$com = "<img src='images/pencil.png' alt='Warning' width='16' height='16' />";
echo "<div id='tableContainer' class='tableContainer'>";
echo "<table width='100%' border='0' padding='0' cellpadding='0' cellspacing='0' class='scrollTable'>";
echo "<thead class='fixedHeader'>";
echo "<tr>";
if ($order=="ASC") { echo "<th>Status</th>"; }
else { echo "<th>Status</th>"; }
echo '<th>Schedule</th>';
if ($order=="ASC") { echo "<th>Job</th>"; }
else { echo "<th>Job</th>"; }
echo '<th>Description</th>';
if ($order=="ASC") { echo "<th>Destination</th>"; }
else { echo "<th>Destination</th>"; }
echo '<th>Errors</th>';
if ($order=="ASC") { echo "<th>Job Type</th>"; }
else { echo "<th>Job Type</th>"; }
if ($order=="ASC") { echo "<th>Category</th>"; }
else { echo "<th>Category</th>"; }
if ($order=="ASC") { echo "<th>Last Ran</th>"; }
else { echo "<th>Last Ran</th>"; }
echo '<th>Next Run</th>';
echo '<th>Log</th>';
echo '</tr></thead><tbody class="scrollContent">';
while($row = mysql_fetch_array($result)){
if($row['ok'] == 1){$status = $pass;}
elseif($row['ok'] == 0){$status = $fail;}
else{$status = $warn;}
echo '<tr>';
echo
'<td>
**<form name="frm_comment" action="" onsubmit="return false;" >' . $status . ' ' .
'<input type="image" src="images/pencil.png" onclick="popup_show(\'popup\', \'popup_drag\', \'popup_exit\', \'mouse\', -10, -5);" width=\'16\' height=\'16\' />
</form>**
</td>';
echo '<td>' . $row['schedule'] . '</td>';
echo '<td>' . $row['job'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['destination'] . '</td>';
echo '<td>' . $row['errormsgs'] . '</td>';
echo '<td>' . $row['jobtype'] . '</td>';
echo '<td>' . $row['catagory'] . '</td>';
echo '<td>' . date('D M d # g:i A', $row['ran_at']) . '</td>';
echo '<td>' . date('D M d # g:i A', tdCron::getNextOccurrence($row['mhdmd'])) . '</td>';
echo "<td><a href='log/" . $row['log'] . "' target='_blank' >View Log</a></td>";
echo '</tr>';
}
echo '</tbody>';
echo "</table>";
echo "</div>";
// ***** Popup Window ****************************************************
echo'<div class="sample_popup" id="popup" style="display: none;">
<div class="menu_form_header" id="popup_drag">
<img class="menu_form_exit" id="popup_exit" src="images/form_exit.png" alt="Close Form" /> Comments
</div>
<div class="menu_form_body">
<form name="up" action="update.php" onsubmit="return validateForm()" method="post" >
<input type="hidden" name="' . $row['job'] . '" />
<table>
<tr>
<td><textarea class="field" onfucus="select();" name="comment" rows="8" cols="44"></textarea>
</tr>
<tr>
<td align="right" ><br /><input class="btn" type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
</div>';
require_once('includes/footer.php');
?>
Javascript code start
// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
// Instead, you may link to the homepage of this code:
// http://www.php-development.ru/javascripts/popup-window.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.
// USAGE
//
// function popup_show(id, drag_id, exit_id, position, x, y, position_id)
//
// id - id of a popup window;
// drag_id - id of an element within popup window intended for dragging it
// exit_id - id of an element within popup window intended for hiding it
// position - positioning type:
// "element", "element-right", "element-bottom", "mouse",
// "screen-top-left", "screen-center", "screen-bottom-right"
// x, y - offset
// position_id - id of an element relative to which popup window will be positioned
// ***** Variables *************************************************************
var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;
// ***** popup_mousedown *******************************************************
function popup_mousedown(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
popup_mouseposX = ie ? window.event.clientX : e.clientX;
popup_mouseposY = ie ? window.event.clientY : e.clientY;
}
// ***** popup_mousedown_window ************************************************
function popup_mousedown_window(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
if ( ie && window.event.button != 1) return;
if (!ie && e.button != 0) return;
popup_dragging = true;
popup_target = this['target'];
popup_mouseX = ie ? window.event.clientX : e.clientX;
popup_mouseY = ie ? window.event.clientY : e.clientY;
if (ie)
popup_oldfunction = document.onselectstart;
else popup_oldfunction = document.onmousedown;
if (ie)
document.onselectstart = new Function("return false;");
else document.onmousedown = new Function("return false;");
}
// ***** popup_mousemove *******************************************************
function popup_mousemove(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
var element = document.getElementById(popup_target);
var mouseX = ie ? window.event.clientX : e.clientX;
var mouseY = ie ? window.event.clientY : e.clientY;
if (!popup_dragging) return;
element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
element.style.top = (element.offsetTop +mouseY-popup_mouseY)+'px';
popup_mouseX = ie ? window.event.clientX : e.clientX;
popup_mouseY = ie ? window.event.clientY : e.clientY;
}
// ***** popup_mouseup *********************************************************
function popup_mouseup(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
var element = document.getElementById(popup_target);
if (!popup_dragging) return;
popup_dragging = false;
if (ie)
document.onselectstart = popup_oldfunction;
else document.onmousedown = popup_oldfunction;
}
// ***** popup_exit ************************************************************
function popup_exit(e)
{
var ie = navigator.appName == "Microsoft Internet Explorer";
var element = document.getElementById(popup_target);
popup_mouseup(e);
element.style.display = 'none';
}
// ***** popup_show ************************************************************
function popup_show(id, drag_id, exit_id, position, x, y, position_id)
{
var element = document.getElementById(id);
var drag_element = document.getElementById(drag_id);
var exit_element = document.getElementById(exit_id);
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
element.style.position = "absolute";
element.style.display = "block";
if (position == "element" || position == "element-right" || position == "element-bottom")
{
var position_element = document.getElementById(position_id);
for (var p = position_element; p; p = p.offsetParent)
if (p.style.position != 'absolute')
{
x += p.offsetLeft;
y += p.offsetTop;
}
if (position == "element-right" ) x += position_element.clientWidth;
if (position == "element-bottom") y += position_element.clientHeight;
element.style.left = x+'px';
element.style.top = y+'px';
}
if (position == "mouse")
{
element.style.left = (document.documentElement.scrollLeft+popup_mouseposX+x)+'px';
element.style.top = (document.documentElement.scrollTop +popup_mouseposY+y)+'px';
}
if (position == "screen-top-left")
{
element.style.left = (document.documentElement.scrollLeft+x)+'px';
element.style.top = (document.documentElement.scrollTop +y)+'px';
}
if (position == "screen-center")
{
element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2+x)+'px';
element.style.top = (document.documentElement.scrollTop +(height-element.clientHeight)/2+y)+'px';
}
if (position == "screen-bottom-right")
{
element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth ) +x)+'px';
element.style.top = (document.documentElement.scrollTop +(height-element.clientHeight) +y)+'px';
}
drag_element['target'] = id;
drag_element.onmousedown = popup_mousedown_window;
exit_element.onclick = popup_exit;
}
// ***** Attach Events *********************************************************
if (navigator.appName == "Microsoft Internet Explorer")
document.attachEvent ('onmousedown', popup_mousedown);
else document.addEventListener('mousedown', popup_mousedown, false);
if (navigator.appName == "Microsoft Internet Explorer")
document.attachEvent ('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);
if (navigator.appName == "Microsoft Internet Explorer")
document.attachEvent ('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);
END Javascript CODE
CSS Code Start
div.sample_popup { z-index: 1; }
div.sample_popup div.menu_form_header
{
border: 1px solid black;
border-bottom: none;
width: 400px;
height: 20px;
line-height: 19px;
vertical-align: middle;
background: url('../images/form_header.png') no-repeat;
text-decoration: none;
font-family: Times New Roman, Serif;
font-weight: 900;
font-size: 13px;
color: #FFFFFF; /*#206040;*/
cursor: default;
}
div.sample_popup div.menu_form_body
{
width: 400px;
height: 200px;
border: 1px solid black;
background: url('../images/form.png') no-repeat left bottom;
}
div.sample_popup img.menu_form_exit
{
float: right;
margin: 4px 5px 0px 0px;
cursor: pointer;
}
div.sample_popup table
{
width: 100%;
border-collapse: collapse;
}
div.sample_popup th
{
width: 1%;
padding: 0px 5px 1px 0px;
text-align: left;
font-family: Times New Roman, Serif;
font-weight: 900;
font-size: 13px;
color: #004060;
}
div.sample_popup td
{
width: 99%;
padding: 0px 0px 1px 0px;
}
div.sample_popup form
{
margin: 0px;
padding: 8px 10px 10px 10px;
}
div.sample_popup input.field
{
width: 95%;
border: 1px solid #808080;
font-family: Verdana, Sans-Serif;
font-size: 12px;
}
div.sample_popup input.btn
{
margin-top: 2px;
border: 1px solid #808080;
background-color: #DDFFDD;
font-family: Verdana, Sans-Serif;
font-size: 11px;
}
CSS CODE END
You're using a JS/CSS popup, so just pass $row['job'] in your call to popup_show() (assuming you are able to modify or overload that JS function), and then populate it in the hidden field of your popup HTML with Javascript. The way you're doing it now, you'd have to duplicate the block of Popup HTML once for each row in your resultset for it to work.