How do I get value of cID on form submission - php

<img src="img/commentBelowIcon.png" width="26" height="26" class="left" /><h3>Add Comment</h3>
<?php if(!empty($_GET['pID'])) $the_pID = mysql_real_escape_string($_GET['pID']); $thedt = date("Y-m-d");?>
<form action="inc/q/prof.php?pID=<?php echo $the_pID; ?>" method="post" id="addition">
<div class="field required">
<select id="courseInfoDD" class="verifyText" name="courseInfoDD" tabindex="1">
<option disabled="disabled">Course...</option>
<?php while($row3 = $sth3->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row3['cID'] . ">" .$row3['prefix']." ".$row3['code']."</option>";}
?>
</select>
</div>
<div class="field required">
<select id="commQuarter" class="verifyText" name="commQuarter" tabindex="2" >
<option disabled="disabled">Quarter...</option>
<option value="Fall">Fall</option>
<option value="Winter">Winter</option>
<option value="Spring">Spring</option>
<option value="Summer">Summer</option>
</select>
</div>
<div class="field required">
<select id="commYr" name="commYr" class="verifyText" tabindex="3">
<option disabled="disabled">Year...</option>
<?php $startdate = 2000;$enddate = date("Y");$years = range ($startdate,$enddate);foreach($years as $year){echo "<option value='$year'>$year</option>";}?>
</select>
</div>
<div class="field required">
<select id="commExp" class="verifyText" name="commExp" tabindex="4" >
<option disabled="disabled">Overall Experience</option>
<option value="1">Positive</option>
<option value="2">Neutral</option>
<option value="3">Negative</option>
</select>
</div>
<div class="field required">
<textarea type="text" id="addComment" class="verifyText" name="addComment" tabindex="5" value="Enter comment"></textarea></div>
<input type="hidden" name="dt" value="<?php echo $thedt; ?>" />
<input type="hidden" name="pID" value="<?php echo $the_pID; ?>" />
<div class="field required">
Accept Terms?
Yes: <input type="radio" name="terms" value="Yes" id="accepting" tabindex="6" />
No: <input type="radio" name="terms" value="No" id="accepting" tabindex="7" />
</div>
<p class="iferror">Please correct the above.</p>
<input type="submit" name="submit" id="submit" tabindex="8" />
</form>
</div>
</div>
<?php // Get select box options
$pID3 = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
$pdo3 = new PDO('mysql:host=###;dbname=###', $u, $p);
$pdo3->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth3 = $pdo3->prepare('
SELECT pID, C.cID, C.prefix, C.code
FROM Department D, Course C, Professor P
WHERE pID = ?
AND D.dID = C.dID
AND D.dID = P.dID;
');
$sth3->execute(array(
$pID3
));
?>
I get submitted data that looks like this:
How do I get a value for cID to submit as well? Can someone show me what I need to put in my php?
Thanks

execute
$cid = mysql_insert_id();
after
$sth3->execute(array(
$pID3
));
link http://php.net/manual/en/function.mysql-insert-id.php
hope helps
:)

Related

How to display a selected option in `drop-down menu` in a PHP update form?

