How to fix "Notice: Undefined index: message in" [duplicate] - php

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 3 years ago.
I am new to PHP and trying to make a form which will email me. However, I am getting an error when submitting it.
I have pasted the form HTML and PHP for it below, any help I can get is appreciated.
<form style="text-align: center; border: 1px solid black;" action="" method="post" id="form">
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="title_text">TITLE</label>
</div>
</div>
<div class="col-md-8">
<div>
<select id="title" name="title" style="margin-top: 5px;">
<option value="">Please select</option>
<option value="Mr">Mr</option>
<option value="Mr">Mrs</option>
<option value="Mr">Mx</option>
<option value="Mr">Ms</option>
<option value="Mr">Miss</option>
<option value="Mr">Dr</option>
</select>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="name_text" style="margin-top: 3px;">First Name *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="text" id="first_name" name="first_name" style="margin-top: 5px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="last_text" style="margin-top: 3px;">Last Name *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="text" id="last_name" name="last_name" style="margin-top: 5px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="dept_text" style="margin-top: 3px;">Department *</label>
</div>
</div>
<div class="col-md-8">
<div>
<select id="dept" name="dept" style="margin-top: 5px;">
<option value="">Please select</option>
<option value="Mr">Mr</option>
<option value="Mr">Mrs</option>
<option value="Mr">Mx</option>
<option value="Mr">Ms</option>
<option value="Mr">Miss</option>
<option value="Mr">Dr</option>
</select>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="job" style="margin-top: 3px;">Job Title *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="text" id="job" name="job" style="margin-top: 5px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="start" style="margin-top: 3px;">Start Date *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="date" id="start" name="start" style="margin-top: 5px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="manager" style="margin-top: 3px;">Manager *</label>
</div>
</div>
<div class="col-md-8">
<select id="manager" name="manager" style="margin-top: 5px;" required>
<option value="">Please select</option>
<option value="Mr">Mr</option>
<option value="Mr">Mrs</option>
<option value="Mr">Mx</option>
<option value="Mr">Ms</option>
<option value="Mr">Miss</option>
<option value="Mr">Dr</option>
</select>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="location" style="margin-top: 3px;">Location *</label>
</div>
</div>
<div class="col-md-8">
<select id="location" name="location" style="margin-top: 5px;" required>
<option value="">Please select</option>
<option value="Mr">Mr</option>
<option value="Mr">Mrs</option>
<option value="Mr">Mx</option>
<option value="Mr">Ms</option>
<option value="Mr">Miss</option>
<option value="Mr">Dr</option>
</select>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="nwc" style="margin-top: 3px;">Now We Comply *</label>
</div>
</div>
<div class="col-md-8">
<select id="nwc" name="nwc" style="margin-top: 5px;" required>
<option value="">Please select</option>
<option value="Mr">Mr</option>
<option value="Mr">Mrs</option>
</select>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="vdq" style="margin-top: 3px;">VQD? Which instance? *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="text" id="vdq" name="vdq" style="margin-top: 8px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="phone" style="margin-top: 3px;">Phone Extention *</label>
</div>
</div>
<div class="col-md-8">
<select id="phone" name="phone" style="margin-top: 5px;" required>
<option value="">Please select</option>
<option value="Mr">Yes</option>
<option value="Mr">No</option>
</select>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="hardware" style="margin-top: 3px;">IT Hardware *</label> //come back to this
</div>
</div>
<div class="col-md-8">
<div class="checkbox">
<label><input type="checkbox" if="keyboard" value="keyboard">Keyboard</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="mouse" value="mouse">Mouse</label>
</div>
<div class="checkbox disabled">
<label><input type="checkbox" id="laptop" value="laptop">Laptop</label>
</div>
<div class="checkbox disabled">
<label><input type="checkbox" id="desktop" value="desktop">Desktop</label>
</div>
<div class="checkbox disabled">
<label><input type="checkbox" id="monitor" value="monitor">Monitor</label>
</div>
<div class="checkbox disabled">
<label><input type="checkbox" id="docking_station" value="docking_station">Docking Station</label>
</div>
<div class="checkbox disabled">
<label><input type="checkbox" id="case" value="case">Laptop Case</label>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="login" style="margin-top: 3px;">AD log in *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="text" id="login" name="login" style="margin-top: 5px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="password" style="margin-top: 3px;">Password *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="password" id="password" name="password" style="margin-top: 5px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="email" style="margin-top: 3px;">Email Address(es) *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="text" id="email" name="email" style="margin-top: 5px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="disgroup" style="margin-top: 3px;">Distribution Groups *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="text" id="disgroup" name="disgroup" style="margin-top: 5px;" required>
</div>
</div>
</div>
<div class="row spacing-top">
<div class="col-md-4">
<div>
<label id="access" style="margin-top: 3px;">Drive & Folder Access *</label>
</div>
</div>
<div class="col-md-8">
<div>
<input type="text" id="access" name="access" style="margin-top: 5px;" required>
</div>
</div>
</div>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$to = "MY EMAIL"; // this is your Email address
$from = "ANOTHER EMAIL"; // this is the sender's Email address
$title = $_POST['title'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$dept = $_POST['dept'];
$job = $_POST['job'];
$start = $_POST['start'];
$manager = $_POST['manager'];
$location = $_POST['location'];
$nwc = $_POST['nwc'];
$vdq = $_POST['vdq'];
$phone = $_POST['phone'];
$login = $_POST['login'];
$password = $_POST['password'];
$email = $_POST['email'];
$disgroup = $_POST['disgroup'];
$access = $_POST['access'];
$subject = "New Starter";
$message = "Here is the new starter details" . "\n\n" . $title . "\n" . $first_name . "\n" .
$last_name . "\n" . $dept . "\n" . $job . "\n" . $start . "\n" . $manager . "\n" .
$location . "\n" . $nwc . "\n" . $vdq . "\n" . $phone. $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
This is the error I am getting when I click submit "Notice: Undefined index: message in /storage/ssd1/948/10446948/public_html/index.php on line 355"

There is no value/missing for $_POST['message']. You may need to insert in your html in order to get them. Thats why it is issuing you with an undefined index.
<input type="textarea" name="message">
in your php code:
$user_message = $_POST['message'];
in your last line of $message put .$user_message
Hope this helps and if your mail function does not work, you may need a mail server configuration to enable the send email function in your php code. All the best and happy coding!

Related

Redirect in same page and display message to user

I would like when the user is filling up the form and click the button to get redirected in the same page and throw him the message "Everything went well, Thank you!"
For now i only do it with action="mail_handler.php" but it goes to the other php file and displays the message in other blank page.
Is there any way to use the functionality of mail_handler.php but without nagivating there?
I tried action="" and before the button<?php include 'mail_handler.php'; ?> but with no success
Index.html form:
<!-- The Form Section -->
<div style="background-color: #5A5377" id="form_section">
<h2 class="w3-wide" align="Center"><font color="white"><strong><br>Přihláška</strong></font></h2>
<form align="center" name="form1" action="" method="post" enctype="multipart/form-data">
<ul class="errorMessages"></ul>
<div class="row">
<div class="col">
<label for="fname"><font color="white"><strong>Jméno</strong></font></label></div>
<div class="col">
<input type="text" id="fname" name="fname" value="" required="required"><br></div>
</div>
<div class="row">
<div class="col">
<label for="lname"><font color="white"><strong><br>Příjmení</strong></font></label></div>
<div class="col">
<input type="text" id="lname" name="lname" value required="required"div>
</div>
<div class="row">
<div class="col">
<label for="vysoho"><font color="white"><strong><br>Vysoká škola</strong></font></label></div>
<div class="col">
<input type="text" id="vysoka_skola" name="vysoka_skola" value="" required="required"></div>
</div>
<div class="row">
<div class="col">
<label for="fname"><font color="white"><strong><br>Studijní obor</strong></font></label></div>
<div class="col">
<input type="text" id="obor" name="obor" value="" required="required"></div>
</div>
<div class="row">
<div class="col">
<label for="prace"><font color="white"><strong><br>Odkaz na bakalářskou práci</strong></font></label></div>
<div class="col">
<input type="text" id="prace" name="prace" value="" required="required"></div>
</div>
<div class="row">
<div class="col">
<label for="myfile"><font color="white"><strong><br>Bakalářská práce</strong></font></label></div>
<div class="col">
<input type="file" id="myfile" name="myfile[]" multiple="multiple" required="required"></div>
</div>
<div class="row">
<div class="col">
<label for="dropdown"><font color="white"><strong><br>Kategorie v soutěži</strong></font></label></div>
<div class="col">
<select id="kategorie" name="kategorie" required="required">
<option value="science">Science</option>
<option value="technology">Technology</option>
<option value="science">Engineering</option>
<option value="science">Mathematics</option>
</select>
</div>
<br>
</div>
<div class="row">
<div class="col"><input type="checkbox" id="gdpr" name="gdpr" value="" required="required">
<label for="gdpr"><font color="white"><strong> I agree with GDPR</strong></font></label></div>
</div>
<div class="row">
<div class="col">
<?php include 'mail_handler.php'; ?>
<input type="submit" name="submit" value="Poslat"><br><br></div>
</div>
</form>
</div>
</div>
<!--END OF FORM-->
mail_handler.php
<?php
if(isset($_POST['submit'])){
$to = "alex#gmail.com"; // this is your Email address
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$skola = $_POST['vysoka_skola'];
$obor = $_POST['obor'];
$prace = $_POST['prace'];
$files = $_FILES['myfile']['name'];
$kategorie = $_POST['kategorie'];
//echo gettype($files);
$all_thesis_string="";
for($index=0;$index<count($_FILES['myfile']['name']);$index++){
$all_thesis_string.=$_FILES['myfile']['name'][$index].","; //create a string with all bachelor attachments of user
}
$subject = "Form submission of ".$first_name." ".$last_name;
$message = "User Details: \n\n Jméno: $first_name \n Příjmení: $last_name \n Vysoká škola: $skola \n Studijní obor: $obor \n Odkaz na bakalářskou práci: $prace \n Kategorie: $kategorie \n Bakalářská práce: $all_thesis_string";
$headers = "From:" . $first_name;
mail($to,$subject,$message,$headers);
echo "Přihláška úspěšně odeslána. Děkuji " . $first_name . ".\n \n";
include 'upload.php';
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
As Ken Lee suggested in the comments, the best way of doing this is to use mail_handler.php itself as a form action. This will become your index.php:
<?php
if(isset($_POST['submit'])){
$to = "alex#gmail.com"; // this is your Email address
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$skola = $_POST['vysoka_skola'];
$obor = $_POST['obor'];
$prace = $_POST['prace'];
$files = $_FILES['myfile']['name'];
$kategorie = $_POST['kategorie'];
//echo gettype($files);
$all_thesis_string="";
for($index=0;$index<count($_FILES['myfile']['name']);$index++){
$all_thesis_string.=$_FILES['myfile']['name'][$index].","; //create a string with all bachelor attachments of user
}
$subject = "Form submission of ".$first_name." ".$last_name;
$message = "User Details: \n\n Jméno: $first_name \n Příjmení: $last_name \n Vysoká škola: $skola \n Studijní obor: $obor \n Odkaz na bakalářskou práci: $prace \n Kategorie: $kategorie \n Bakalářská práce: $all_thesis_string";
$headers = "From:" . $first_name;
mail($to,$subject,$message,$headers);
echo "Přihláška úspěšně odeslána. Děkuji " . $first_name . ".\n \n";
include 'upload.php';
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
<!-- The Form Section -->
<div style="background-color: #5A5377" id="form_section">
<h2 class="w3-wide" align="Center"><font color="white"><strong><br>Přihláška</strong></font></h2>
<form align="center" name="form1" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
<ul class="errorMessages"></ul>
<div class="row">
<div class="col">
<label for="fname"><font color="white"><strong>Jméno</strong></font></label></div>
<div class="col">
<input type="text" id="fname" name="fname" value="" required="required"><br></div>
</div>
<div class="row">
<div class="col">
<label for="lname"><font color="white"><strong><br>Příjmení</strong></font></label></div>
<div class="col">
<input type="text" id="lname" name="lname" value required="required"div>
</div>
<div class="row">
<div class="col">
<label for="vysoho"><font color="white"><strong><br>Vysoká škola</strong></font></label></div>
<div class="col">
<input type="text" id="vysoka_skola" name="vysoka_skola" value="" required="required"></div>
</div>
<div class="row">
<div class="col">
<label for="fname"><font color="white"><strong><br>Studijní obor</strong></font></label></div>
<div class="col">
<input type="text" id="obor" name="obor" value="" required="required"></div>
</div>
<div class="row">
<div class="col">
<label for="prace"><font color="white"><strong><br>Odkaz na bakalářskou práci</strong></font></label></div>
<div class="col">
<input type="text" id="prace" name="prace" value="" required="required"></div>
</div>
<div class="row">
<div class="col">
<label for="myfile"><font color="white"><strong><br>Bakalářská práce</strong></font></label></div>
<div class="col">
<input type="file" id="myfile" name="myfile[]" multiple="multiple" required="required"></div>
</div>
<div class="row">
<div class="col">
<label for="dropdown"><font color="white"><strong><br>Kategorie v soutěži</strong></font></label></div>
<div class="col">
<select id="kategorie" name="kategorie" required="required">
<option value="science">Science</option>
<option value="technology">Technology</option>
<option value="science">Engineering</option>
<option value="science">Mathematics</option>
</select>
</div>
<br>
</div>
<div class="row">
<div class="col"><input type="checkbox" id="gdpr" name="gdpr" value="" required="required">
<label for="gdpr"><font color="white"><strong> I agree with GDPR</strong></font></label></div>
</div>
<div class="row">
<div class="col">
<input type="submit" name="submit" value="Poslat"><br><br></div>
</div>
</form>
</div>
</div>
<!--END OF FORM-->
In the PHP script you can display whatever message you want to by just adding echo
Your second option is to target the form to an iframe:
<iframe name="myframe" id="frame1" src="thankyou.php" style="display:none"></iframe>
<form action="../thankyou.php" method="post" target="myframe">
<input type="submit" name="DoIt" value="DoIt">
</form>

create a shortcode of html form

I am trying to create a short code for html form. because I want to use this multiple time in my word-press page.
I have no idea how to do this . if any help please let help me
<form action="<?php echo get_page_link(2599) ?>" method="POST" >
<input type='hidden' name='page_id' value='2599'>
<div class="row">
<div class="form-group col-sm-3 col-md-2" id="bgform_text2">
<h4>SEARCH</h4>
<p>For Your Favourite Place</p>
</div>
<div class="form-group col-sm-5 col-md-2">
<label>Where to ? </label>
<input type="text" name="names" class="input-text full-width" placeholder="start typing here....">
</div>
<div class="form-group col-sm-5 col-md-4">
<div class="row">
<div class="col-xs-6">
<label>Arrive </label>
<div class="controls">
<input type="text" name="arive_time" id="departing">
</div>
</div>
<div class="col-xs-6">
<label>Departs </label>
<div class="controls">
<input type="text" name="depart_time" id="returning">
</div>
</div>
</div>
</div>
<div class="form-group col-sm-9 col-md-2">
<label>Sleeps </label>
<div class="controls">
<i class="fa fa-sort"></i>
<select name="sleeps">
<option value="" disabled="" selected=""></option>
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></option>
</select>
</div>
</div>
<div class="form-group col-sm-3 col-md-2">
<input type="submit" value="submit" name="submit_btn" class="button">
</div>
</div>
</form>
Try this.
<?php
function my_shortcode(){
$pagelink = get_page_link(2599);
return '<form action="'.$pagelink.'" method="POST" >
<input type="hidden" name="page_id" value="2599">
<div class="row">
<div class="form-group col-sm-3 col-md-2" id="bgform_text2">
<h4>SEARCH</h4>
<p>For Your Favourite Place</p>
</div>
<div class="form-group col-sm-5 col-md-2">
<label>Where to ? </label>
<input type="text" name="names" class="input-text full-width" placeholder="start typing here....">
</div>
<div class="form-group col-sm-5 col-md-4">
<div class="row">
<div class="col-xs-6">
<label>Arrive </label>
<div class="controls">
<input type="text" name="arive_time" id="departing">
</div>
</div>
<div class="col-xs-6">
<label>Departs </label>
<div class="controls">
<input type="text" name="depart_time" id="returning">
</div>
</div>
</div>
</div>
<div class="form-group col-sm-9 col-md-2">
<label>Sleeps </label>
<div class="controls">
<i class="fa fa-sort"></i>
<select name="sleeps">
<option value="" disabled="" selected=""></option>
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></option>
</select>
</div>
</div>
<div class="form-group col-sm-3 col-md-2">
<input type="submit" value="submit" name="submit_btn" class="button">
</div>
</div>
</form>';
}
add_shortcode('my_shortcode_name','my_shortcode');
?>
you can use this shortcode in your page
<?php echo do_shortcode('[my_shortcode_name]');?>
I think you are saying that you do not want to copy-paste the exact same code on multiple places inside your project, PHP has an include control structure method to take any file and use the contents on run-time.
Your code could eventually look something like this:
# form definition inside the main page that needs the form
<form action="<?php echo get_page_link(2599) ?>" method="POST" >
# include the template
<?php include('template.php') ?>
</form>
# template.php contains the html form
<input type='hidden' name='page_id' value='2599'>

Bootstrap nav-tabs not working with php script

My nav-tabs works fine using static data for my dropdown list but when I add the script to populate the dropdown list, the tabs don't work anymore.
I don't think there's any problem with the query since the list gets populated. Probably with the echo?
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active">Boarding House Info</li>
<li>Other Info</li>
<li>Location</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_1">
<div class="box-body">
<div class="form-group">
<label for="boarding-house-name">Boarding House Name</label>
<input type="text" class="form-control" id="bh-name" name="bh-name" placeholder="boarding house name">
</div>
<div class="form-group" style="margin-bottom:50px">
<label for="price">Price</label><br>
<div class="col-md-2" style="margin-left:-15px;">
<input type="text" class="form-control" id="pricemin" name="bh-pricemin" placeholder="min">
</div>
<div class="col-md-2" style="margin-left:-15px;">
<input type="text" class="form-control" id="pricemax" name="bh-pricemax" placeholder="max">
</div>
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" name="bh-address" placeholder="address">
</div>
<div class="form-group">
<label for="barangay">Barangay</label>
<select class="form-control" name="bh-barangay">
<option value="Brgy 1">Brgy 1</option>
<option value="Brgy 2">Brgy 2</option>
<option value="Brgy 3">Brgy 3</option>
<option value="Brgy 4">Brgy 4</option>
</select>
</div>
<div class="form-group">
<label for="contactperson">Contact Person</label>
<input type="text" class="form-control" id="contactperson" name="bh-contactperson" placeholder="contact person">
</div>
<div class="form-group">
<label for="contactnumber">Contact Number</label>
<input type="text" class="form-control" id="contactnumber" name="bh-contactnumber" placeholder="contact number">
</div>
<div class="form-group">
<label for="owner">Owner</label>
<select class="form-control" name="bh-owner-id">
<?php
$query = "SELECT id_owner, owner_name FROM tbl_owner";
$result = $conn->query($query) or die("Connection failed: " . $conn->connect_error);
while($row = mysqli_fetch_assoc($result)) {
echo "<option value='".$row['id_owner']."'>".$row['owner_name']."</option>";
} mysql_free_result($result);
?>
</select>
</div>
</div>
</div>
<div class="tab-pane" id="tab_2">
<div class="box-body">
<div class="form-group">
<label for="tenant" style="margin-bottom:-15px;">Tenant</label>
<div class="checkbox">
<label class="checkbox-inline">
<input type="checkbox" id="tenant_checkbx" value="Male"> Male
</label>
<label class="checkbox-inline">
<input type="checkbox" id="tenant_checkbx" value="Female"> Female
</label>
</div>
</div>
<div class="form-group" style="margin-bottom:50px">
<label for="specification">Specification</label><br>
<div class="col-md-6" style="margin-left:-15px;">
<select class="form-control">
<option>Boarding House</option>
<option>Dormitory</option>
<option>Apartelle</option>
<option>Lodge</option>
<option>Motel</option>
</select>
</div>
</div>
<div class="form-group" style="margin-bottom:50px">
<label for="noofrooms">No. of Rooms</label><br>
<div class="col-md-6" style="margin-left:-15px;">
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="# of rooms">
</div>
</div>
<div class="col-md-2">
<div class="form-group" style="margin-left:-15px;">
<label for="curfew">Curfew</label>
<div class="radio">
<label>
<input type="radio" name="curfew_radio" id="curfew_yes" value="Yes" checked> Yes
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="curfew_radio" id="curfew_no" value="No"> No
</label>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group" style="margin-left:-15px;">
<label for="guests">Guests</label>
<div class="radio">
<label>
<input type="radio" name="guests_radio" id="guests_yes" value="Yes" checked> Yes
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="guests_radio" id="guests_no" value="No"> No
</label>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group" style="margin-left:-15px;">
<label for="crtype">CR Type</label>
<div class="checkbox">
<label>
<input type="checkbox" id="crtype_checkbx" value="Private"> Private
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="crtype_checkbx" value="Public"> Public
</label>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="tab_3">
<div class="box-body">
<!-- INSERT MAP HERE -->
</div>
</div>
</div>
</div>
Here is the query php script I used to populate the owner dropdown list:
<?php
$query = "SELECT id_owner, owner_name FROM tbl_owner";
$result = $conn->query($query) or die("Connection failed: " . $conn->connect_error);
while($row = mysqli_fetch_assoc($result)) {
echo "<option value='".$row['id_owner']."'>".$row['owner_name']."</option>";
} mysql_free_result($result);
?>
It's working now. Did some more debugging with the script and it seems like the line:
mysql_free_result($result);
(after the while condition) is the culprit.
I removed it and the tabs are working now. :)

input to sql not ok with 'copy-paste'

i have a php form, that adds a 'review' to a 'guide' in an SQL database.
i finally figured out my problem, and it is when i use copy paste in the input areas.
what can cause this??
any help appreciated!!
this is the link
this is my code:
<body >
<form class="form-horizontal" method="POST" >
<div class="form-group" >
<div class="col-sm-1">
<a href="." > <img src="Pictures/Design/בחזרה לאתר.png" height="100" width="100"/> </a>
</div>
<div class="col-sm-10">
<h2>הוספת ביקורת ל: <?php if(isset($_SESSION ['name'])){echo $_SESSION ['name'];} else {echo $gname;}?></label>
</h2>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-12 " >
<div class="col-sm-4 " align="right">
<?php $val="uploads/guides/".$row['Picture'];?>
<image src='<?php echo $val;?>' height="130px" width="100px">
</div>
<div class="col-sm-7 " align="right">
<div><label class=" control-label" ><?php if(isset($_SESSION ['name'])){echo $_SESSION ['name'];} else {echo $gname;}?></label><label class=" control-label" >&nbsp&nbsp&nbsp:שם המדריך</label></div>
<div><label class=" control-label" ><?php if(isset($_SESSION ['attraction'])){echo $_SESSION ['attraction'];} else {echo $gattraction;}?></label><label class=" control-label" >&nbsp&nbsp&nbsp:אטרקציה</label></div>
<div><label class=" control-label" ><?php if(isset($_SESSION ['email'])){echo $_SESSION ['email'];} else {echo $gemail;}?></label><label class=" control-label" >&nbsp&nbsp&nbsp:אימייל</label></div>
<div><label class=" control-label" ><?php if(isset($_SESSION ['phone'])){echo $_SESSION ['phone'];} else {echo $gphone;}?></label><label class=" control-label" >&nbsp&nbsp&nbsp:טלפון</label></div>
</div>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-12 " >
<div class="col-sm-6 col-sm-offset-6" align="right">
<label class=" control-label" >שמך המלא</label>
</div>
<div class="col-sm-12">
<input type="text" class="form-control" name="name" placeholder="" />
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 " >
<div class="col-sm-6 col-sm-offset-6" align="right">
<label class=" control-label" >מתי השתמשת בשירותי המדריך</label>
</div>
<div class="col-sm-6 " align="right">
<select class="form-control" name="year">
<option value="בחר/י שנה">בחר/י שנה</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
</select>
</div>
<div class="col-sm-6 " align="right">
<select class="form-control" name="month">
<option value="בחר/י חודש">בחר/י חודש</option>
<option value="ינואר">ינואר</option>
<option value="פברואר">פברואר</option>
<option value="מרץ">מרץ</option>
<option value="אפריל">אפריל</option>
<option value="מאי">מאי</option>
<option value="יוני">יוני</option>
<option value="יולי">יולי</option>
<option value="אוגוסט">אוגוסט</option>
<option value="ספטמבר">ספטמבר</option>
<option value="אוקטובר">אוקטובר</option>
<option value="נובמבר">נובמבר</option>
<option value="דצמבר">דצמבר</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 " >
<div class="col-sm-6 col-sm-offset-6" align="right">
<label class=" control-label" >ציון 1-5</label>
</div>
<div class="col-sm-3 col-sm-offset-9 " align="right">
<select class="form-control " name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 " >
<div class="col-sm-6 col-sm-offset-6" align="right">
<label class=" control-label" >כמה שילמת ומה זה כלל</label>
</div>
<div class="col-sm-12">
<textarea class="form-control" name="pay" cols="40" rows="2"></textarea>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 " >
<div class="col-sm-6 col-sm-offset-6" align="right">
<label class=" control-label" >פרטו את חוויתכם עם המדריך בהרחבה</label>
</div>
<div class="col-sm-12">
<textarea class="form-control" name="exp" cols="40" rows="5" required></textarea>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 " >
</div>
</div>
<div class="form-group" >
<div class="col-sm-12 col-sm-offset-5"><button type="submit" class="btn btn-primary btn-sm" name="addreview" value="Submit Record">הוספת ביקורת</button></div>
</div>
<?php
if(isset($_POST['addreview'])){
$name = $_POST['name'];
$name = str_replace("'","''",$name);
$monthh = $_POST['month'];
$yearr = $_POST['year'];
$pay = $_POST['pay'];
$pay = str_replace("'","''",$pay);
$exp= $_POST['exp'];
$exp = str_replace("'","''",$exp);
$rating=$_POST['rating'];
$query1="INSERT INTO review (ReviewerName,ServiceMonth,ServiceYear,Rating,Payment,Experience,Guide_ID) VALUES ";
$query1.="('$name','$monthh','$yearr','$rating','$pay','$exp','$guideid')";
$result=mysqli_query($conn,$query1);
if($result){
?>
<script type="text/javascript">
window.location = "./review_added_successfully.php";
</script>
<?php
}
else{
echo "not submitted";
}
} ?>
</form>
</body>

how to create multiple query in one. when i want fetch date from database which is search from user

here my html code.
i want fetch data from database. when a user search profile then i want display only searched data which enter in form.
the problem is query doesn't work. can you tell me can we run multiple query in single query.
<form method="get" action="search.php" enctype="multipart/form-data">
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Gender : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<select name="gender">
<option value="">Select Gender</option>
<option value="">Male</option>
<option value="">Female</option>
</select>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Marital Status : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<select name="mstatus">
<option>Select status</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
<option value="Widow">Widow</option>
<option value="Widower">Widower</option>
<option value="Divorcee">Divorcee</option>
<option value="Seprated">Seprated</option>
</select>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Gotra : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<select name="gotra">
<option>Select gotra</option>
<option value="Aalakuntor">Aalakuntor</option>
<option value="Bantalor">Bantalor</option>
<option value="Batalor">Batalor</option>
<option value="Bayamuttalor">Bayamuttalor</option>
</select>
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">District / City : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<input type="text" class="form-control" placeholder="city" name="city" >
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Education : </label>
<div class="col-sm-7 form_radios">
<div class="select-block1">
<input type="text" class="form-control" placeholder="education" name="education" >
</div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-2 control-lable1" for="sex">Age : </label>
<div class="col-sm-7 form_radios">
<div class="col-sm-5 input-group1">
<input class="form-control has-dark-background" name="age1" id="slider-name" placeholder="28" type="text" >
</div>
<div class="col-sm-5 input-group1">
<input class="form-control has-dark-background" name="age2" id="slider-name" placeholder="40" type="text" >
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<div class="col-sm-5 input-group1">
<div class="select-block1">
<input type="submit" class="btn btn-success" value="Search" name="search">
</div>
</div>
<div class="clearfix"> </div>
</div>
</form>
here my search.php code.
<div class="paid_people">
<h1></h1>
<div class="row_1">
<?php
include("includes/db.php");
global $con;
if(isset($_GET['search']))
{
$search_gender = $_GET['gender'];
$search_mstatus = $_GET['mstatus'];
$search_gotra = $_GET['gotra'];
$search_city = $_GET['city'];
$search_education = $_GET['education'];
$search_age1 = $_GET['age1'];
$search_age2 = $_GET['age2'];
$get_user = "SELECT * FROM users WHERE age BETWEEN '$search_age1' AND '$search_age2' AND gender like '$search_gender' AND mstatus like '$search_mstatus' AND gotra like '$search_gotra' AND education like '$search_education' AND city like'$search_city'";
$run_user = mysqli_query($con, $get_user);
while ($row_user = mysqli_fetch_array($run_user))
{
$u_id = $row_user['user_id'];
$u_fname = $row_user['first_name'];
$u_age = $row_user['age'];
$u_education = $row_user['education'];
$u_occupation = $row_user['occupation'];
$u_city = $row_user['city'];
$u_image = $row_user['photo'];
$profile_id = $row_user['profile_id'];
echo "<div class='col-sm-6 paid_people-left'>
<ul class='profile_item'>
<a href='view_profile.php?userdetail_id=$u_id'>
<li class='profile_item-img'>
<img src='admin_vadarshadi/users-photo/resized_$u_image' class='img-responsive' alt='$u_fname' />
</li>
<li class='profile_item-desc'>
<h4>Profile ID: $profile_id</h4>
<h4>Name: $u_fname Age: $u_age Yrs </h4>
<p>City: $u_city, Education: $u_education</p>
<h5>View Full Profile</h5>
</li>
<div class='clearfix'> </div>
</a>
</ul>
</div>";
}
}
?>
</div>
</div>

Categories