PHP code in echo with html - php

I have been struggling to put a content locker to a form in my template and I succeeded but form is fetching some php values so my echo has PHP code in it. Not sure how do I do it.
Can anyone help? I am struggling since 10 hours and couldn't come to a solution.
<?
$locker='[ihc-hide-content ihc_mb_type="block" ihc_mb_who="all" ihc_mb_template="1"]
<form id="contact" type="post" action="" >
<span class="contact-name">
<input type="text" name="contactName" id="contactName" value="" class="input-textarea" placeholder="<?php _e("Name*", "themesdojo"); ?>" />
</span>
<span class="contact-email">
<input type="text" name="email" id="email" value="" class="input-textarea" placeholder="<?php _e("Email*", "themesdojo"); ?>" />
</span>
<span class="contact-message">
<textarea name="message" id="message" cols="8" rows="8" ></textarea>
</span>
<span class="contact-test">
<p style="margin-top: 20px;"><?php _e("Human test. Please input the result of 5+3=?", "themesdojo"); ?></p>
<input type="text" onfocus="if(this.value=='')this.value='';" onblur="if(this.value=='')this.value='';" name="answer" id="humanTest" value="" class="input-textarea" />
</span>
<input type="text" name="receiverEmail" id="receiverEmail" value="<?php echo $wpjobus_job_email; ?>" class="input-textarea" style="display: none;"/>
<input type="hidden" name="action" value="wpjobContactForm" />
<?php wp_nonce_field( 'scf_html', 'scf_nonce' ); ?>
<input style="margin-bottom: 0;" name="submit" type="submit" value="<?php _e( 'Send Message', 'themesdojo' ); ?>" class="input-submit">
<span class="submit-loading"><i class="fa fa-refresh fa-spin"></i></span>
</form>
[/ihc-hide-content]';
echo do_shortcode( $locker );
?>

just concat your php variables
$locker='[ihc-hide-content ihc_mb_type="block" ihc_mb_who="all" ihc_mb_template="1"]
<form id="contact" type="post" action="" >
<span class="contact-name">
<input type="text" name="contactName" id="contactName" value="" class="input-textarea" placeholder="'._e("Name*", "themesdojo").'" />
</span>
<span class="contact-email">
<input type="text" name="email" id="email" value="" class="input-textarea" placeholder="'._e("Email*", "themesdojo").'" />
</span>
<span class="contact-message">
<textarea name="message" id="message" cols="8" rows="8" ></textarea>
</span>
<span class="contact-test">
<p style="margin-top: 20px;">'._e("Human test. Please input the result of 5+3=?", "themesdojo").'</p>
<input type="text" onfocus="if(this.value=="")this.value="";" onblur="if(this.value=="")this.value="";" name="answer" id="humanTest" value="" class="input-textarea" />
</span>
<input type="text" name="receiverEmail" id="receiverEmail" value="'.$wpjobus_job_email.'" class="input-textarea" style="display: none;"/>
<input type="hidden" name="action" value="wpjobContactForm" />
'.wp_nonce_field( 'scf_html', 'scf_nonce' ).'
<input style="margin-bottom: 0;" name="submit" type="submit" value="'._e( 'Send Message', 'themesdojo' ).'" class="input-submit">
<span class="submit-loading"><i class="fa fa-refresh fa-spin"></i></span>
</form> [/ihc-hide-content]';
echo do_shortcode( $locker );

Line 25 contains PHP that is being interpreted as part of the $locker variable.
<?php wp_nonce_field( 'scf_html', 'scf_nonce' ); ?>

Related

i want to store values in two tables but i'm able store in single table

