Select-option tag remains selected on refresh

Filip

I want to make a website about famous quotes and i want to add an "ADD Quote Section". I made the <form> like below, but i want when if someone forgets to select an author or an subject or to write his quote to display an error like in the error section bellow, but if he write the quote and forgot to select the author or the subject i want to display the error but keep the writed quote so the user will not be angry or something like this that he have to write again his quote. This code i want to apply to the select author and select subject too. The form will look like this: [Form add quote]: http://imgur.com/PN72ZcH.jpg

And another problem will be that on refresh that added quote is added again in mysql database and i want to be checked if that quote is added in database and if it is added to display an error 'This quote is already in the database'.


require("connection.php");

Here you select the name of the author:

echo '<select name="selauthor"><option>-Author-</option>';

$author=mysql_query('SELECT * FROM author ORDER BY  `name` ASC ');

while($linea=mysql_fetch_array($author)){

echo '<option value="'.$linea[0].'">'.$linea[1].'</option>';}

echo '</select>';

Here you select the quote subject(like love, friendship, peace)

echo '<select name="selsubject"><option>-Subject-</option>';

$subject=mysql_query('SELECT * FROM subject ORDER BY  `name` ASC ' );

while($lines=mysql_fetch_array($subject)){

echo '<option value="'.$lines[0].'">'.$lines[1].'</option>';}

echo '</select>';

And here you write your quote:

echo 'Write your quote:<input type="text" name="quote" value="">

<input type="submit" name="qtebut" value="Add Quote"><br /><br /><br />';

if(isset($_POST['qtebut'])){

$author=$_POST['selauthor'];

$subject=$_POST['selsubject'];

$quote=$_POST['quote'];

Errors:

if($author=='-Author-'){echo 'Choose Author.<br />';}

if($subject=='-Subject-'){echo 'Choose Subject.<br />';}

if($quote==''){echo 'Don`t forget to write your quote.<br />';}

if($quote!='' && $author!='-Author-' && $subject!='-Subject-'){

$insert=mysql_query('INSERT INTO `quotes` (`id_subject`, `id_author`, `quote`) 

VALUES ("'.$author.'", "'.$subject.'", "'.$quote.'")');

echo 'Quote added in the database';}
Srinu M

Try This This is HTML FORM:

<form>
<select name="selauthor" required="required">
<option value="">-Select Author-</option>
</select>
<select name="selsubject" required="required">
<option value="">-Select Subject-</option>
</select>
<input type="text" name="qtebut" value="" required="required">
<input type="submit" value="ADD quote" />
</form>

PHP CODE:

$author=$_POST['selauthor'];
$subject= $_POST['selsubject'];
$quote=$_POST['qtebut'];
if($author==''){echo 'Choose Author.<br />';}

if($subject==''){echo 'Choose Subject.<br />';}

if($quote==''){echo 'Don`t forget to write your quote.<br />';}

if($quote !='' && $author !='' && $subject!=''){

$insert=mysql_query('INSERT INTO `quotes` (`id_subject`, `id_author`, `quote`) 

VALUES ("'.$author.'", "'.$subject.'", "'.$quote.'")');
if($insert)
{
echo 'Quote added in the database';
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select-option tag remains selected on refresh

From Dev

If Select tag option is selected shows another select tag

From Dev

Displaying selected option from database in a select option tag

From Dev

Displaying selected option from database in a select option tag

From Dev

Select option selected an not selected

From Dev

Display table row based on the selected option of Select html tag

From Dev

"selected" tag on option doesn't work when select has formControlName

From Dev

Rails select tag option not being selected (using float data)

From Dev

jQuery>=1.9: Selecting an option in a select tag is not "fully" selected

From Dev

Get selected option from the tag <select> in php to use on if

From Dev

select_tag doesn't save the selected option

From Dev

How to have a select_tag with an "selected disabled hidden" option?

From Dev

Angular 2 one way binding removing selected option of select tag

From Dev

MVC form submit won send the select tag selected option

From Dev

remove option once is selected from many select tag

From Dev

Refresh Select Option

From Dev

keep option selected after a refresh

From Dev

keep option selected after a refresh

From Dev

Make <select> option selected

From Dev

How can I select using jQuery 'select' tag with determined selected option?

From Dev

Expanded Select & Option tag

From Dev

select tag has no option

From Dev

setting a select option by another select selected option

From Dev

jQuery not reading selected option after refresh

From Dev

How do I get the ng-model of a select tag to get the initially-selected option?

From Dev

Avoid same option selected multiple times using jquery except the first select tag

From Dev

Styling <select> tag when option has been selected [CSS3]

From Dev

Render select Tag from jQuery Ajax , then get the value from selected option

From Java

Set select option 'selected', by value

Related Related

  1. 1

    Select-option tag remains selected on refresh

  2. 2

    If Select tag option is selected shows another select tag

  3. 3

    Displaying selected option from database in a select option tag

  4. 4

    Displaying selected option from database in a select option tag

  5. 5

    Select option selected an not selected

  6. 6

    Display table row based on the selected option of Select html tag

  7. 7

    "selected" tag on option doesn't work when select has formControlName

  8. 8

    Rails select tag option not being selected (using float data)

  9. 9

    jQuery>=1.9: Selecting an option in a select tag is not "fully" selected

  10. 10

    Get selected option from the tag <select> in php to use on if

  11. 11

    select_tag doesn't save the selected option

  12. 12

    How to have a select_tag with an "selected disabled hidden" option?

  13. 13

    Angular 2 one way binding removing selected option of select tag

  14. 14

    MVC form submit won send the select tag selected option

  15. 15

    remove option once is selected from many select tag

  16. 16

    Refresh Select Option

  17. 17

    keep option selected after a refresh

  18. 18

    keep option selected after a refresh

  19. 19

    Make <select> option selected

  20. 20

    How can I select using jQuery 'select' tag with determined selected option?

  21. 21

    Expanded Select & Option tag

  22. 22

    select tag has no option

  23. 23

    setting a select option by another select selected option

  24. 24

    jQuery not reading selected option after refresh

  25. 25

    How do I get the ng-model of a select tag to get the initially-selected option?

  26. 26

    Avoid same option selected multiple times using jquery except the first select tag

  27. 27

    Styling <select> tag when option has been selected [CSS3]

  28. 28

    Render select Tag from jQuery Ajax , then get the value from selected option

  29. 29

    Set select option 'selected', by value

HotTag

Archive