Is it possible to have a : separator in a form input field for a manual time input? Something like the following example:
<p>
<div class='field'>
<label for='$time_in'>Time In</label>
<input type='text' name='time_in' id='time_in'
size='10' maxlength='5' /></div>
</p>
Using "Internet explorer"
You can take 2 seperate fields like
<p>
<div class='field'>
<label for='$time_in'>Time In</label>
<input type='text' name='time_in1' id='time_in1'
size='10' maxlength='2' />
:
<input type='text' name='time_in2' id='time_in2'
size='10' maxlength='2' />
</div>
</p>
and handle them separately in the code, it will work!
Related
I tried to search yet i unable to find out what i am looking for.Please help me.I am working on a rating form which using radio button star for rating,I am using while loop of mysqli_fetch_assoc to pull the date from database.As shown below
<?php
$sql = "SELECT * FROM orderdetail,orderuser,food WHERE orderuser.CustomerID=orderdetail.CustomerID AND orderuser.OrderID=orderdetail.OrderID AND orderdetail.FoodID=food.FoodID AND orderuser.confirmstatus=1";
$result = $conn->query($sql) or die($conn->error);
while($colum = mysqli_fetch_assoc($result))
{
?>
<img src="../php/<?php echo $colum['Foodphoto'];?>" style="height:150px;width:150px">
<br>
<?php echo $colum['FoodName'];?>
<br>
<div class="stars">
<form action="">
<input class="star star-5" id="rate-5[]" type="radio" name="rate[]" />
<label class="star star-5" for="rate-5[]"></label>
<input class="star star-4" id="rate-4[]" type="radio" name="rate[]" />
<label class="star star-4" for="rate-4[]"></label>
<input class="star star-3" id="rate-3[]" type="radio" name="rate[]" />
<label class="star star-3" for="rate-3[]"></label>
<input class="star star-2" id="rate-2[]" type="radio" name="rate[]" />
<label class="star star-2" for="rate-2[]"></label>
<input class="star star-1" id="rate-1[]" type="radio" name="rate[]" />
<label class="star star-1" for="rate-1[]"></label>
</form>
</div>
<hr>
<?php
}
?>
but the rating for the second result is not working,i find out that is due to the problem of name but i tried to edit it by adding the array still not working. And how could i store them into mysql using php?those tutorial i found only using ajax or jquery i need the ratings submit once the user submitted the form.
The problem I think is that you cannot relate the form being submitted with the record so any update will not work as expected. One of the simplest ways to accomplis this would be a hidden field with the ID of the record - the ID can then be used in the update statement - ie: ( pseudo sql update )
update orderdetail set rating=$rate where ID=$id
So, add a hidden field per form like this perhaps
while($colum = mysqli_fetch_assoc($result)){
?>
<img src='../php/<?php echo $colum['Foodphoto'];?>' style='height:150px;width:150px'>
<br>
<?php echo $colum['FoodName'];?>
<br>
<div class='stars'>
<form action=''>
<input class='star star-5' type='radio' id='rate-5' name='rate' />
<label class='star star-5' for='rate-5'></label>
<input class='star star-4' type='radio' id='rate-4' name='rate' />
<label class='star star-4' for='rate-4'></label>
<input class='star star-3' type='radio' id='rate-3' name='rate' />
<label class='star star-3' for='rate-3'></label>
<input class='star star-2' type='radio' id='rate-2' name='rate' />
<label class='star star-2' for='rate-2'></label>
<input class='star star-1' type='radio' id='rate-1' name='rate' />
<label class='star star-1' for='rate-1'></label>
<!--
HIDDEN FIELD WITH ID
-->
<input type='hidden' name='id' value='<?php echo $colum['id'];?>' />
</form>
</div>
<hr>
So I've put a contact form into my site but I can't seem to add a subject line. (I'm SUPER new to PHP so I'm only about 40% sure of what I'm doing. The rest of the time I'm just learning through trial and error).
Here's what I have for the form:
<?PHP
require_once("./include/fgcontactform.php");
$formproc = new FGContactForm();
$formproc->AddRecipient('email address');
$formproc->AddSubject('Website Communication:');
$formproc->SetFormRandomKey('boQQEtSLenwppBa');
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$formproc->RedirectToURL("thank-you.php");
}
}
?>
<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Contact us</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='message' >Message:</label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
I added the $formproc->AddSubject('Website Communication:'); segment but it doesn't seem to be working and I'm wondering if there's something I'm missing?
What you're really asking is how to use a specific library class that you've downloaded from the Internet! If you look into the code of the class you're including at the top (which I assume is the same as this?) then you'll see it's automatically generating a subject line here:
$this->mailer->Subject = "Contact form submission from $this->name";
The reason your AddSubject function doesn't work is because that behaviour doesn't exist within the class.
If you want to change this behaviour, you'll have to change the class. You'll want to change the above line to something like
$this->mailer->Subject = $this->getSubject();
and implement a getSubject() method, similar to the GetFromAddress() one.
Better yet, create your own mailer class! Look into the PHP mail function to get started!
This is an extended question from: Get $_POST from multiple checkboxes
I am trying to get the labels of each checked checkbox, then display it as such:
"Sales | Engineering" (without the quotes)
Or if only one checkbox was selected:
"Sales"
HTML (myform.html):
<!DOCTYPE html>
<html>
<head></head>
<body>
<form name='myform' method='post' action='result.php'>
<label for='sales'>Sales</label>
<input type='checkbox' name='loc_chks[]' id='sales' value='Sales' /><br/>
<label for='insideSales'>Inside Sales</label>
<input type='checkbox' name='loc_chks[]' id='insideSales' value='Inside Sales' /><br/>
<label for='engineering'>Engineering</label>
<input type='checkbox' name='loc_chks[]' id='engineering' value='Engineering' /><br/>
<label for='fieldService'>Field Service</label>
<input type='checkbox' name='loc_chks[]' id='fieldService' value='Field Service' /><br/>
<label for='production'>Production</label>
<input type='checkbox' name='loc_chks[]' id='production' value='Production' /><br/>
<label for='warehouse'>Warehouse</label>
<input type='checkbox' name='loc_chks[]' id='warehouse' value='Warehouse'/><br/>
<br/>
<input type='submit' id='subBtn' value='Submit'/>
</form>
</body>
</html>
PHP (result.php):
<!DOCTYPE html>
<html>
<head></head>
<body>
<p><?php
if(!empty($_POST["loc_chks"]) and is_array($_POST["loc_chks"])) {
echo implode(' | ',$_POST["loc_chks"]);
} else { echo "we have a loser";}
?>
</p>
</body>
</html>
*Edited - the "if" statement in the php file always returns false even if multiple checkboxes are checked
You should use array type naming loc_chks[], this also lets you use specific keys for each item, for example: loc_chks[sales] and with PHP you have it in $_POST["loc_chks"]["sales"]
HTML (myform.html):
<label for='sales'>Sales</label>
<input type='checkbox' name='loc_chks[]' id='sales' value='Sales' /><br/>
<label for='insideSales'>Inside Sales</label>
<input type='checkbox' name='loc_chks[]' id='insideSales' value='Inside Sales' /><br/>
<label for='engineering'>Engineering</label>
<input type='checkbox' name='loc_chks[]' id='engineering' value='Engineering' /><br/>
<label for='fieldService'>Field Service</label>
<input type='checkbox' name='loc_chks[]' id='fieldService' value='Field Service' /><br/>
<label for='production'>Production</label>
<input type='checkbox' name='loc_chks[]' id='production' value='Production' /><br/>
<label for='warehouse'>Warehouse</label>
<input type='checkbox' name='loc_chks[]' id='warehouse' value='Warehouse' /><br/>
In PHP you can use implode funciton, which lets you concatenate array items with the glue string (as first parameter)
PHP (result.php):
<?php
session_start();
if(!empty($_POST["loc_chks"]) and is_array($_POST["loc_chks"])) {
$loc = implode(' | ',$_POST["loc_chks"]);
}
?>
Value is missing... use following
<label for='sales'>Sales</label>
<input type='checkbox' name='loc_chks[]' id='sales' value='Sales' /><br/>
<label for='insideSales'>Inside Sales</label>
<input type='checkbox' name='loc_chks[]' id='insideSales' value='Inside Sales' /><br/>
<label for='engineering'>Engineering</label>
<input type='checkbox' name='loc_chks[]' id='engineering' value='Engineering' /><br/>
<label for='fieldService'>Field Service</label>
<input type='checkbox' name='loc_chks[]' id='fieldService' value='Field Service' /><br/>
<label for='production'>Production</label>
<input type='checkbox' name='loc_chks[]' id='production' value='Production' /><br/>
<label for='warehouse'>Warehouse</label>
<input type='checkbox' name='loc_chks[]' id='warehouse' value='Warehouse'/><br/>
First of all assign those labels as values of checkboxes and secondly name the checkboxes like an array. Without naming all your checkboxes like that, you won't get multiple values like you are expecting in your loop.
<label for='sales'>Sales</label>
<input type='checkbox' name='loc_chks[]' id='sales' value="Sales"/><br/>
^^ ^
Nevermind - Im as dumb#$$. I didn't close out the "name" property in the form. Everything works - Thank you all for your input. George PHP has a slightly better solution.
I am on the PostgreSQL system. I've used it before and have not had this issue, but that was for basic select querying.
Now I am trying to insert data through an HTML form and php.
I do not get an error back when I fill out the data (even when I input all fields on the form) so I assume it should be inserted....
Here is my php/html:
<div id='insert_form'>
<form method='POST' action='insert.php' onsubmit='return checkSubmit()'>
<label id='lbl_header'><b>Bold</b> fields are required.</label>
<br /><br />
<label class='required' for='code1' id='lbl_code1'>* Country code</label>
<input type='text' name='code1' id='code1' maxlength='3' size='3'/>
<br /><br />
<label class='required' for='code2' id='lbl_code2'>* Country code (abbr.)</label>
<input type='text' name='code2' id='code2' maxlength='2' size='2'/>
<br /><br />
<label class='required' for='country_name' id='lbl_name'>* Country name</label>
<input type='text' name='country_name' id='country_name' maxlength='52'/>
<br /><br />
<label class='required' for='continent' id='lbl_continent'>* Continent</label>
<select name='continent' id='continent'>
<option value='Africa'>Africa</option>
<option value='Antarctica'>Antarctica</option>
<option value='Asia'>Asia</option>
<option value='Europe'>Europe</option>
<option value='North America'>North America</option>
<option value='Oceania'>Oceania</option>
<option value='South America'>South America</option>
</select>
<br /><br />
<label class='required' for='region' id='lbl_region'>* Region</label>
<input type='text' name='region' id='region' maxlength='26' />
<br /><br />
<label class='required' for='area' id='lbl_area'>* Surface area</label>
<input type='text' name='area' id='area' />
<br /><br />
<label for='indepYear' id='lbl_year'>Year of independence</label>
<input type='text' name='indepYear' id='indepYear' />
<br /><br />
<label class='required' for='population' id='lbl_pop'>* Population</label>
<input type='text' name='population' id='population' />
<br /><br />
<label for='lifeExp' id='lbl_lifeExp'>Life expectancy</label>
<input type='text' name='lifeExp' id='lifeExp' />
<br /><br />
<label for='gnp' id='lbl_gnp'>GNP</label>
<input type='text' name='gnp' id='gnp' />
<br /><br />
<label for='gnp_old' id='lbl_gnp_old'>GNP (old)</label>
<input type='text' name='gnp_old' id='gnp_old' />
<br /><br />
<label class='required' for='local_name' id='lbl_local_name'>* Local name</label>
<input type='text' name='local_name' id='local_name' maxlength='45' />
<br /><br />
<label class='required' for='govt' id='lbl_govt'>* Form of government</label>
<input type='text' name='govt' id='govt' maxlength='45' />
<br /><br />
<label for='HoS' id='lbl_HoS'>Head of state</label>
<input type='text' name='HoS' id='HoS' maxlength='60' />
<br /><br />
<label for='capital' id='lbl_capital'>Capital code</label>
<input type='text' name='capital' id='capital' />
<br /><br />
<label><a href='index.php'>Return to Selection Page</a></label>
<input type='submit' name='submit' value='Insert row' />
</form>
?>
The connect file has already been proven to work in my past projects so I know that's not the issue. I've compiled it and it also says thats not the issue. Any idea why it would not be inserting into the database? Or maybe a function I could add on to the end with an if statement that could check if it had actually been inserted?
Using INSERT in the fashion that you are, you must ensure that the contents of the VALUES () clause exactly match the number and order of columns in the table. If there are any columns that you are not including, even if they have default values or are autonumbered, the command will fail. Since you don't show any information about your table I don't know whether this is the source of your problem or not.
If it is the problem, you can use the full form of INSERT:
INSERT INTO county (col1, col2, col3) VALUES ($val1, $val2, $val3)
This form is highly recommended in any event as it makes no assumptions about the table (other than the names of the columns) and guards against the command failing from structural changes to the table later on.
I have problem with: I want to create admin for add questions to quiz system. Structure is:
<label>Question 1</label>
<input type='text' name='question' value=''/>
<label>Possible reply</label>
<input type='text' name='1' />
<input type='text' name='2' />
...
<input type='text' name='6' />
<label>**Correct reply</label>
<input type='text' name='correct' />
<label>Question 2 </label>
<input type='text' name='question' value=''/>
<label>Possible reply </label>
<input type='text' name='1' />
<input type='text' name='2' />
...
<input type='text' name='6' />
<label>Correct reply </label>
<input type='text' name='correct' />
<label>Question 3 </label>
...
<input type='submit' name='submit' value='submit'>
And I need multiple questions post to Mysql db tables: question, 1,2,3,4,5,6, correct.
I was create this:
<?php
if(isset($_POST['submit']))
{
$question $_POST['question '];
$a = $_POST['1'];
$b = $_POST['2'];
$c = $_POST['3'];
$d = $_POST['4'];
$e = $_POST['5'];
$f = $_POST['6'];
correct = $_POST['correct '];
$result=mysql_query("insert into test (question, 1, 2, 3, 4, 5, 6, correct) values ('$result', '$a', '$b', '$c', '$d', '$e', '$f', '$correct' )");
}
else
{
?>
<label>Question 1 </label>
<input type='text' name='question' value=''/>
<label>Possible reply </label>
<input type='text' name='1' />
<input type='text' name='2' />
...
<input type='text' name='6' />
<label>Correct reply </label>
<input type='text' name='correct' />
<label>Question 2 </label>
<input type='text' name='question' value=''/>
<label>Possible reply </label>
<input type='text' name='1' />
<input type='text' name='2' />
...
<input type='text' name='6' />
<label>Correct reply </label>
<input type='text' name='correct' />
<label>Question 3 </label>
...
<input type='submit' name='submit' value='submit'>
<?
}
But this send only 1 question to DB.
If you can't use
<input type='text' name='question_1' value=''/>
<input type='text' name='question_1' value=''/>
<input type='text' name='question_1' value=''/>
Write in HTML:
<input type='text' name='question[]' value=''/>
<input type='text' name='reply1[]' />
<input type='text' name='reply2[]' />
<input type='text' name='reply3[]' />
<input type='text' name='reply4[]' />
<input type='text' name='reply5[]' />
<input type='text' name='reply6[]' />
<input type='text' name='correct[]' />
In PHP:
<?php
if (isset($_POST['submit'])){
$questions=$_POST['question'];
$reply1=$_POST['reply1'];
$reply2=$_POST['reply2'];
$reply3=$_POST['reply3'];
$reply4=$_POST['reply4'];
$reply5=$_POST['reply5'];
$reply6=$_POST['reply6'];
$correct=$_POST['correct'];
foreach($questions as $key=>$value){
$result=mysql_query("insert into test (question, 1, 2, 3, 4, 5, 6, correct) values ('$value', '".$reply1[$key]."', '".$reply2[$key]."', '".$reply3[$key]."', '".$reply4[$key]."', '".$reply5[$key]."', '".$reply5[$key]."', '".$correct[$key]."' )");
}
}
It would be nice if you can state your database structure and expected result, because it may not work the way you think and we'll never know until we see it.
If you want 1 answer per row, you need to use a multiple row insertion - How to insert multiple rows in single insert statement?.
try that:
<input type='text' name='question1' value=''/>
<input type='text' name='question2' value=''/>
instead of
<input type='text' name='question1' value=''/>
<input type='text' name='question1' value=''/>