i have two table rooinventory and reservation i want to store values in that tables but its getting inserting in rooinventory table only..
demo.php
<form name="checkoutForm" method="post" action="order.php">
<div class="container" style="float: left; width: 299px; margin-left: 12px;">
<span class="top-label">
<span class="label-txt">Room Details</span>
</span>
<div class="content-area" style="border-radius:15px;">
<div>
</div>
<div class="content drop-here">
<div id="cart-icon">
<img src="img/Shoppingcart_128x128.png" alt="shopping cart" class="pngfix" width="128" height="128" />
<img src="img/ajax_load_2.gif" alt="loading.." id="ajax-loader" width="16" height="16" />
</div>
<input name="start" type="hidden" value="<?php echo $arival; ?>" />
<input name="end" type="hidden" value="<?php echo $departure; ?>" />
<input name="numnights" type="hidden" value=<?php echo $numberofnights; ?>" />
<div>
<div id="item-list">
</div>
<div id="total"></div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<span class="top-label">
<span class="label-txt">Personal Details</span>
</span>
<div class="content-area" style="border-radius:15px; padding-bottom: 25px;">
<div>
Firstname:<br>
<input type="text" name="fname" id="boxy" pattern="[A-Za-z]{1,32}" required="" /><br>
lastname:<br>
<input type="text" name="lname" id="boxy" required="" /><br>
Address:<br>
<input type="text" name="address" id="boxy" pattern="[A-Za-z]{1,32}" required="" /><br>
City:<br>
<input type="text" name="city" id="boxy" required="" /><br>
Country:<br>
<input type="text" name="country" id="boxy" required="" /><br>
Email:<br>
<input type="email" name="email" id="boxy" /><br>
Contact Number:<br>
<input type="text" name="contact" id="boxy" required="" /><br>
<input type="hidden" name="confirmation" id="boxy" value="<?php echo $confirmation ?>" /><br>
<input type="submit" name="check" onclick="document.forms.checkoutForm.submit(); return false;" class="button" value="Checkout" id="boxy" style="width: 147px; margin-top: 18px;">
</div>
</div>
</div>
</form>
order.php
<?php
$confirmation = $_POST['confirmation'];
$numnights=round($_POST['numnights']);
$arival=$_POST['start'];
$departure=$_POST['end'];
$firstname=$_POST['fname'];
$lastname=$_POST['lname'];
$address=$_POST['address'];
$city=$_POST['city'];
$country=$_POST['country'];
$email=$_POST['email'];
$contact=$_POST['contact'];
$stat='active';
$roomid=$_POST['id'];
$qty=$_POST['qty'];
$price=$_POST['price'];
$roomname=$_POST['roomname'];
$N = count($roomid);
$ip_sqlq=mysql_query("select * from rooinventory where confirmation='$confirmation' and arrival='$arival'and departure='$departure'");
$countq=mysql_num_rows($ip_sqlq);
if($countq==0)
{
for($i=0; $i < $N; $i++)
{
mysql_query("INSERT INTO rooinventory (room, qty, arrival, departure, status, confirmation) VALUES ('$roomid[$i]','$qty[$i]','$arival','$departure','$stat','$confirmation')");
echo '<h2>'.$qty[$i].' x '.$roomname[$i].' = '.$ble=$qty[$i]*$price[$i].'</h2>';
echo '<div style="display:none;">';
$dddd=$ble;
$total=$total+$dddd;
echo '</div>';
}
mysql_query("INSERT INTO reservation (firstname, lastname, city, address, country, email, contact, arrival, departure, result, payable, status, confirmation) VALUES ('$firstname','$lastname','$city','$address','$country','$email','$contact','$arival','$departure','$numnights','$total','$stat','$confirmation')");
header("location: paypalpayout.php?confirm=$confirmation");
}
else{
header("location: ../index.php");
}
?>
Could it be the data in one of your variables is causing the second query to fail? Since they're not bound as parameters or at least escaped, they could be altering your actual query. For instance, if there's an apostrophe in any of your data, it's going to break the query.

PHP check if unique

