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.
Related
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.
I have a popup which shows up if the user is not logged in. It contains a cancel link, a form to enter details, and a forget password link. My problem is when the user comes back from the forget password link and clicks the cancel link, it takes them back to the forget password page.
Here is my code.
<div class="contactForm_new" id="popUpDiv" style="display:none;">
<!--<div class="lightBlue heading" >Tell us your Buy Requirement</div>-->
<div class="blueLightBG heading" style="text-align: left;
padding-left: 2%;background-color:#009bcb ">Enter Password <span class=" dpbl fr mainSp cr_bt2 p_a closeTrigger closePopup href" style="position: absolute; display: block;"></span></div>
<form method="post" class="contactF" id="login-form">
<input type="hidden" value="" name="offerid">
<input type="hidden" value="" name="refvalue">
<input type="hidden" value="" name="tenderid">
<input type="hidden" value="" name="item_id">
<input type="hidden" value="" name="pid">
<input type="hidden" value="sd" name="ref">
<input type="hidden" value="1" name="isLogRequest">
<input type="hidden" name="iso" id="iso" value="<?php echo $details['iso'] ?>">
<input type="hidden" value="<?php echo $return_en_url ?>" id="p_address" name="p_address">
<div class="errorMessage" id="errorUsername"></div>
<input type="hidden" name="diff_usr" value="Y">
<input type="hidden" value="Y" name="diff_usr">
<input class="pd3 textlogin_new" name="LoginForm[password]" id="LoginForm_password" type="password">
<div class="errorMessage" id="errorPassword"></div>
<div style="padding:15px 0;text-align:center">
<span id="imgprcp" class="fl" style=" display: none; text-align: center;margin-left:50%;"><img src="<?php echo Yii::app()->params['hostName'] ?>/images/ind.gif" alt="Proceeding"></span>
<input id="btnSubmit" type="button" name="yt0" value="Proceed" class="redBtn_new" >
</div>
<div class="mb3per" style="display:block">
<p class="k7_new" style="position:absolute;" >
<a class="k7_new" id="forgotpass" style="position:relative;" href="<?php echo Yii::app()->params['hostName'] ?>/forgotpass/?ref=<?php echo $ref ?>&p=<?php echo $return_en_url ?>" >Forgot Password?</a>
</p>
</div>
</form>
</div>
Can anybody suggest what am I doing wrong? All of my URLs are formed correctly.This problem is coming in only chrome browser.In another browser it is working fine
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' ); ?>
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>
I am creating an html form that contains multiple checkboxes...
Here is my code
Form
<form enctype="multipart/form-data" action="processstart.php" method="post" class="wpcf7-form">
<div class="form-row">
<span class="label--input-group">Services you require</span>
<span class="wpcf7-form-control-wrap services">
<span class="wpcf7-form-control wpcf7-checkbox check-group-input">
<span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Branding" /> <span class="wpcf7-list-item-label">Branding</span>
</label>
</span>
<span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Design" /> <span class="wpcf7-list-item-label">Design</span>
</label>
</span>
<span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Other" /> <span class="wpcf7-list-item-label">Other</span>
</label>
</span>
<span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Development" /> <span class="wpcf7-list-item-label">Development</span>
</label>
</span>
<span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Illustration" /> <span class="wpcf7-list-item-label">Illustration</span>
</label>
</span>
</span>
</span>
</div>
</form>
Here is processstart.php
<?php
if(isset($_POST['services'])) {
foreach($_POST['services'] as $services) {
echo $services;
}
}
?>
Now nothing is getting echoed...I have tried var_dump(get_defined_vars()); and every other variable is defined except these checkboxes. Not even showing "null" there. What is going wrong?
You have missed to close <form> tag and add submit button
<input type="submit" name="submit" value="submit">
</form>
try i have action on same file but you can change action values will be appear after any checkbox is checked else you can't get checkbox values
On your form not any close <form> tag and not submit form action like button or submit button
<?php if(isset($_POST['services']))
{
foreach($_POST['services'] as $services)
{
echo $services;
}
}?>
<html>
<body>
<form enctype="multipart/form-data" action="" method="post" class="wpcf7-form">
<div class="form-row"><span class="label--input-group">Services you require</span><span class="wpcf7-form-control-wrap services"><span class="wpcf7-form-control wpcf7-checkbox check-group-input"><span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Branding" />
<span class="wpcf7-list-item-label">Branding</span></label>
</span><span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Design" />
<span class="wpcf7-list-item-label">Design</span></label>
</span><span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Other" />
<span class="wpcf7-list-item-label">Other</span></label>
</span><span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Development" />
<span class="wpcf7-list-item-label">Development</span></label>
</span><span class="wpcf7-list-item">
<label>
<input type="checkbox" name="services[]" value="Illustration" />
<span class="wpcf7-list-item-label">Illustration</span></label>
</span></span></span></div>
<input type="submit" name="sub">
</form>
</body>
</html>
actually you are not submitting your form. You just specified in 'action'. To achieve your code workable, add a submit button. So that, while clicking it will call processstart.php
<input type="submit">