Can someone help me please, I am trying to implement a simple php MySQL survey, but I am stuck on this, how do I store the specific selection in MySQL that users select.
How satisfied are you:
<table id="table1" rules="all" border="1" cellpadding="3" cellspacing="0" width="70%">
<colgroup width="70%"></colgroup>
<colgroup width="6%">
</colgroup>
<thead>
<tr align="center">
<th></th>
<th font="" style="font-size:9pt;" size="2"><b>Dissatisfied</b></th>
<th font="" style="font-size:9pt;" size="2"><b>Satisfied</b></th>
<th font="" style="font-size:9pt;" size="2"><b>Very Satisfied</b></th>
</tr>
</thead>
<tbody>
<tr align="center">
<td align="left"><font style="font-size:10pt;"><b>Technician's ability to understand the unique nature of your problem?</b></font></td>
<td><input name="satisfaction" value="Dissatisfied" type="radio"></td>
<td><input name="satisfaction" value="Satisfied" type="radio"></td>
<td><input name="satisfaction" value="Very Satisfied" type="radio"></td>
</tr>
<tr align="center">
</tbody>
</table>
for this what you need will need a form to submit data selection. You will need two php files
The first one is to built a form of radio buttons. I had removed table's elements for neat view then we set the URL of the second page .Can also be a single page if you want but this is more easier.
feedback.php
<form action="add.php" method="post" accept-charset="utf-8">
<input name="satisfaction" value="Dissatisfied" type="radio">Dissatisfied<br>
<input name="satisfaction" value="Satisfied" type="radio">Satisfied<br>
<input name="satisfaction" value="Very Satisfied" type="radio">Very Satisfied<br>
<input type='submit' value="submit">
</form>
In the second page we catch what we had posted from first page.
add.php
$result= $_POST['satisfaction'];
echo $result;
using $result to store in your database. Good luck
As simple as :
1st, Add this line before the table tag:
<form method="post" action="">
2nd, this one at the end of your code:
<input type="submit" name="submit" value="Submit">
</form>
Then you can have this code for inserting in the DB.
if ($stmt = $mysqli->prepare("INSERT INTO TABLENAME(COLUMN NAME) values (?)")) {
$stmt->bind_param('s', $satisfaction);
$satisfaction=$_POST['satisfaction'];
$stmt->execute();
$stmt->close();
}
Related
Query 1.
form submitting working fine in local , but not working in live. I removed the action and put # and also i didn't call any script for redirect but while click the submit button it is automatically redirect to the same page. i don't know how it is redirecting ?
Query 2.
In action i mentioned <?php echo $_SERVER['PHP_SELF']; ?> and also gave direct url . if i print the post value it is not coming to POST .
In both ways it is showing the error
This page isn’t working
www.XXXXXXXXXXX.com didn’t send any data.
here below i paste my short code
<?php
ob_start();
session_start();
$_SESSION['captcha'] = rand(1000,9999);
include("./config/dbconnect.php");
include("./functions/functions.php");
if($_POST){
print_r($_POST); exit;
}
?>
<table border="0" width="100%"><tr><td style="padding-left:25px">
<form name="register" method="post" action="#" enctype="multipart/form-data">
<table width="634" border="0">
<tr>
<td colspan="3" class="sub_heading"><div align="right"><span class="style_r">* Mandatory Fields</span></div></td>
</tr>
<tr>
<td height="24" colspan="3"><div align="left" class="sub_heading">Login Information</div></td>
</tr>
<tr>
<td width="178">Email<span class="style_r">*</span></td>
<td width="10">:</td>
<td width="432"><input type="text" name="email" width="14" maxlength="50" /></td>
</tr> ******************* etc <tr>
<td colspan="3"><input type="checkbox" name="terms" />
I have read, understood and agree to the Terms and Conditions of eGulfCareers.com</td>
</tr>
<tr>
<td width="178"></td>
<td width="10"></td>
<td width="432"><input type="hidden" name="register" value="1" />
<input type="submit" name="submit" value="Signup" class="submit_button" /></td>
</tr>
</table>
</form></td>
</tr>
</table> `
I'm expanding existing code to have an extra row in the database. I've added the row "Base" into the table. Everything but the new row shows up in the database
whats going wrong here?
The new row is varchar. I've sniffed the data and all the post data including the base info is in the post data being sent..the problem seems to be in the MySQL query.
This is the old code to enter the data
$query="INSERT INTO blah1 (UserID, Name, Date, Contact, Note, Izbrisan)
VALUES
('$_POST[userid]','$_POST[name]','$_POST[date]','$_POST[contact]','$_POST[note]',0)";
mysqli_query($query);
this is the new code
$query="INSERT INTO blah1 (UserID, Name, Date, Contact, Note, Base, Izbrisan)
VALUES
('$_POST[userid]','$_POST[name]','$_POST[date]','$_POST[contact]','$_POST[base]','$_POST[note]',0)";
mysqli_query($query);
here is the form i use to enter the data but the "base" portion of the info never makes it into the database.. whats going wrong here?
<html>
<body>
<center>
<form action="adduser2.php" method="post">
<table border="1">
<td colspan = "2"> <center> Add User</td>
<tr>
<td>UserID:</td>
<td> <input type="text" name="userid" value="<?php if(isset($_GET['Id'])) { echo $_GET['Id'];}?>" > </td>
</tr>
<tr>
<td>Name:</td>
<td> <input type="text" name="name"> </td>
</tr>
<tr>
<td>Date(dd:mm:yy):</td>
<td> <input type="text" name="date"> </td>
</tr>
<tr>
<td>Contact:</td>
<td> <input type="text" name="contact"> </td>
</tr>
<tr>
<td>Note:</td>
<td> <input type="text" name="note"> </td>
</tr>
<tr>
<td>Base:</td>
<td> <input type="text" name="base"> </td>
</tr>
<tr>
<td colspan = "2"> <center> <input type="submit" value="Dodadi Korisnik"> </td>
</tr>
</table>
</form>
</body>
</html>
You forgot the connection identifier for your mysql connection:
mysqli_query($link, $query);
See the documentation.
FYI, you are wide open to SQL injections
What I presently have is this code which displays all the invoices under a specific catalogue. On change of the catalogue dropdown, the table should be populated based on the selected dropdown value. The table displays the invoices pertaining to the selected catalogue with 3 textboxes for each recordset. And what I need is to validate those textboxes. Lets say there are 3 invoices/records for a specific catalogue, then there should be 9 textboxes.
The View Page contains:-
<script type="text/javascript">
$(document).ready(function(){
$('#catalogue').change(function(){
$.post('../controller/valuation.php', {catalogue:valuation_form.catalogue.value},
function(result){
$('#valuationResult').html(result).show();
})
});
});
</script>
<form action="" id="valuation_form" name="valuation_form">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16%">Catalogue Code</td>
<td width="15%">
<select name="catalogue" id="catalogue" style="width:75px;">
<option></option>
<?php
require_once '../model/catalogue.php';
#$result=Catalogue::getAllCatalogues();
while($value=mysql_fetch_assoc($result)){
?>
<option value="<?php echo $value['catalogue_id']; ?>">
<?php echo $value['catalogue_code'] ?>
</option>
<?php } ?>
</select>
</td>
</tr>
</table>
</form>
<div class="atable">
<form action="../controller/valuation.php" method="POST" enctype="multipart/form-data">
<div id="valuationResult"></div>
</form>
</div>
The Controller Page contains:-
function getValuationDetails(){
require_once '../model/sales.php';
$catalogue=$_POST['catalogue'];
$obj=new Sales();
$result=$obj->getValuationEntryLotsForCatalogue($catalogue);
#$num=mysql_num_rows(#$result);
if($num>0){
$table='<table id="tabled" class="tftable" border="1">
<thead>
<tr>
<th style="display:none" width="0%">INVOICE ID</th>
<th width="6%">LOT #</th>
<th width="15%">SELLING MARK</th>
<th width="9%">INVOICE #</th>
<th width="8%">PACKAGES</th>
<th width="8%">GRADE</th>
<th width="13%">NET WEIGHT(Kg)</th>
<th style="text-align:center">DESCRIPTION</th>
<th width="11%" style="text-align:center;">VALUATION </th>
</tr>
</thead>';
while($value=mysql_fetch_assoc($result)){
$table.='<tr>
<td style="display:none">
<input type="text" id="invoice" name="invoice[]" value="'.$value['invoice_id'].'"/>
</td>
<td>'.$value['lot_no'].'</td>
<td>'.$value['selling_mark'].'</td>
<td>'.$value['ref_invoice_no'].'</td>
<td>'.$value['no_of_packages'].'</td>
<td>'.$value['grade_desc'].'</td>
<td style="text-align:right;">'.$value['total_net_qty'].' </td>
<td>
<textarea style="width:270px;max-width:270px;" class="description" name="description[]"></textarea>
</td>
<td>
<input type="text" class="value1" name="value1[]" size="2">
<input type="text" class="value2" name="value2[]" size="2">
</td>
</tr>';
}
$table.='<tr><td colspan="9" style="text-align:right">
<input type="hidden" name="action" value="valuation_entry"/>
<input type="submit" name="save" id="save" value="Save"/>
<input type="reset" value="Clear"/>
</td></tr>';
echo $table;
}
else{
echo "";
}
}
The three textboxes/textareas are as follows:-
1. Description- textarea that allows only letters.
2. Value1- textbox that allows only numbers.
3. Value1- textbox that allows only numbers.
*All the 3 cannot be empty.
I have tried all sorts of options to try this but unfortunately I cannot figure out what and where I am missing.
Any help is very much appreciated!!!
Use class "required" to mark the fields that cannot be empty.
Then on Jquery you should loop through these elements:
var error = false;
$('.required').each(function(i){
if(!$(this).val()){
$(this).css('border', '2px solid red');
error = true;
}else{
$(this).css('border','1px solid #BBBBBB');
}
});
if(error) {
alert('All red fields are required!!!!!');
}
I am a bit new to PHP and forms. I'm trying to send some variables from one page to another in a PHP form.
This is the form:
<form name="dates" action="document_creation/7bform.php" method="post" onsubmit="return mandatoryFields()">
<table width="748" border="0" cellspacing="2" cellpadding="2">
<tr>
<td class="main_text">
<div align="right" class="main_text">*Contract Start Date:</div>
</td>
<td>
<input name="start_date" type="text" value="YYYY-MM-DD" maxlength="100" class="datepick" id="date1" />
</td>
</tr>
<tr>
<td class="main_text">
<div align="right" class="main_text">*Contract End Date:</div>
</td>
<td>
<input name="end_date" type="text" value="YYYY-MM-DD" maxlength="100" class="datepick" id="date2" />
</td>
</tr>
<tr>
<td height="36" colspan="2">
<table width="100" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="68"> <input name="submit" type="submit" id="Submit" value="Generate 7B Form" <?php if($disable ==1){?>disabled<?php }?>/></td>
<td width="48">
<label><input type="reset" name="reset" value="Reset" /></label>
</td>
<td width="46"><div align="center">Back</div></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
I want to pass start_date and end_date to another page document_creation/7bform.php and it's not working. document_creation/7bform.php looks like this:
<?php
$start_date = ($_POST['start_date']);
$end_date = ($_POST['end_date']);
When I try to print these variables, they come out as blank. Where am I going wrong?
Everything looks fine, so I think your function mandatoryFields() is returning false.
Other than that, you may want to use this on your retrieving page:
if(isset($_POST['start_date']) && !empty($_POST['start_date'])){
// now assign values
}
if(isset($_POST['end_date']) && !empty($_POST['end_date'])){
// now assign values
}
Also, just a helpful tip...
<?php if($disable ==1){?>disabled<?php }?>
That is VERY messy... You should use short-tags
<?=($disable==1 ? " disabled" : "")?>
And even further, 1 is TRUE, so you don't actually need it...
<?=($disable ? " disabled" : "")?>
Remove the parentheses around your $_POST call.
Also, you may want to consider sanitizing your strings. I know you're new, but whenever I teach someone PHP forms I always describe sanitary procedures first.
At #rckhoe, don't use short tags. Short tags are extremely buggy and dependent on browser variables.
You can read about sanitizing your input here. It's always good practice to use htmlspecialchars() and using parameterized queries is good too. It also wouldn't hurt to read up more on your PHP/SQL.
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
Here is the form that is confusing me
<h1>
Login
</h1>
<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>
Username:
</td>
<td>
<input type="text" name="user" maxlength="30">
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="pass" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2" align="left">
<input type="checkbox" name="remember">
<font size="2">
Remember me next time
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="sublogin" value="Login">
</td>
</tr>
<tr>
<td colspan="2" align="left">
Join
</td>
</tr>
</table>
</form>
I got the code from this tutorial and it works fine but i cant seem to understand where a/the form submit too if no action is present
If action is set to "" or if the action attribute is missing, the form submits to itself. That is, if your script is index.php, your form submits to index.php.
If the form's action attribute is either set to "" OR not specified, it will still default to action="self", thus the form will send to the address of the document containing the form.
So,
<form method="post">
<!-- IS THE SAME AS... -->
<form action="" method="post">
<!-- IS THE SAME AS... -->
<form action="self" method="post">
(Try it)
For reference, see the HTML standard 4.10.18.3 #8:
http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#form-submission-algorithm
default action for form submission is METHOD="GET" and ACTION="SELF"
you should use a form name
if the action is empty then it posts to itself.