I have this code to enter product in my stoc administration script.
I need some help.
I want when i enter new product to check if row cod (codint in mysql ) is unique and if is not unique alert me.
Like opencat model field ..
<?php
require('header.php');
include('functii/functions.php');
if(isset($_POST[submit]) && !empty($_POST[nume])){
$_POST[nume] = mysql_real_escape_string($_POST[nume]);
$_POST[stoc] = mysql_real_escape_string($_POST[stoc]);
$_POST[pretintrare] = mysql_real_escape_string($_POST[pretintrare]);
$_POST[pretrecomandat] = mysql_real_escape_string($_POST[pretrecomandat]);
$_POST[comentarii] = mysql_real_escape_string($_POST[comentarii]);
$_POST[descriere] = mysql_real_escape_string($_POST[descriere]);
$_POST[locatie] = mysql_real_escape_string($_POST[locatie]);
$_POST[stare] = mysql_real_escape_string($_POST[stare]);
$_POST[tip] = mysql_real_escape_string($_POST[tip]);
$sql = "INSERT INTO stoc (nume, tip, locatie, stoc, pretintrare, pretrecomandat, stare, comentarii, descriere, model1, model2, model3, model4, model5, model6, model7, model8, model9, model10, model11, model12, model13, model14, brand, img, img2, img3, img4, codint) VALUES ('$_POST[nume]', '$_POST[tip]', '$_POST[locatie]', '$_POST[stoc]', '$_POST[pretintrare]', '$_POST[pretrecomandat]', '$_POST[stare]', '$_POST[comentarii]', '$_POST[descriere]', '$_POST[model1]', '$_POST[model2]', '$_POST[model3]', '$_POST[model4]', '$_POST[model5]', '$_POST[model6]', '$_POST[model7]', '$_POST[model8]', '$_POST[model9]', '$_POST[model10]', '$_POST[model11]', '$_POST[model12]', '$_POST[model13]', '$_POST[model14]', '$_POST[brand]', '$_POST[img]', '$_POST[img2]', '$_POST[img3]', '$_POST[img4]', '$_POST[codint]' )";
$result=mysql_query($sql);
$last_id=mysql_insert_id();
die('<script type="text/javascript">window.location.href="stoc-id.php?id='.$last_id.'";</script>');
}
?>
<ul id="nav">
<li class="inactive">Ecrane</li>
<li class="inactive">Tastaturi</li>
<li class="inactive">Incarcatoare</li>
<li class="inactive">HDD</li>
<li class="inactive">Placi de baza</li>
<li class="inactive">RAM</li>
<li class="inactive">Cooler</li>
<li class="inactive">Balamale</li>
<li class="inactive">Laptop</li>
<li class="inactive">Accesorii Laptop</li>
<li class="inactive">Mufe Alimentare</li>
<li class="inactive">Module Electronice</li>
<li class="inactive">Carcasa laptop</li>
<li class="inactive">Dezmembrari</li>
</ul>
<div id="content">
<h1>Adauga un produs pe stoc:</h1>
<form action="stoc-adauga.php" method="post">
<div id="tichetleft">
<p>Nume: <input style="margin-left: 40px;" type="text" name="nume"></p>
<p>Cod: <input style="margin-left: 52px;" type="text" name="codint"></p>
<p>Stoc: <input style="margin-left: 51px;" type="text" name="stoc"/></p>
<p>Pret recom: <input style="margin-left: -1px;" type="text" name="pretintrare"/></p>
</div>
<div id="tichetright">
<p>Locatie:
<input style="margin-left: 33px;" type="radio" id="1" name="locatie" value="0"><label for="1">Crangasi</label>
<input type="radio" name="locatie" id="2" value="1" checked="checked"><label for="2">Dristor</label>
</p>
<p style="margin-top: 27px;">Stare:
<input style="margin-left: 48px;" id="3" type="radio" name="stare" value="0" checked="checked"><label for="3">Nou</label>
<input type="radio" name="stare" id="4" value="1"><label for="4">Second-Hand</label>
</p>
<p style="margin-top: 23px;">Pret Distributie: <input style="margin-left: 13px;width:262px;" type="text" name="pretrecomandat"/></p>
</div>
<div class="clear"></div>
<div id="center">
<p class="stoc">Tip:
<input type="radio" id="5" name="tip" value="ecran" checked="checked"><label for="5">Ecran</label>
<input type="radio" id="6" name="tip" value="tastatura"><label for="6">Tastatura</label>
<input type="radio" id="7" name="tip" value="incarcator"><label for="7">Incarcator</label>
<input type="radio" id="8" name="tip" value="hdd"><label for="8">HDD</label>
<input type="radio" id="9" name="tip" value="placibaza"><label for="9">Placa de baza</label>
<input type="radio" id="10" name="tip" value="ram"><label for="10">RAM</label>
<input type="radio" id="12" name="tip" value="cooler"><label for="12">Cooler</label>
<input type="radio" id="13" name="tip" value="balamale"><label for="13">Balamale</label>
<input type="radio" id="11" name="tip" value="laptop"><label for="11">Laptop</label>
<input type="radio" id="14" name="tip" value="accesoriil"><label for="14">Accesorii Laptop</label>
<input type="radio" id="15" name="tip" value="mufealimentare"><label for="15">Mufe Alimentare</label>
<input type="radio" id="16" name="tip" value="moduleel"><label for="16">Module Electronice</label>
<input type="radio" id="17" name="tip" value="carcasa"><label for="17">Carcasa</label>
<input type="radio" id="18" name="tip" value="dez"><label for="18">Dezmembrari</label>
</p>
<p>Note int: <textarea style="margin-left: 45px;" type="text" name="comentarii"/></textarea></p>
<p>Descriere: <textarea style="margin-left: 45px;" type="text" name="descriere"/></textarea></p>
</div>
<div id="tichetleft">
<p>Model1: <input style="margin-left: 40px;" type="text" name="model1"></p>
<p>Model2: <input style="margin-left: 40px;" type="text" name="model2"></p>
<p>Model3: <input style="margin-left: 40px;" type="text" name="model3"></p>
<p>Model4: <input style="margin-left: 40px;" type="text" name="model4"></p>
<p>Model5: <input style="margin-left: 40px;" type="text" name="model5"></p>
<p>Model5: <input style="margin-left: 40px;" type="text" name="model11"></p>
<p>Model5: <input style="margin-left: 40px;" type="text" name="model12"></p>
<p>Brand: <input style="margin-left: 40px;" type="text" name="brand"></p>
<p>IMG3: <input style="margin-left: 40px;" type="text" name="img3"></p>
</div>
<div id="tichetright">
<p>Model6: <input style="margin-left: 40px;" type="text" name="model6"></p>
<p>Model7: <input style="margin-left: 40px;" type="text" name="model7"></p>
<p>Model8: <input style="margin-left: 40px;" type="text" name="model8"></p>
<p>Model9: <input style="margin-left: 40px;" type="text" name="model9"></p>
<p>Model0: <input style="margin-left: 40px;" type="text" name="model10"></p>
<p>Model0: <input style="margin-left: 40px;" type="text" name="model13"></p>
<p>Model0: <input style="margin-left: 40px;" type="text" name="model14"></p>
<p>IMG: <input style="margin-left: 40px;" type="text" name="img"></p>
<p>IMG2: <input style="margin-left: 40px;" type="text" name="img2"></p>
<p>IMG4: <input style="margin-left: 40px;" type="text" name="img4"></p>
</div>
<div id="center">
<input type="submit" style="padding-left: 25px;" name="submit" value="Adauga produsul"><img style="vertical-align: -10%;margin-left:-160px;" src="imagini/produs-icon.png" alt="Adauga tichet"></input>
</div>
</form>
</div> <!-- end content -->
<?php require('footer.php');?>
To check the record is existing in DB or not,
You first get the count of the specified codint. For that code like below given.
$checkStmt=mysqli_prepare($con, "SELECT COUNT(*) FROM stoc WHERE codint<>?");
if( $checkStmt ) {
$codint = mysqli_real_escape_string($con, $_POST[codint]);
mysqli_stmt_bind_param($checkStmt,"d",$codint);
mysqli_stmt_execute($checkStmt);
mysqli_stmt_bind_result($checkStmt,$txt_RecordCount);
mysqli_stmt_fetch($checkStmt);
mysqli_stmt_close($checkStmt);
$knownRecordCount=$txt_RecordCount;
}
if($txt_RecordCount>0){
// record id existing
}else{
// not existing. It is a fresh recored
}
Please understand and implement in your code. This will work. This is perfectly works in my case.