I have to display a selected option in the drop down list preview, but currently when extracting the value from the database it only shows one option and not the other from the database.
Is there a way to show the actual drop down list option when extracting the known value from the database (PgAdmin)(All code is either HTML,CSS or PHP)
Basically, I want it show the value in the database as the selected option in the Drop-Down menu, as you probably see in the below code I have tried but I am not too sure how to progress further from this point. Also feel free to correct me on errors within my code. I am aware it is a bit to digest but hopefully this will be answered soon :)
<?php
$conn = pg_connect("host=localhost port=5432 dbname=cafe user=postgres password=password");
if(count($_POST)>0) {
pg_query($conn,"UPDATE cakesweetorder set id='$_POST[id]',
firstname='$_POST[firstname]',
surname='$_POST[surname]',streetno='$_POST[streetno]',
streetname='$_POST[streetname]',
state = '$_POST[state]', suburb='$_POST[suburb]',
postcode='$_POST[postcode]', email='$_POST[email]',
mobno='$_POST[mobno]',colour='$_POST[colour]',
toping='$_POST[toping]',
chocosentence='$_POST[chocosentence]',
quantity='$_POST[quantity]', date='$_POST[date]',
file='$_POST[file]',
tea='$_POST[tea]'
WHERE id='$_POST[id]' ");
$message = "Record Modified Successfully";
}
$result = pg_query($conn,"SELECT * FROM cakesweetorder WHERE id='" . $_GET['id'] . "'");
$row= pg_fetch_array($result);
?>
<html>
<head>
<?php
include_once 'head.php';
?>
<p>
<div class='text-box'>
<div class='wrapper-glass'>
<div class='shape-1'></div>
<div class='shape-2'></div>
<div class='shape-3'></div>
<div class='shape-4'></div>
<div class='shape-5'></div>
<div class='shape-6'></div>
<div class='shape-7'></div>
<div class='shape-8'></div>
<div class='shape-9'></div>
<div class='shape-10'></div>
<div class='container-glass'>
<title>Cafe Database</title>
</head>
<body>
<form name="frmUser" method="post" action="">
<div><?php if(isset($message)) { echo $message; }
?>
</div>
ID: <br>
<input type="hidden" name="id" class="txtField" value="<?php echo $row['id']; ?>">
<input readonly='readonly' name="id" value="<?php echo $row['id']; ?>">
<br>
<legend>Name</legend>
Firstname:<div class="bar"><div class="text-bar"><input type="text" class="form-control" name="firstname" id="name" placeholder="Firstname..." value="<?php echo $row['firstname']; ?>"required/></div></div>
Surname:<div class="bar"><div class="text-bar2"><input type="text" class="form-control" name="surname" id="name" placeholder="Surname..." value="<?php echo $row['surname']; ?>"required/></div></div>
<legend>Address For Delivery</legend>
Street No: <div class="bar"><div class="text-bar3"><input type="number" id="text-bar" class="form-control" name="streetno" placeholder="Street No..." value="<?php echo $row['streetno']; ?>"required/><br/></div></div>
Street: <div class="bar"><div class="text-bar4"><input type="text" id="text-bar" class="form-control" name="streetname" placeholder="Street Name..." value="<?php echo $row['streetname']; ?>"required/><br/></div></div>
State:
State:
<div class="bar"><div class="text-bar5"><select id="state" class="form-control" name="state" value="<?php echo $row['state']; ?>" name="state"></div></div>
<optgroup label="States">
<option value="NSW">NSW</option>
<option value="QLD">QLD</option>
<option value="VIC">VIC</option>
<option value="SA">SA</option>
<option value="NT">NT</option>
<option value="TAS">TAS</option>
</select><br></div></div>
Suburb: <div class="bar"><div class="text-bar6"><input type="text" class="form-control" name="suburb" placeholder="Suburb..." value="<?php echo $row['suburb']; ?>" required/><br/></div></div>
Postcode: <div class="bar"><div class="text-bar7"><input type="number" class="form-control" name="postcode" placeholder="Postcode..." value="<?php echo $row['postcode']; ?>" required/><br/></div></div>
<legend>Personal Details</legend>
Email:<div class="bar"><div class="text-bar8"> <input type="email" class="form-control" name="email" placeholder="Email..." value="<?php echo $row['email']; ?>" required/><br/></div></div>
Phone Number: <div class="bar"><div class="text-bar9"><input type="number" class="form-control" name="mobno" placeholder="Phone Number..." value="<?php echo $row['mobno']; ?>"required/><br/></div></div>
Colour of Cake: <div class="input-color-container">
<div class="bar"><div class="text-bar11"><input id="input-color" name="colour" class="input-color" type="color" value="<?php echo $row['colour']; ?>"></div></div>
</div>
<label class="input-color-label" for="input-color">
</label>
Topings: <br><br>
<label class="checkbox-container">
<input type="checkbox" name="toping" <?php if(isset($_POST['toping']) && $_POST['toping'] = 'Vanilla') echo "checked" ?> value="<?php echo $row['toping']; ?>"><span class="checkmark"></span><span class="checkbox-txt"> Vanilla</span><br/></br></label>
<label class="checkbox-container">
<input type="checkbox" name="toping" <?php if(isset($_POST['toping']) && $_POST['toping'] = 'Chocolate') echo "checked" ?> value="<?php echo $row['toping']; ?>"><span class="checkmark"></span><span class="checkbox-txt" >Chocolate</span><br/></br></label>
<label class="checkbox-container">
<input type="checkbox" name="toping" <?php if(isset($_POST['toping']) && $_POST['toping'] = 'Caramel') echo "checked" ?> value="<?php echo $row['toping']; ?>"><span class="checkmark"></span><span class="checkbox-txt" >Caramel</span><br/></br></label>
<label class="checkbox-container">
<input type="checkbox" name="toping" <?php if(isset($_POST['toping']) && $_POST['toping'] = "Strawberry") echo "checked" ?> value="<?php echo $row['toping']; ?>"><span class="checkmark"></span><span class="checkbox-txt" >Strawberry</span><br/></br></label>
<label class="checkbox-container">
<input type="checkbox" name="toping" <?php if(isset($_POST['toping']) && $_POST['toping'] = "M&M's") echo "checked" ?> value="<?php echo $row['toping']; ?>"><span class="checkmark"></span><span class="checkbox-txt" >M&M's</span><br/></br></label>
<label class="checkbox-container">
<input type="checkbox" name="toping" <?php if(isset($_POST['toping']) && $_POST['toping'] = "Oreo") echo "checked" ?> value="<?php echo $row['toping']; ?>"><span class="checkmark"></span><span class="checkbox-txt" >Oreo</span><br/></br></label>
<label class="checkbox-container">
<input type="checkbox" name="toping" <?php if(isset($_POST['toping']) && $_POST['toping'] = "Meringue") echo "checked" ?> value="<?php echo $row['toping']; ?>"><span class="checkmark "></span><span class="checkbox-txt" >Meringue</span><br/></label>
Chocolate Sentences: <div class="bar"><div class="text-bar12"><input type="text" class="form-control" name="chocosentence" placeholder="Chocolate sentence..." value="<?php echo $row['chocosentence']; ?>"/><br/></div></div>
Quantity of Cakes or Sweets: <div class="bar"><div class="text-bar13"><input type="number" class="form-control" min="1" value="1" max="10" name="quantity" placeholder="Quantity..." value="<?php echo $row['quantity']; ?>" required/><br/></div></div>
Complimentary Tea: <br>
<div class="container">
<input type="radio" name="tea" value="true" <?php if(isset($_POST['tea']) && $_POST['tea'] = 't') echo "checked" ?>value="<?php echo $row['tea']; ?>">
<label for="tea" class="label1">
<span>YES</span>
</label>
<input type="radio" name="tea" <?php if(isset($_POST['tea']) && $_POST['tea'] = 'f') echo "checked" ?>value="<?php echo $row['tea']; ?>">
<label for="tea" class="label2">
<span>NO</span>
</label>
</div>
<br><br><br><br><br>
<legend>Miscellaneos</legend>
Date Of Delivery: <div class="bar"><div class="text-bar14"><input type="date" class="form-control" name="date" placeholder="Date of Delivery..." value="<?php echo $row['date']; ?>" required/><br/><br><br></div></div>
Custom Order with Instructions: <input type="file" class="form-control" name="file" placeholder="Custom Order..." /><br/>
OR Type in Instructions:
<div class="container3">
<div class="bar"><div class="text-bar15"><textarea id="my-text" name="file" rows="5" placeholder="Type Custom Order Here.." value="<?php echo $row['file']; ?>" ></textarea>
<p id="result"></p>
</div></div></div>
<br>
<input type="submit" name="submit" class='signup-btn' value="Submit" class="button">
</form>
</body>
</html>TAS</option>
</select><br></div></div>’
I have tried something like this but it didn’t really work: (Below), Its a very vague attempt but as I said before it doesn’t work I can’t really figure it out
`<?php
$db = pg_connect("host=localhost port=5432 dbname=SRIS user=postgres password=password");
$result = pg_query($db, "SELECT * FROM customer where customer_id = '$_POST[customer_id]'");
$row = pg_fetch_assoc($result);
 
// isset is set to submit in line 14
if (isset($_POST['submit']))
{
 
if ($row[pref_gender] == 'M') {
echo "</br>";
$statement1 = "<option value='M' selected>Male</option>
<option value='F'>Female</option>";
}        
 
if ($row[pref_gender] == 'F') {
echo "</br>";
$statement1 = "<option value='F' selected>Female</option>
<option value='M'>Male</option>";
}        
 
// retrieves one row of data from the table and displays the fields in the form
// Book id is a primary key so we can't edit it        
echo "<p>
 
<form name='update' action='enter_primarykey.php' method='POST' >
<li>Customer Id</li><li><input type='text' name='customer_id_updated' value='$row[customer_id]' /></li>
 
<li>Firstname</li><li><input type='text' name='firstname_updated' value='$row[firstname]' /></li>
<li>Surname</li><li><input type='text' name='surname updated' value='$row[surname]' /></li>
 
<li>Gender</li>
<li>
<select name='pref_gender_updated'>
$statement1                
</select>
</li>
 
<li><input type='submit' name='new' /></li>  </form>
</p>";
}
 
// isset is set to new in line 37
// uses the primary key to save all the values back into the database when submit is clicked
if (isset($_POST['new']))
{
$result1 = pg_query($db, "UPDATE customer SET firstname = '$_POST[firstname_updated]',
surname = '$_POST[surname_updated]', pref_gender = '$_POST[pref_gender_updated]' WHERE customer_id= '$_POST[customer_id_updated]'”);`
Below is what I want to change. When displaying the extracted data from the table I want it to show 'QLD' instead it shows the default 'NSW', how do I adapt the code to do this?
`State:
<div class="bar"><div class="text-bar5"><select id="state" class="form-control" name="state" value="<?php echo $row['state']; ?>" name="state"></div></div>
<optgroup label="States">
<option value="NSW">NSW</option>
<option value="QLD">QLD</option>
<option value="VIC">VIC</option>
<option value="SA">SA</option>
<option value="NT">NT</option>
<option value="TAS">TAS</option>
</select><br></div></div>`
It will look somewhat like this:
PHP
//Do Query (In your case, we can use $row['states']
HTML
`State:
<div class="bar">
<div class="text-bar5">
<select id="state" class="form-control" name="state" name="state"></div></div>
<optgroup label="States">
<option value="NSW" <?php if($row['states'] == 'NSW')echo 'selected'; ?> >NSW</option>
<option value="QLD" <?php if($row['states'] == 'QLD')echo 'selected'; ?> >QLD</option>
<!-- VIC will be selected -->
<option value="VIC" <?php if($row['states'] == 'VIC')echo 'selected'; ?> >VIC</option>
<!-- VIC will be selected -->
<option value="SA" <?php if($row['states'] == 'SA')echo 'selected'; ?> >SA</option>
<option value="NT" <?php if($row['states'] == 'NT')echo 'selected'; ?> >NT</option>
<option value="TAS" <?php if($row['states'] == 'TAS')echo 'selected'; ?> >TAS</option>
</select><br>
</div>
</div>`
You can do it in very simple way.
<?php $row= ("Your SQL QUERY WITH CONNECTION AND EXECUTION"); ?>
<div>
<div>
<select id="select_state" name="state" name="state"></div></div>
<optgroup label="States">
<option value="NSW" <?php if($row['states'] == 'NSW')echo 'selected'; ?> >NSW</option>
<option value="QLD" <?php if($row['states'] == 'QLD')echo 'selected'; ?> >QLD</option>
<option value="VIC" <?php if($row['states'] == 'VIC')echo 'selected'; ?> >VIC</option>
<option value="SA" <?php if($row['states'] == 'SA')echo 'selected'; ?> >SA</option>
<option value="NT" <?php if($row['states'] == 'NT')echo 'selected'; ?> >NT</option>
<option value="TAS" <?php if($row['states'] == 'TAS')echo 'selected'; ?> >TAS</option>
</select><br>
</div>
</div>
This also seemed to work!
PHP
$result = pg_query($conn,"SELECT * FROM cakesweetorder WHERE id='" . $_GET['id'] . "'");
$row= pg_fetch_array($result);
if ($row['state'] == 'NSW') {
echo "</br>";
$statement1 = "<option value='NSW' selected>NSW</option>
<option value='QLD'>QLD</option>
<option value='VIC' >VIC</option>
<option value='SA'>SA</option>
<option value='NT'>NT</option>
<option value='TAS'>TAS</option>";
}
if ($row['state'] == 'QLD') {
echo "</br>";
$statement1 = "<option value='QLD' selected>QLD</option>
<option value='NSW'>NSW</option>
<option value='VIC' >VIC</option>
<option value='SA'>SA</option>
<option value='NT'>NT</option>
<option value='TAS'>TAS</option>";
}
if ($row['state'] == 'VIC') {
echo "</br>";
$statement1 = "<option value='VIC' selected>VIC</option>
<option value='NSW' >NSW</option>
<option value='QLD'>QLD</option>
<option value='SA'>SA</option>
<option value='NT'>NT</option>
<option value='TAS'>TAS</option>";
}
if ($row['state'] == 'SA') {
echo "</br>";
$statement1 = "<option value='SA' selected>SA</option>
<option value='NSW'>NSW</option>
<option value='QLD'>QLD</option>
<option value='VIC'>VIC</option>
<option value='NT'>NT</option>
<option value='TAS'>TAS</option>";
}
if ($row['state'] == 'NT') {
echo "</br>";
$statement1 = " <option value='NT' selected>NT</option>
<option value='NSW'>NSW</option>
<option value='QLD'>QLD</option>
<option value='VIC'>VIC</option>
<option value='SA'>SA</option>
<option value='TAS'>TAS</option>";
}
if ($row['state'] == 'TAS') {
echo "</br>";
$statement1 = "<option value='TAS' selected>TAS</option>
<option value='NSW'>NSW</option>
<option value='QLD'>QLD</option>
<option value='VIC'>VIC</option>
<option value='SA'>SA</option>
<option value='NT'>NT</option>"
;
}
HTML
State: <br>
<select id='state' class='form-control' name='state'>
$statement1
</select>
"

Show DIV based on form value

I have a database driven table where the last column in the table contains a form that repeats for each row. I want to have a day_inperson field show if the value in the spring_2021_status field is equal to "Both" Since the form is repeated on the page, it doesn't work.
Here is my code for the repeating form. The form itself works fine and inserts into the database. Just need the one field to show if it meets the value of "Both":
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" id="spring_2021_status" name="spring_2021_status">
<option></option>
<option value="In Person" <?php if (!(strcmp('In Person', ($survey->getColumnVal("spring_2021_status"))))) { echo "selected=\"selected\"";} ?>>In Person</option>
<option value="Remote" <?php if (!(strcmp('Remote', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>Remote</option>
<option value="Both" <?php if (!(strcmp('Both', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>Both</option>
<option value="N/A" <?php if (!(strcmp('N/A', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>N/A</option>
</select>
<br>
<script>
$('#spring_2021_status').on('change',function(){
if( $(this).val()==="Both"){
$("#update_status2").show()
}
else{
$("#update_status2").hide()
}
});
</script>
<div class="row" id="update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
<?php echo($survey->getColumnVal("notes")); ?></textarea>
</div>
<input type="hidden" value="<?php echo($survey->getColumnVal("theein")); ?>" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>
You can use class selector inside your div update_status2 then whenever your select-box gets change use $(this).closest('form').find().. this line will get closest form from select-box and then find your div which you need to show/hide.
Demo Code :
//onchange of sleect
$('[name=spring_2021_status]').on('change', function() {
if ($(this).val() === "Both") {
//get closest form tag and then find your div
$(this).closest('form').find(".update_status2").show()
} else {
$(this).closest('form').find(".update_status2").hide()
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" name="spring_2021_status">
<option></option>
<option value="In Person" selected>In Person</option>
<option value="Remote">Remote</option>
<option value="Both">Both</option>
<option value="N/A">N/A</option>
</select>
<br>
<!--added class-->
<div class="row update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
something...</textarea>
</div>
<input type="hidden" value="abc" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" name="spring_2021_status">
<option></option>
<option value="In Person" selected>In Person</option>
<option value="Remote">Remote</option>
<option value="Both">Both</option>
<option value="N/A">N/A</option>
</select>
<br>
<div class="row update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
something...</textarea>
</div>
<input type="hidden" value="abc" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>

Capturing form data from multiple checkboxes with associated textboxes

I have an html form that has lots of fields, and I have built a PHP form handler to email the results of the form to me.
The only part I am having trouble with is, I have a list of checkboxes with an associated text field for each.
In my email, I want a list of ONLY the items that are checked, with the contents of the text box. For Example, 360 - qty 10
Here are a few of the items and the code for them:
<form action="form_handler2.php" method="POST">
<div class="one_third first">
<label for="first_name"><b>First Name</b> <span>*</span></label>
<input type="text" name="first_name" id="first_name" value="" size="22" required>
</div>
<div class="one_third">
<label for="last_name"><b>Last Name</b> <span>*</span></label>
<input type="text" name="last_name" id="last_name" value="" size="22" required>
</div>
<div class="one_third first">
<label for="phone"><b>Phone #</b> <span>*</span></label>
<input type="text" name="phone" id="phone" value="" size="22" required>
</div>
<div class="one_third">
<label for="email"><b>Email</b> <span>*</span></label>
<input type="email" name="email" id="email" value="" size="22" required>
</div>
<div class="two_thirds first">
<label for="business_name"><b>Business Name (type personal if not affiliated with a business)</b> <span>*</span></label>
<input type="text" name="business_name" id="business_name" value="" size="59" required>
</div>
<div class="two_thirds first">
<label for="address_1"><b>Address 1</b></label>
<input type="text" name="address_1" id="address_1" value="" size="59" >
</div>
<div class="two_thirds first">
<label for="address_2"><b>Address 2</b></label>
<input type="text" name="address_2" id="address_2" value="" size="59" >
</div>
<div class="one_third first">
<label for="city"><b>City</b></label>
<input type="text" name="city" id="city" value="" size="22" >
</div>
<div class="one_third">
<label for="state"><b>State</b></label>
<select name="state" id="state">
<option value="">- select -</option>
<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="IA">IA</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="MA">MA</option>
<option value="MD">MD</option>
<option value="ME">ME</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MO">MO</option>
<option value="MS">MS</option>
<option value="MT">MT</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="NE">NE</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NV">NV</option>
<option value="NY">NY</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VA">VA</option>
<option value="VT">VT</option>
<option value="WA">WA</option>
<option value="WI">WI</option>
<option value="WV">WV</option>
<option value="WY">WY</option>
</select>
</div>
<div class="one_third first">
<label for="zip"><b>Zip</b></label>
<input type="text" name="zip" id="zip" value="" size="10" >
</div>
<div class="one_third first">
<label for="country"><b>Country</b></label>
<select name="country" id="country">
<option value="">- select -</option>
<option value="US">US</option>
</select>
</div>
<div class="two_thirds first">
<label for="reason"><b>Reason for Contact</b> <span>*</span></label>
Note: sample requests for businesses using Abralon pads in their current business <br>practice only. Limit one pad per grit type, max 3 pads per sample
<select name="reason" id="reason" required>
<option value="">- select -</option>
<option value="Order">Order</option>
<option value="Reorder">Re-order</option>
<option value="Sample">Sample Request</option>
<option value="Information">Information Request</option>
<option value="Feedback">Feedback/Comment</option>
<option value="Other">Other</option>
</select>
</div>
<div class="two_thirds first">
<b>Order/Sample Request - </b>Select grits and quantity. Full boxes are 20 count. <br>Orders of 20 or more qualify for lower pricing. Orders of 60 or more pads are <br>automatically upgraded to priority mail.
</div>
<div class="inline-field">
<input type="checkbox" name="grit[]" value="180">
<label for="180"> 180
<input id="180_qty" name="180_qty" type="text" placeholder="Qty" size="5" class="180_qty">
</label><br>
</div>
<div class="inline-field">
<input type="checkbox" name="grit[]" value="360">
<label for="360"> 360
<input id="360_qty" name="360_qty" type="text" placeholder="Qty" size="5" class="360_qty">
</label><br>
</div>
<div class="inline-field">
<input type="checkbox" name="grit[]" value="500">
<label for="500"> 500
<input id="500_qty" name="500_qty" type="text" placeholder="Qty" size="5" class="500_qty">
</label><br>
</div>
<div class="inline-field">
<input type="checkbox" name="grit[]" value="1000">
<label for="1000"> 1000
<input id="1000_qty" name="1000_qty" type="text" placeholder="Qty" size="5" class="1000_qty">
</label><br>
</div>
<div class="inline-field">
<input type="checkbox" name="grit[]" value="2000">
<label for="2000"> 2000
<input id="2000_qty" name="2000_qty" type="text" placeholder="Qty" size="5" class="2000_qty">
</label>
<br>
</div>
<div class="inline-field">
<input type="checkbox" name="grit[]" value="3000">
<label for="3000"> 3000
<input id="3000_qty" name="3000_qty" type="text" placeholder="Qty" size="5" class="3000_qty">
</label>
<br>
</div>
<div class="inline-field">
<input type="checkbox" name="grit[]" value="4000">
<label for="4000"> 4000
<input id="4000_qty" name="4000_qty" type="text" placeholder="Qty" size="5" class="4000_qty">
</label><br>
</div>
<div class="two_thirds first">
<label for="comment"><b>Comments/Special Instructions</b></label>
<textarea name="comment" id="comment" cols="59" rows="5"></textarea>
</div>
<br>Order will be confirmed by email with pricing. Payment information must be<br> received via phone or fax prior to shipment.
<br><br>
<b>NOTE: Fields with "*" are required</b><br><br>
<div class="inline-field">
<input type="checkbox" name="abranet_info" value="abranet_info">
<label for="abranet_info"> I would like information on Abranet pads
</label><br>
</div>
<div class="inline-field">
<input type="checkbox" name="newsletter" value="newsletter" checked>
<label for="newsletter"> Sign me up for your quarterly newsletter on Abralon and related products
</label><br>
</div> <br>
<div>
<input type="submit" name="submit" value="Submit Form">
<input type="reset" name="reset" value="Reset Form">
</div>
</form>
My php is:
<?php
$field_first_name = $_POST['first_name'];
$field_last_name = $_POST['last_name'];
$field_phone = $_POST['phone'];
$field_email = $_POST['email'];
$field_business_name = $_POST['business_name'];
$field_address_1 = $_POST['address_1'];
$field_address_2 = $_POST['address_2'];
$field_city = $_POST['city'];
$field_state = $_POST['state'];
$field_zip = $_POST['zip'];
$field_country = $_POST['country'];
$field_reason = $_POST['reason'];
$field_comment = $_POST['comment'];
$mail_to = 'xxx#xxx.com';
$subject = 'XXX - '.$field_reason;
$body_message = 'Name: '.$field_first_name.' '.$field_last_name."\n";
$body_message .= 'Business Name: '.$field_business_name."\n";
$body_message .= 'E-mail: '.$field_email."\n\n";
$body_message .= 'Phone: '.$field_phone."\n\n";
$body_message .= 'Address: '.$field_address_1."\n";
$body_message .= ' '.$field_address_2."\n";
$body_message .= ' '.$field_city.', '.$field_state.' '.$field_zip.' '.$field_country."\n\n";
$body_message .= 'Comment: '.$field_comment."\n";
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
window.location = 'success.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
window.location = 'failure.html';
</script>
<?php
}
?>
You don't have the php for the "grit," which I assume is the part you're concerned about.
However what I think you want to do, is name each grit checkbox like
<input type="checkbox" name="grit3000" value="3000">
And then in the PHP you will want to have an if statement for each
if (isset($_POST['grit3000']) {
$body_message .= 'Grit3000 CHECKED \n';
}

Dependent dropdown

i have a problem in dependent dropdown and i am not professional in this issue
so the problem is when i choose the first one the another one doesnt get any value from database and i didnt know the solution
<?php
include 'header.php';
require 'connection.php';
?>
<div class="container">
<form id="contact" action="add_line.php" method="post">
<center> <h3>Add Line</h3></center>
<fieldset>
<?php
require 'connection.php';
$query = "select * from agents";
$result = mysqli_query($conn,$query);
?>
<div class="select">
<select class="agents-name " name="agents-name" autofocus tabindex="1">
<option selected="selected">--Select agent--</option>
<?php while ($row = mysqli_fetch_assoc($result)): ?>
<option value="<?php $row['id'];?>"><?php echo $row['name'];?></option>
<?php endwhile;?>
</select>
</div>
<div class="select" >
<select tabindex="1" name="sp_choosen" class="sp_choosen"
onChange="getState( this.value );" tabindex="2">
<option selected="selected">--Select service provider--</option>
<option value="CELLCOM">CELLCOM</option>
<option value="HoTMobile">HoTMobile</option>
<option value="Orange">Orange</option>
<option value="Pelphone">Pelphone</option>
<option value="Golan">Golan</option>
<option value="019">019</option>
</select>
</div>
<div class="select">
<select id="packet_select" name="packet_chossen" tabindex="3">
<option selected="selected">--Select packet--</option>
</select>
</div>
</fieldset>
<fieldset>
<input placeholder="customer name" type="text" tabindex="4"
name="customer_name" required >
</fieldset>
<fieldset>
<input placeholder="SIM_SERIAL" type="tel" tabindex="5" name="sim_serial"
required >
</fieldset>
<fieldset>
<input placeholder="phone_number" type="tel" tabindex="6" name="number"
required >
</fieldset>
<fieldset>
<label></label>
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit" tabindex="7" >Add
Available line</button>
</fieldset>
</form>
</div>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
function getState(val) {
$.ajax({
type: "POST",
url: "dropdown_add_line.php",
data:'sp='+val,
success: function(data){
$("#packet_select").html(data);
}
});
}
</script>
<?php
include 'footer.php';
?>
and this is the dropdown_add_line.php :
<?php
require_once("connectione.php");
$db_handle = new DBController();
if(!empty($_POST["sp"])) {
$sp=$_POST['sp'];
$query ="SELECT * FROM packets p WHERE sp LIKE '%$sp%'";
$results = $db_handle->runQuery($query);
?>
<option value="">--Select service provider--</option>
<?php
foreach($results as $packets) {
?>
<option value= "<?php echo $packets["id"]; ?>" ><?php echo $packets["packet"]; ?></option>
<?php
}
}
?>
and the table name is "packets" and the columns is "id","sp","packet"

Validating the form from redirecting it to next page in php

I have created a form where user enters a number and month. When the number and month entered is not stored in database it should display a alert box saying details is not valid. iF if the details matches it as to redirect it to next page.My code redirects to next page if the details doesnt match too. how to solve this. Here is the code
<div id="col1" align="center"><br />
<form method="post" action="modifypay3.php">
<label type="text" name="name" maxlength="50" size="30" class="label">Enter the Membership Number which You want to edit</label><br />
<input type="text" name='uid' placeholder="enter Membership Number" class="input" size="40"/><br />
<span class="field">(* Required field)</span><br /><br />
<label type="text" name="month" maxlength="50" size="30" class="label">Select Month in which u want to edit</label><br />
<select name="month" placeholder="" class="input" style="width: 380px;" >
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select><br/><br/>
<input type="submit" name="submit" value="SUBMIT" class="button"><br /><br /><br /><br />
</form>
</div>
<?php
mysql_connect("localhost","root","");
mysql_select_db("anthonys");
if(isset($_POST['submit'])) {
$uid= $_POST['uid'];
if( ! ctype_alnum($uid) )
die('invalid id');
$month=$_POST['month'];
$query = "SELECT uid,month FROM `payment` WHERE uid ='$uid' and month='$month'";
$run = mysql_query($query);
if(mysql_num_rows($run)==1) {
echo "<script>window.open('modifypay3.php?uid=".$uid."','_self')</script>";
} else {
echo "<script>alert('Membership No is Invalid!')</script>";
}
}
?>
In your form action call modifypay3.php page
<form method="post" action="modifypay3.php">
Edit the form action like this
<form method="post" action="#">
replace
<form method="post" action="modifypay3.php">
to
<form method="post" action="">
<div id="col1" align="center"><br />
<form method="post" action="">
<label type="text" name="name" maxlength="50" size="30" class="label">Enter the Membership Number which You want to edit</label><br />
<input type="text" name='uid' placeholder="enter Membership Number" class="input" size="40"/><br />
<span class="field">(* Required field)</span><br /><br />
<label type="text" name="month" maxlength="50" size="30" class="label">Select Month in which u want to edit</label><br />
<select name="month" placeholder="" class="input" style="width: 380px;" >
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select><br/><br/>
<input type="submit" name="submit" value="SUBMIT" class="button"><br /><br /><br /><br />
</form>
</div>
<?php
mysql_connect("localhost","root","");
mysql_select_db("anthonys");
if(isset($_POST['submit'])) {
$uid = trim($_POST['uid']);
if( !ctype_alnum($uid) )
die('invalid id');
$month=trim($_POST['month']);
$query = "SELECT `uid`,`month` FROM `payment` WHERE `uid` ='".$uid."' and `month`='".$month."' LIMIT 1";
$run = mysql_query($query);
if(mysql_num_rows($run)==1) {
header("Location:modifypay3.php?uid=".$uid."");
} else {
echo "<script>alert('Membership No is Invalid!')</script>";
}
}
?>

Categories