I have very simple dropdown menu like below in my PHP page.
<div class="form-group">
<label class="col-md-3 control-label">FAQ Type :-</label>
<div class="col-md-6">
<select name="faq_type" id="faq_type" class="select2" required>
<option value="0">Text</option>
<option value="1">Image</option>
<option value="2">Video</option>
</select>
</div>
</div>
I want select Text, Image or Video selection automatically according to value I get from database, for other field I am able to echo like below
<div class="col-md-6">
<textarea name="question" id="question" rows="1" class="form-control" ><?php if(isset($_GET['faq_id'])){echo $row['question'];}?></textarea>
</div>
How can I do same for dropdown ?
Edit : according to answer, I was able to do it but I have one small another issue in it, I want only set selected if if(isset($_GET['faq_id'])) else want show normal all button as currently I am showing as above.
<div class="form-group">
<label class="col-md-3 control-label">FAQ Type :-</label>
<div class="col-md-6">
<?php
if(isset($_GET['faq_id'])) {
<select name="faq_type" id="faq_type" class="select2" required>
<option value="0" <?php if($row['type'] == "0") echo "selected"; ?>>Text</option>
<option value="1" <?php if($row['type'] == "1") echo "selected"; ?>>Image</option>
<option value="2" <?php if($row['type'] == "2") echo "selected"; ?>>Video</option>
</select>
} else {
}
?>
</div>
</div>
if I do like this, its giving me error like below
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\new\add_faq.php on line 169
Thanks
For drop down you can set selected field like this
<div class="form-group">
<label class="col-md-3 control-label">FAQ Type :-</label>
<div class="col-md-6">
<select name="faq_type" id="faq_type" class="select2" required>
<option value="0" <?php if($row['your_db_field'] == "0") { ?> selected="selected" <?php } ?> >Text</option>
<option value="1" <?php if($row['your_db_field'] == "1") { ?> selected="selected" <?php } ?> >Image</option>
<option value="2" <<?php if($row['your_db_field'] == "3") { ?> selected="selected" <?php } ?> >Video</option>
</select>
</div>
</div>
Related
$batch = htmlentities($_POST['batch']);
if($batch === 'NULL'){
echo "Batch Failed";
} else {
echo "$bacth";
}
<div class="col-md-12">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-globe"></i></span>
<select class="form-control" name="batch" id="select">
<option selected disabled>Batch Preference</option>
<option value="Weekends">Weekends</option>
<option value="Holidays">Holidays</option>
</select>
</div>
</div>
</div>
How to select those select options in form using php, how i can validate them...
Thank You
I'm working on a profile update page and i have a form field where users can select enabled or disabled. When i echo the value, it has a duplicate and can be confusing for the user. How can i get rid of the duplicate?
<div class="form-group">
<label for="status" class="col-sm-3 control-label">Change Status</label>
<div class="col-sm-9">
<select class="form-control btn-danger" id="status" name="status">
<option value="<?php echo $status ?>"><?php echo $status ?></option>
<option value="Disabled">Disabled</option>
<option value="Enabled">Enabled</option>
</select>
</div>
</div>
As you can see, if the status is enabled and i hit the select menu its gonna say Enabled twice, same thing for disabled.
The only thing i thought of was to have another field labeled current status and have the select menu to change status.
I really dont want to do that.
<div class="form-group">
<label for="currentstatus" class="col-sm-3 control-label">Current Status</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="currentstatus" name="currentstatus" value="<?php echo $status ?>">
</div>
</div>
<div class="form-group">
<label for="status" class="col-sm-3 control-label">Change Status</label>
<div class="col-sm-9">
<select class="form-control btn-danger" id="status" name="status">
<option value="<?php echo $status ?>"><?php echo $status ?></option>
<option value="Disabled">Disabled</option>
<option value="Enabled">Enabled</option>
</select>
</div>
</div>
This worked for me:
<option <?php if ($status=="Disabled") echo " selected"; ?>>Disabled</option>
<option <?php if ($status=="Enabled") echo " selected"; ?>>Enabled</option>
Instead of outputting the selected value as another option, output it as the selected attribute of an existing option. Something like this:
<select class="form-control btn-danger" id="status" name="status">
<option value="Disabled" <?php echo ($status == "Disabled") ? "selected" : ""; ?>>Disabled</option>
<option value="Enabled" <?php echo ($status == "Enabled") ? "selected" : ""; ?>>Enabled</option>
</select>
There are likely a variety of ways to achieve the same end result, but the point is to not add options based on the data you have but instead use that data to determine which of the existing, finite, hard-coded options you already have should be selected.
Here is some jQuery that will let you change the value of the select box.
function setStatusSelect(val) {
$("select#status").val(val);
}
setStatusSelect('Enabled');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
<label for="status" class="col-sm-3 control-label">Change Status</label>
<div class="col-sm-9">
<select class="form-control btn-danger" id="status" name="status">
<option value="Disabled">Disabled</option>
<option value="Enabled">Enabled</option>
</select>
</div>
</div>
If you include the Jquery function at the top of the page (so that it loads quickly) then you can do something like this:
<?php
print("<script type=\"text/javascript\">");
print("setStatusSelect(".$status.")");
print("</script>");
?>
to set the value.
I haven't tested the PHP portion, but I know the jQuery portion works.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
ive been all around trying to fix the code but i still get an error
Parse error: syntax error, unexpected 'userfirstName' (T_STRING), expecting ',' or ';' in /home/crosswayprinting/public_html/ztest2/functions/shop.php on line 66
here's the code btw
whats my mistake :/ ?
<?php if($user_home->is_logged_in()){
echo '
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2 class="section-heading">Place an Order</h2>
<div class="text-center" style="input, select, textarea{
color: #000;
}">
</div><BR>
<form role="form" class="userTrans" method="POST">
<input type="hidden" value="OrderInsert" name="act_userTrans">
<div class="form-group">
<label for="typeofservice">Select Type of Service</label>
<select id="typeofservice" class="form-control" name="typeofservice">
<option value="Tarpaulin">Tarpaulin</option>
<option value="Rush ID">Rush ID</option>
<option value="Photocopy">Photocopy</option>
<option value="Graphic Layout">Graphic Layout</option>
<option value="Invitation">Invitation</option>
<option value="Panaflex">Panaflex</option>
<option value="Signages">Signages</option>
<option value="Stickers">Stickers</option>
<option value="Sintra board">Sintra board</option>
<option value="Large Format Photo">Large Format Photo</option>
<option value="PVC ID">PVC ID</option>
<option value="Lamination">Lamination</option>
<option value="Bag Tags">Bag Tags</option>
<option value="Notary Public">Notary Public</option>
<option value="Scan">Scan</option>
</select>
</div>
<div class="form-group">
<label for="templateselect">Template Selection</label>
<select id="templateselect" class="form-control" name="templateselect">
<option value="Own Made Template">Own Made Template</option>
<option value="Pre-made Template">Pre-made Template</option>
</select>
</div>
<div class="form-group">
<label for="text">More details about your order</label>
<input type="text" class="form-control" id="orderdetails" name="orderdetails">
</div>
<div class="form-group">
<label for="text"> Customer Name</label>
<input type="text" value=" <?php echo $row['userfirstName']; ?> " class="form-control" id="customer" name="customer">
</div>
/* this is the code btw what makes it an error, i am trying to
echo a customer's name and make it Passive or uneditable textbox so it can
register to my orderlist to whom ordered */
<button type="submit" class="btn btn-default userTrans">Submit</button>
</form>
';
}
else{
echo '
<center> Please Login to Place an Order </center>
';}
?>
Get rid of the echo statements wrapping your HTMl. There's no need, just escape out of the PHP interpreter and print your HTML. Then you won't get an error when you're doing <?php echo $row['userFirstName']; ?>....Something like this:
<?php if($user_home->is_logged_in()){ ?>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2 class="section-heading">Place an Order</h2>
<form role="form" class="userTrans" method="POST">
<input type="hidden" value="OrderInsert" name="act_userTrans">
<div class="form-group">
<label for="typeofservice">Select Type of Service</label>
<select id="typeofservice" class="form-control" name="typeofservice">
<option value="Tarpaulin">Tarpaulin</option>
<option value="Rush ID">Rush ID</option>
<option value="Photocopy">Photocopy</option>
<option value="Graphic Layout">Graphic Layout</option>
<option value="Invitation">Invitation</option>
<option value="Panaflex">Panaflex</option>
<option value="Signages">Signages</option>
<option value="Stickers">Stickers</option>
<option value="Sintra board">Sintra board</option>
<option value="Large Format Photo">Large Format Photo</option>
<option value="PVC ID">PVC ID</option>
<option value="Lamination">Lamination</option>
<option value="Bag Tags">Bag Tags</option>
<option value="Notary Public">Notary Public</option>
<option value="Scan">Scan</option>
</select>
</div>
<div class="form-group">
<label for="templateselect">Template Selection</label>
<select id="templateselect" class="form-control" name="templateselect">
<option value="Own Made Template">Own Made Template</option>
<option value="Pre-made Template">Pre-made Template</option>
</select>
</div>
<div class="form-group">
<label for="text">More details about your order</label>
<input type="text" class="form-control" id="orderdetails" name="orderdetails">
</div>
<div class="form-group">
<label for="text"> Customer Name</label>
<input type="text" value=" <?php echo $row['userfirstName']; ?> " class="form-control" id="customer" name="customer">
<!-- now the above won't give an error -->
</div>
<button type="submit" class="btn btn-default userTrans">Submit</button>
</form>
</div>
</div>
<?php } else { ?>
<!-- Do not use center tags when you're using bootstrap framework -->
<!--<center> Please Login to Place an Order </center>-->
<div class="text-center"> Please Login to Place an Order </div>
<?php } ?>
Also what's going on with your inline styles? That's not how this works:
<div class="text-center" style="input, select, textarea{
color: #000;
}">
Just move that CSS somewhere else. You can't use targeted selectors within the style="" tag, only relevant CSS.
I have some php which lists a bunch of options (through a loop) and prints them on the page with a new line for each.
I want the options to come up in a dynamically sized drop down HTML list each with different option values.
This is the PHP (it works perfectly):
if($postOpts) {
foreach($postOpts as $option)
echo $option["name"]." - ".$option["price"]."<BR>";
}
//Otherwise, present the default postage option for domestic or international.
else {
echo "Default Shipping Option - $".$post->getDefaultPrice();
}
I have a form but as you can see the form amount of options is static not dynamic:
<form> <!-- form action will go here -->
<div class="form-group col-xs-12">
<div class="col-xs-3 col-md-2 form-label"><label>Shipping Options:</label></div>
<div class="col-xs-4 col-md-3">
<select class="form-control" name="list" title="pick a type">
<!-- I assume I need to iterate through options here -->
<option value="01">Shipping1</option>
<option value="02">Shipping2</option>
<option value="03">Shipping3</option>
</select>
</div>
</div>
</form>
EDIT I forgot the other else statement in the PHP, please check.
Replace your select with this,
<select class="form-control" name="list" title="pick a type">
<?php if(count($postOpts)) { ?>
<?php foreach($postOpts as $row) { ?>
<option value="<?= $row["price"] ?>"><?= $row["name"] ?></option>
<?php } ?>
<?php } else { ?>
<option value="<?= $post->getDefaultPrice() ?>"><?= "Default Shipping Option - $".$post->getDefaultPrice() ?></option>
<?php } ?>
</select>
You can try this
<form> <!-- form action will go here -->
<div class="form-group col-xs-12">
<div class="col-xs-3 col-md-2 form-label"><label>Shipping Options:</label></div>
<div class="col-xs-4 col-md-3">
<select class="form-control" name="list" title="pick a type">
<option value="">Choose type</option>
<?php foreach($postOpts as $option) { ?>
<option value="<?php echo $option['name'].' - '.$option['price'];?>"><?php echo $option["name"]." - ".$option["price"]; ?></option>
<?php } ?>
</select>
</div>
</div>
</form>
I am trying to upload a .zip file. It is working well for small files . But I can upload files >2MB. When I try to upload files >2 MB google chrome shows in the bottom left corner as (uploadin : --%) where -- is a no like 10. But it is stuck after 14%. After some time it shows an error like "Error 101 (net::ERR_CONNECTION_RESET): The connection was reset."This web page is not available.
Please help me
This is the form code
<form name="addnewitem" id="addnewitem" method="post" enctype="multipart/form-data">
<?php if (($succ==0) && ($message!="")) { echo "<div class='error'>".$message."</div>"; } ?>
<?php if ($msg!="") { echo "<div class='success'>".$msg."</div>"; } ?>
<?php if ($msg1!="") { echo "<div class='error'>".$msg1."</div>"; } ?>
<div class="list-item">
<div class="form">
<h2>Name & Description</h2>
<div class="row">
<div class="left">
<label>Item Title:</label>
</div>
<div class="right">
<input name="listitemname" id="listitemname" type="text" class="input" maxlength="50" value="<?php echo $_POST['listitemname']; ?>" />
<em>Maximum 50 characters</em>
</div>
</div>
<div class="row">
<div class="left">
<label>
Item Description:
</label></div>
<div class="right">
<textarea name="itemdescription" id="itemdescription" cols="10" rows="5"><?php echo $_POST['itemdescription'];?></textarea>
<em>Maximum 600 characters</em>
</div>
</div>
</div>
<div class="form">
<h2>
Item Files & Preview
</h2>
<div class="row">
<div class="left">
<label>
Item Thumbnail:
</label>
</div>
<div class="right"><input type="file" name="thumbnailimage" id="thumbnailimage" class="input" />
<em>JPG or PNG, 80 x 80 Thumbail</em>
</div>
</div>
<div class="row">
<div class="left">
<label>
Item Rollover Preview:
</label></div>
<div class="right"><input type="file" name="rolloverimage" id="rolloverimage" class="input" />
<em>JPG or PNG, 190 x 190 Preview Image</em>
</div>
</div>
<div class="row">
<div class="left">
<label>
Screenshot image 1:
</label></div>
<div class="right"><input type="file" name="themepreview1" id="themepreview1" class="input" />
<em>JPG or PNG, 420 x 420 Image Screenshot ( Required )</em>
</div>
</div>
<div class="row">
<div class="left">
<label>
Screenshot image 2:
</label></div>
<div class="right"><input type="file" name="themepreview2" id="themepreview2" class="input" />
<em>JPG or PNG, 420 x 420 Image Screenshot ( Optional )</em>
</div>
</div>
<div class="row">
<div class="left">
<label>
Screenshot image 3:
</label></div>
<div class="right"><input type="file" name="themepreview3" id="themepreview3" class="input" />
<em>JPG or PNG, 420 x 420 Image Screenshot ( Optional )</em>
</div>
</div>
<div class="row">
<div class="left">
<label>
Screenshot image 4:
</label></div>
<div class="right"><input type="file" name="themepreview4" id="themepreview4" class="input" />
<em>JPG or PNG, 420 x 420 Image Screenshot ( Optional )</em>
</div>
</div>
<div class="row">
<div class="left">
<label>
Item Zip File:
</label></div>
<div class="right"><input type="file" name="itemfile" id="itemfile" class="input" />
<em>.ZIP File Only </em>
</div>
</div>
<div class="row">
<div class="left">
<label>Demo URL:</label>
</div>
<div class="right">
<input name="demourl" id="demourl" type="text" class="input" value="<?php echo $_POST['demourl']; ?>" />
<em>Enter the www.themepreviewurl.com here for the item Live Preview</em>
</div>
</div>
</div>
<div class="form">
<h2>
Category & Attributes
</h2>
<div class="row">
<div class="left">
<label>
Category:
</label></div>
<div class="right">
<?php
$getmaincategories = "SELECT category_name,category_id FROM ".$tbl_main_categories." WHERE category_status = 1";
$exec_getmaincategories = mysql_query($getmaincategories);
echo "<select name='categoryname' id='categoryname'>";
echo "<option value='' >Select a Category Now</option>";
while($rows_getmaincategories = mysql_fetch_array($exec_getmaincategories)) {
$getsubcategories = "SELECT sub_category_name,sub_category_hash FROM ".$tbl_sub_categories." WHERE sub_category_status=1 AND category_id=".$rows_getmaincategories['category_id'];
$exec_getsubcategories = mysql_query($getsubcategories);
echo "<option disabled='disabled' value='".$rows_getmaincategories['category_id']."'>".$rows_getmaincategories['category_name']."</option>";
while($rows_getsubcategories = mysql_fetch_array($exec_getsubcategories)) {
if ($_REQUEST['categoryname'] == $rows_getsubcategories['sub_category_hash']) { echo $selectedvalue = "selected='selected'"; }
echo "<option value='".$rows_getsubcategories['sub_category_hash']."' style='padding-right:inherit' $selectedvalue> -".$rows_getsubcategories['sub_category_name']."</option>";
}
}
echo "</select>";
?>
</div>
</div>
<div class="row">
<div class="left">
<label>
Compatible Browsers:<br />
use 'ctrl' to select multiples
</label></div>
<div class="right">
<select multiple="multiple" class="select" name="browsercompatiable[]" id="browsercompatiable[]">
<option value="">Select</option>
<option value="ie7" <?php if ($_REQUEST['browsercompatiable'] == "ie7") echo "selected='selected'"; ?>>IE7</option>
<option value="ie8" <?php if ($_REQUEST['browsercompatiable'] == "ie8") echo "selected='selected'"; ?>>IE8</option>
<option value="ie9" <?php if ($_REQUEST['browsercompatiable'] == "ie9") echo "selected='selected'"; ?>>IE9</option>
<option value="firefox" <?php if ($_REQUEST['browsercompatiable'] == "firefox") echo "selected='selected'"; ?>>Firefox</option>
<option value="safari" <?php if ($_REQUEST['browsercompatiable'] == "safari") echo "selected='selected'"; ?>>Safari</option>
<option value="chrome" <?php if ($_REQUEST['browsercompatiable'] == "chrome") echo "selected='selected'"; ?>>Chrome</option>
</select>
</div>
</div>
<div class="row">
<div class="left">
<label>
Files Includes:<br />
Use 'ctrl' to select multiples
</label></div>
<div class="right">
<select multiple="multiple" size="5" class="select" name="filesinclude[]" id="filesinclude[]">
<option value="">Select</option>
<option value="ie7" <?php if ($_REQUEST['filesinclude'] == "ie7") echo "selected='selected'"; ?>>PSD Files</option>
<option value="ie8" <?php if ($_REQUEST['filesinclude'] == "ie8") echo "selected='selected'"; ?>>Documentation</option>
<option value="ie9" <?php if ($_REQUEST['filesinclude'] == "ie9") echo "selected='selected'"; ?>>Multiple Layouts</option>
<option value="firefox" <?php if ($_REQUEST['filesinclude'] == "firefox") echo "selected='selected'"; ?>>Multiple Colour Options</option>
<option value="safari" <?php if ($_REQUEST['filesinclude'] == "safari") echo "selected='selected'"; ?>>Video Help Files</option>
<option value="chrome" <?php if ($_REQUEST['filesinclude'] == "chrome") echo "selected='selected'"; ?>>Other</option>
</select>
</div>
</div>
<div class="row">
<div class="left">
<label>
Columns:
</label></div>
<div class="right">
<select name="noofcolumns" id="noofcolumns">
<option value="">Select</option>
<option value="1" <?php if ($_REQUEST['noofcolumns'] == "1") echo "selected='selected'"; ?>>1</option>
<option value="2" <?php if ($_REQUEST['noofcolumns'] == "2") echo "selected='selected'"; ?>>2</option>
<option value="3" <?php if ($_REQUEST['noofcolumns'] == "3") echo "selected='selected'"; ?>>3</option>
<option value="4" <?php if ($_REQUEST['noofcolumns'] == "4") echo "selected='selected'"; ?>>4</option>
<option value="5" <?php if ($_REQUEST['noofcolumns'] == "5") echo "selected='selected'"; ?>>5</option>
</select>
</div>
</div>
<div class="row">
<div class="left">
<label>
Layout:
</label></div>
<div class="right">
<select name="layout" id="layout">
<option value="">Select</option>
<option value="1" <?php if ($_REQUEST['layout'] == "1") echo "selected='selected'"; ?>>1</option>
<option value="2" <?php if ($_REQUEST['layout'] == "2") echo "selected='selected'"; ?>>2</option>
<option value="3" <?php if ($_REQUEST['layout'] == "3") echo "selected='selected'"; ?>>3</option>
<option value="4" <?php if ($_REQUEST['layout'] == "4") echo "selected='selected'"; ?>>4</option>
<option value="5" <?php if ($_REQUEST['layout'] == "5") echo "selected='selected'"; ?>>5</option>
</select>
<em>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id arcu vitae eros molestie ultricies ut sit amet nisi. Nulla facilisi.</em>
</div>
</div>
</div>
<div class="form">
<h2>Tags</h2>
<div class="row">
<div class="left">
<label>Tags:</label>
</div>
<div class="right">
<textarea name="itemtags" id="itemtags" cols="10" rows="5"><?php echo $_POST['itemtags']; ?></textarea>
<em>Maximum 50 characteres</em>
</div>
</div>
</div>
<div class="botton">
<input name="additem" id="additem" type="submit" value="Upload Now" class="btn" />
</div>
</div>
</form>
And I would like to upload >3MB files in the .zip field shown below
<div class="right"><input type="file" name="itemfile" id="itemfile" class="input" />
<em>.ZIP File Only </em>
</div>
Check upload_max_filesize, max_input_time, and post_max_size in your php.ini
If the file size is very large, you may need to bump memory_limit as well.
change php.ini change size and test your script.(php.ini resides in php installation directory)
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
to
upload_max_filesize = Required_size M
Please check that your "max_input_time" option in your server is not too low, it might be why PHP is cutting you off. Else it could be a server/network infrastructure related issue:
echo ini_get('max_input_time');
If you get -1 from this, it is most probably not PHP cutting you off but something else in the loop. It can be any piece of hardware on the way to your server, but most probably the server itself or something at the server place...
For large files, if you don't want to have to deal with configuring server settings (particularly if you are on shared hosting or some other hosting that doesn't give you full control over the server), one potential solution is to hand the upload off to a third party service.
For example, you could have the form do a direct post to Amazon S3 (http://s3.amazonaws.com/doc/s3-example-code/post/post_sample.html) or use a service like Filepicker.io
Full disclosure: I work at Filepicker.io, but want to help out folks who are dealing with issues doing large file uploads