Passing, Assigning and Displaying PHP variables

I tried to search through past questions, but I'm not sure how to phrase my question to get the answer I need.
I know basis HTML / CSS and I'm trying to learn PHP.
I have a WordPress membership site where I would like to pass a variable from one plugin and display it in another.
Take a look at https://ridesharedriversclub.com/generate-qr-code/
The QR Code form type defaults to "Business Card". I have been trying to make it to default to "URL".
I have also been trying to get the "referral URL" that displays above the form to display in the "URL" input field on the form where it currently shows "https://".
Here is the code that displays the URL above the form:
<p><?php printf( __( 'Your referral URL is: <strong>%s</strong>', 'affiliate-wp' ), esc_url( urldecode( affwp_get_affiliate_referral_url() ) ) ); ?></p>
Here is code for the form below the URL:
<?php
defined('SQR_PATH') or die();
/* Form for 'In Content' generator */
function getQRForm(){
$fields = wpsqr_get_fields();
$f1 = $fields[0];
$f2 = $fields[1];
$display_dl = wpsqr_get_dl_bool();
$f = '
<div id="incontentqrgen">
<div id="wpqr_gen">
<div class="wpsqr_field">'.$f1.'</div>
<form name="qrin_form" id="qrin_form" method="post" action="">
<input type="hidden" id="wpsqr_url" value="'.SQR_URL.'js/" />
<div id="qrselect">
Type:
<select id="qrtype" name="qrtype">
<option value="buscardqr">Business Card</option>
<option value="urlqr">URL</option>
<option value="messageqr">Message</option>
</select>
</div><div class="clear"></div>';
if(wpsqr_color_choice()):
$f .= '
<div class="wpsqr_colorpicker">
<p>Choose colors:
<input type="text" id="wpsqr_bg_color" name="wpsqr_bg_color" class="wpsqr_picker" value="'.wpsqr_get_bgcolor().'" />
<input type="text" id="wpsqr_fg_color" name="wpsqr_fg_color" class="wpsqr_picker" value="'.wpsqr_get_fgcolor().'" />
</p>
</div>';
endif;
$f .='
<div id="buscardqrid">
<p>First Name:<br /><input type="text" name="first_name" class="in_box" value="" size="28" /></p>
<p>Last Name:<br /><input type="text" name="last_name" class="in_box" value="" size="28" /></p>
<p>Company Name:<br /><input type="text" name="company_name" class="in_box" value="" size="28" /></p>
<p>Title:<br /><input type="text" name="title" class="in_box" value="" size="28" /></p>
<p>Telephone:<br /><input type="text" name="phone" id="phone" class="in_box" value="" size="28" /></p>
<p>Work Address:<br /><input type="text" name="work_address" id="addr" class="in_box" value="" size="28" /></p>
<p>City:<br /><input type="text" name="city" id="city" class="in_box" value="" size="28" /></p>
<p>State, ZIP Code:<br /><input type="text" name="state" id="state" class="in_box" value="" /></p>
<p>Email Address<br /><input type="text" name="email" id="email" class="in_box" value="" size="28" /></p>
<p>Website<br /><input type="text" name="website" class="in_box" value="https://" size="28" /></p>
<p>Memo<br /><input type="text" name="notes" id="notes" class="in_box" value="" size="28" /></p>
</div>
<div id="urlqrid">';
if( wpsqr_require_name() ):
$f .= '<p>Name:<br /><input type="text" name="first_name_url" class="in_box" value="" size="28" /></p>';
endif;
$f .= '
<p>URL<br /><input type="text" id="qrurl" name="qrurl" class="in_box" value="https://" size="28" /></p>
</div>
<div id="messageqrid">';
if( wpsqr_require_name() ):
$f .= '<p>Name:<br /><input type="text" name="first_name_message" class="in_box" value="" size="28" /></p>';
endif;
$f .= '
<p>Message<br /><textarea id="qrmessage" name="qrmessage" class="in_box" value="" size="28" ></textarea></p>
</div>
<p style="text-align:right"><input type="submit" name="wrqrin_submit" id="wrqrin_submit" value="Generate" /></p>
<input type="hidden" id="wpsqr_store" name="wpsqr_store" value="'.SQR_STORE.'" />
<input type="hidden" id="ip_address" name="ip_address" value="'.$_SERVER['REMOTE_ADDR'].'" />
</form>
<img id="qrimagescr" src="" border="none" />';
if($display_dl):
$f .= '
<div class="wpsqr_download">
<div class="wpsqr_field">'.$f2.'</div>
<div class="wpsqe_dl_img">
Download: <a class="wpsqr_dl_jpg" href="">JPG</a> | <a class="wpsqr_dl_png" href="">PNG</a>
</div>
</div>';
endif;
$f .='
<div class="clear"></div>
</div>
</div>';
return $f;
}
?>
Any assistance would be greatly appreciated.
Jack

php echo form inside div "wp"

I'm having a problem with my php code, when I try to echo a form inside a php I see it outside of div.
<?php
if ( is_user_logged_in() ) {
echo '<div class="loginformheader" style="margin-top: 0;">
<div id="reg-login">خروج</div></div>';
} else {
echo '<div class="loginformheader">'.header_login_form().'<div id="reg-login">تسجيل<span>|</span><a style="cursor: pointer;" id="logina">دخول</a><i class="fa fa-angle-up"></i></div></div>';
}
?>
The output
<p class="login-username">
<label for="user_login"></label>
<input type="text" name="log" id="user_login" class="input" value="" size="20" placeholder="اسم المستخدم">
</p>
<p class="login-password">
<label for="user_pass"></label>
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" placeholder="كلمة المرور">
</p>
<p class="login-remember"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever"> تذكرني</label></p>
<p class="login-submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="تسجيل الدخول">
<input type="hidden" name="redirect_to" value="http://localhost:8080/wordpress/2014/10/30/links-post-2/">
</p>
</form><div class="loginformheader"><div id="reg-login">تسجيل<span>|</span><a style="cursor: pointer;" id="logina">دخول</a><i class="fa fa-angle-up"></i></div></div> <hgroup class="site-branding">
<img class="site-logo" src="http://localhost:8080/wordpress/wp-content/themes/merwaa/img/logo.svg">
Maybe my English not very good, sorry me for that.
Can you help me?
Have a look at your header_login_form() function. It almost certainly echos the form, rather than returning it as a string. If that's the case, it'll be echoed when it's evaluated, which will be before the string it's in can be evaluated. Try this instead:
<?php
if ( is_user_logged_in() ) {
echo '<div class="loginformheader" style="margin-top: 0;">
<div id="reg-login">خروج</div></div>';
} else {
echo '<div class="loginformheader">';
header_login_form();
echo '<div id="reg-login">تسجيل<span>|</span><a style="cursor: pointer;" id="logina">دخول</a><i class="fa fa-angle-up"></i></div></div>';
}
?>

How to assign array value to textarea in smarty php

I have form where i have to edit this information. I can fetch all the fields to edit except description. Why textarea is not accepting dynamic array value? this is my issue.Please help me to fix this. Thanks in advance!!.
<form id="commentForm" name="commentForm" action="index.php?mdf=addbiography" method="POST" enctype="multipart/form-data" >
{if $admindetails[0].name neq ''}
<input type="hidden" id="action" name="action" value="saveupdate">
<input type="hidden" id="upid" name="upid" value="{$admindetails[0].id}">
{else}
<input type="hidden" id="action" name="action" value="add_biography">
{/if}
<article class="module width_full">
<header><h3 style="color: white;"> Add Biography</h3></header>
<div class="module_content">
<fieldset>
<div><label>Name<span class="star">*</span></label>
<input type="text" id="cname" name="name" class="required" value="{$admindetails[0].name}"></div></br></br></br>
<label>Description:<span class="star">*</span></label>
<textarea cols="60" rows="5" type="text" class="required" name="description" id="description" value="{$admindetails[0].description}"></textarea></br></br></br><br><br><br><br>
<div><label>Type<span class="star">*</span></label>
<select name="type" id="type" >
<option value="personal">Personal</option>
<option value="professional">Professional</option>
</select>
</div></br>
<div><label>Image<span class="star">*</span></label>
{if $admindetails[0].image eq ''}
<input type="file" name="file" id="file" style="margin-left:10px;" accept="image/*" class="required" value="">
{else}
<input type="file" name="file" id="file" style="margin-left:10px;" accept="image/*" value="">
{/if}
</div></br>
<img src="upload/{$admindetails[0].image}" width="300" height="300" alt="">
</fieldset>
<div class="clear"></div>
</div>
<footer>
<div class="submit_link">
<input type="submit" value="Save">
<input type="reset" value="Reset">
</div>
</footer>
</article><!-- end of stats article -->
</form>
Have you try doing this..
<textarea cols="60" rows="5" type="text" class="required" name="description" id="description" >{$admindetails[0].description}</textarea>

Categories