jquery form inserting with php - php

please help find the sourse of my codes issue...when I click request the page just refreshes with all the data gone but nothing is inserted into the db...
here is the image of the db and the code! what do I need to change to be able to insert the data along with the username of the logged in user?
![the database]http://imgur.com/t0DrlHH
#user1151316 I made the changes and here is the code removing the pointless comments...the data is not being inserted and after submitting I get a blank screen...
<?php
//require_once 'includes/dbconnect.php';
session_start();
if (isset($_POST["request"]))
{
//print_r($_POST);die;
//take care of injections
$service = mysqli_real_escape_string($link,$_POST['service']);
$service_details = mysqli_real_escape_string($link,$_POST['service_details']);
$duedate = mysqli_real_escape_string($link,$_POST['duedate']);
$postdate = mysqli_real_escape_string($link,$_POST['postdate']); //READ ONLY DATE POST
// Insert data into mysql + LOGGED IN USERS USERNAME TO BE INSERTED
$sql = "INSERT INTO serviceposts VALUES ('".$_SESSION["username"]."','".$service."', '".$service_details."', '".$duedate."', '".$postdate."')";
$result= $link -> query($sql) or die (mysqli_error($link));
echo "($result)";
// if successfully insert data into database, displays message "Successful".
if($result){
echo "request post success!";
echo'<script>window.location="http://localhost/Project2/User.php#viewrequests";</script>';
}
else {
echo "Possible data input error";
}
$link->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="includes/js/modernizr.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="jqueryAssets/jquery.mobile.icons.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/Mobi~Style~Me.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.icons-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.datepicker.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
body,td,th {
font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
color: #303;
}
body {
background-image: url();
}
</style>
<link href="jqueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
a {
font-weight: bolder;
}
</style>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="jqueryAssets/jquery-ui.min.js"></script>
<script src="jqueryAssets/jquery-2.1.1.min.js"></script>
<script src="jqueryAssets/jquery.mobile-1.4.5.min.js"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.dialog.custom.min.js"></script>
<script src="jqueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.datepicker.custom.min.js" type="text/javascript"></script>
<title>MyITjobs</title>
<meta charset="utf-8">
</head>
<body>
<div data-role="page" id="servicerequest" data-theme="c">
<div data-role="header" data-add-back-btn="true"><h4>IT~Service Request</h4></div>
<span align="center"><?php if (isset($_SESSION["username"]))
{
echo "".$_SESSION["username"]."";
}
?>
</span>
<div data-role="content" class="ui-field-contain" align="center" data-content-theme="c">
<form style="align-items:justify" method="post" action="" id="servicerequest">
<input type="hidden" name="service" id="selected_service"/>
<span>
<select name="selectmenu" required class="ui-bar-c slidedown" id="service" data-collapsed="false" onchange="onchangeservice()">
<option selected="selected" class="ui-selectmenu-placeholder">IT-Services</option>
<option value="service1" id="MobileApps">Mobile Apps Development</option>
<option value="service2" id="WebDev">Website Development</option>
<option value="service3" id="Programming">Programming</option>
</select>
</span>
<br>
<span>
<div data-role="fieldcontain">
<label for="service_details">IT~Service Request Details</label>
<textarea name="service_details" cols="35" rows="6" id="service_details" placeholder="Input Request details"></textarea>
</div>
</span>
<span>
<label for="duedate">Set Due Date:</label>
<input type="datetime-local" required name="duedate" id="duedate" data-mini="true">
</span>
<br>
<span>
<label for="datetime-local">Request Date</label>
<DateTime id="postdate" data-mini="true">
<?php
$postdate = date("Y-m-d, H:i");
echo "$postdate";
?>
</span>
<input type="hidden" name="postdate" value="<?php echo $postdate; ?>"/>
<br>
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<button type="submit" data-icon="check" data-iconshadow="true" data-iconpos="left" id="request" name="request">Request</button></div>
<div class="ui-block-b">
<button type="reset" data-icon="delete" data-iconshadow="true" data-iconpos="left">Cancel</button>
</div>
</fieldset>
<script>
function onchangeservice()
{
var service_option = $( "#service option:selected" ).text();
$('#selected_service').val(service_option);
}
</script>
</form>
</div>
<div data-role="footer" data-theme="c" align="center">
</div>
</div>
</body>
</html>

Do below steps to resolve the issue :
Add a new hidden field
<input type="hidden" name="service" id="selected_service"/>
Add onchange function to select box as
<select name="selectmenu" required class="ui-bar-c slidedown" id="service" data-collapsed="false" onchange="onchangeservice()">
Replace your script into function
function onchangeservice()
{
var service_option = $( "#service option:selected" ).text();
$('#selected_service').val(service_option);
}
Full code will look like :
`<?php
require_once 'includes/dbconnect.php';
session_start();
//require_once 'includes/dbconnect.php';
/* if (isset($_SESSION["username"]) && !empty($_SESSION["username"])){
echo "".strtoupper($_SESSION['username'])."(Sign out)"; }else{
echo "Sign In";
} */
if (isset($_POST["request"]))
{
//print_r($_POST);die;
//take care of injections
$service = mysqli_real_escape_string($link,$_POST['service']);
$service_details = mysqli_real_escape_string($link,$_POST['service_details']);
$duedate = mysqli_real_escape_string($link,$_POST['duedate']);
$postdate = mysqli_real_escape_string($link,$_POST['postdate']); //READ ONLY DATE POST
// Insert data into mysql + LOGGED IN USERS USERNAME TO BE INSERTED
$sql = "INSERT INTO serviceposts VALUES ('".$_SESSION["username"]."','".$service."', '".$service_details."', '".$duedate."', '".$postdate."')";
$result= $link -> query($sql) or die (mysqli_error($link));
echo "($result)";
// if successfully insert data into database, displays message "Successful".
if($result){
echo "request post success!";
echo'<script>window.location="http://localhost/Project2/User.php#viewrequests";</script>';
// header('Location: ../User.php?success=1');
}
else {
echo "Possible data input error";
//header('Location: ../user.php?error=1');
}
$link->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="includes/js/modernizr.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="jqueryAssets/jquery.mobile.icons.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/Mobi~Style~Me.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.icons-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.datepicker.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
body,td,th {
font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
color: #303;
}
body {
background-image: url();
}
</style>
<link href="jqueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
a {
font-weight: bolder;
}
</style>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="jqueryAssets/jquery-ui.min.js"></script>
<script src="jqueryAssets/jquery-2.1.1.min.js"></script>
<script src="jqueryAssets/jquery.mobile-1.4.5.min.js"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.dialog.custom.min.js"></script>
<script src="jqueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.datepicker.custom.min.js" type="text/javascript"></script>
<title>MyITjobs</title>
<meta charset="utf-8">
</head>
<body>
<div data-role="page" id="servicerequest" data-theme="c">
<div data-role="header" data-add-back-btn="true"><h4>IT~Service Request</h4></div>
<span align="center"><?php if (isset($_SESSION["username"]))
{
echo "".$_SESSION["username"]."";
}
?>
</span>
<div data-role="content" class="ui-field-contain" align="center" data-content-theme="c">
<form style="align-items:justify" method="post" action="" id="servicerequest">
<input type="hidden" name="service" id="selected_service"/>
<span>
<select name="selectmenu" required class="ui-bar-c slidedown" id="service" data-collapsed="false" onchange="onchangeservice()">
<option selected="selected" class="ui-selectmenu-placeholder">IT-Services</option>
<option value="service1" id="MobileApps">Mobile Apps Development</option>
<option value="service2" id="WebDev">Website Development</option>
<option value="service3" id="Programming">Programming</option>
</select>
</span>
<br>
<span>
<div data-role="fieldcontain">
<label for="service_details">IT~Service Request Details</label>
<textarea name="service_details" cols="35" rows="6" id="service_details" placeholder="Input Request details"></textarea>
</div>
</span>
<span>
<label for="duedate">Set Due Date:</label>
<input type="datetime-local" required name="duedate" id="duedate" data-mini="true">
</span>
<br>
<span>
<label for="datetime-local">Request Date</label>
<DateTime id="postdate" data-mini="true">
<?php
$postdate = date("Y-m-d, H:i");
echo "$postdate";
?>
</span>
<input type="hidden" name="postdate" value="<?php echo $postdate; ?>"/>
<br>
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<button type="submit" data-icon="check" data-iconshadow="true" data-iconpos="left" id="request" name="request">Request</button></div>
<div class="ui-block-b">
<button type="reset" data-icon="delete" data-iconshadow="true" data-iconpos="left">Cancel</button>
</div>
</fieldset>
<script>
function onchangeservice()
{
var service_option = $( "#service option:selected" ).text();
$('#selected_service').val(service_option);
}
</script>
</form>
</div>
<div data-role="footer" data-theme="c" align="center">
</div>
</div>
</body>
</html>`

You have to do lots of fixes.
You have not added any name attribute to all the input types so they were not posting.
You should write code much indented and clean so that you can find out the issues.
Don't include files multiple times.
Remove unwanted commented code.
Please try below code :
<?php
require_once 'includes/dbconnect.php';
session_start();
//require_once 'includes/dbconnect.php';
/* if (isset($_SESSION["username"]) && !empty($_SESSION["username"])){
echo "".strtoupper($_SESSION['username'])."(Sign out)"; }else{
echo "Sign In";
} */
if (isset($_POST["request"]))
{
//take care of injections
$service = mysqli_real_escape_string($link,$_POST['service']);
$service_details = mysqli_real_escape_string($link,$_POST['service_details']);
$duedate = mysqli_real_escape_string($link,$_POST['duedate']);
$postdate = mysqli_real_escape_string($link,$_POST['postdate']); //READ ONLY DATE POST
// Insert data into mysql + LOGGED IN USERS USERNAME TO BE INSERTED
$sql = "INSERT INTO serviceposts VALUES ('".$_SESSION["username"]."','".$service."', '".$service_details."', '".$duedate."', '".$postdate."')";
$result= $link -> query($sql) or die (mysqli_error($link));
echo "($result)";
// if successfully insert data into database, displays message "Successful".
if($result){
echo "request post success!";
echo'<script>window.location="http://localhost/Project2/User.php#viewrequests";</script>';
// header('Location: ../User.php?success=1');
}
else {
echo "Possible data input error";
//header('Location: ../user.php?error=1');
}
$link->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="includes/js/modernizr.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="jqueryAssets/jquery.mobile.icons.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/Mobi~Style~Me.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.icons-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet" type="text/css">
<link href="jqueryAssets/jquery.ui.datepicker.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
body,td,th {
font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, serif;
color: #303;
}
body {
background-image: url();
}
</style>
<link href="jqueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
a {
font-weight: bolder;
}
</style>
<script src="jqueryAssets/jquery-1.11.1.min.js"></script>
<script src="jqueryAssets/jquery-ui.min.js"></script>
<script src="jqueryAssets/jquery-2.1.1.min.js"></script>
<script src="jqueryAssets/jquery.mobile-1.4.5.min.js"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.dialog.custom.min.js"></script>
<script src="jqueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jqueryAssets/jquery-ui-1.9.2.datepicker.custom.min.js" type="text/javascript"></script>
<title>MyITjobs</title>
<meta charset="utf-8">
</head>
<body>
<div data-role="page" id="servicerequest" data-theme="c">
<div data-role="header" data-add-back-btn="true"><h4>IT~Service Request</h4></div>
<span align="center"><?php if (isset($_SESSION["username"]))
{
echo "".$_SESSION["username"]."";
}
?>
</span>
<div data-role="content" class="ui-field-contain" align="center" data-content-theme="c">
<form style="align-items:justify" method="post" action="" id="servicerequest">
<span>
<select name="selectmenu" required class="ui-bar-c slidedown" id="service" data-collapsed="false">
<option selected="selected" class="ui-selectmenu-placeholder">IT-Services</option>
<option value="service1" id="MobileApps">Mobile Apps Development</option>
<option value="service2" id="WebDev">Website Development</option>
<option value="service3" id="Programming">Programming</option>
</select>
</span>
<br>
<span>
<div data-role="fieldcontain">
<label for="service_details">IT~Service Request Details</label>
<textarea name="service_details" cols="35" rows="6" id="service_details" placeholder="Input Request details"></textarea>
</div>
</span>
<span>
<label for="duedate">Set Due Date:</label>
<input type="datetime-local" required name="duedate" id="duedate" data-mini="true">
</span>
<br>
<span>
<label for="datetime-local">Request Date</label>
<DateTime id="postdate" data-mini="true">
<?php
$postdate = date("Y-m-d, H:i");
echo "$postdate";
?>
</span>
<input type="hidden" name="postdate" value="<?php echo $postdate; ?>"/>
<br>
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<button type="submit" data-icon="check" data-iconshadow="true" data-iconpos="left" id="request" name="request">Request</button></div>
<div class="ui-block-b">
<button type="reset" data-icon="delete" data-iconshadow="true" data-iconpos="left">Cancel</button>
</div>
</fieldset>
<script>
$( "#service option:selected" ).text();
</script>
</form>
</div>
<div data-role="footer" data-theme="c" align="center">
</div>
</div>
</body>
</html>

Related

From data not getting submitted

HTML From data not getting submitted not even the PHP page is being loaded where a form is there.
In below Code, I have used From above the table from where I will have to select table's row using checklist after clicking submit button, but current pade is not even being load to show me even error and blank page itself.
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<style media="screen">
#listdiv1{
position: relative;
display:block;
left:15%;
}
body{
background-color: rgb(231, 187, 82);
}
th{
font-variant: small-caps;
font-weight: lighter;
color:red;
}
</style>
</head>
<body >
<div id="listdiv1" style="background-
color:red;width:1400px;height:900px;position:relative;top:20px;">
<div id="listDivIn2" style="background-color:blue;width:1400px;height:900px;display:inline-block;position: absolute;">
<h1 style="margin-left:500px;font-family:Trebuchet MS;font-variant: small-caps;"> Customers List</h1>
<div style="position:absolute;top:80px;margin-left:60px;">
<label style="font-family:Trebuchet MS;color:rgb(187, 218, 177);">Customer_Name</label><input type="text" name="cn_tosearch" placeholder="enter name" style="position: absolute;width:300px;margin-left:14px" /></br>
<label style="margin-left:30px;font-family:Trebuchet MS;color:rgb(187, 218, 177);">Date</label><input type="text" name="Date_tosearch" placeholder="enter date" style="position: absolute;margin-left:68px;width:300px;" /></div></br>
<button type="button" class="btn btn-secondary" style="position:absolute;top:150px;left:280px;">Search</button>
<div id="divtable" style="background-color:black;width:1200px;height:570px;position:absolute;top:220px;margin-left:90px;" >
<table style="width:100%;position:absolute;color:red;margin-left:35px;top:10px;" >
<?php
$dbs=mysqli_connect("localhost","root","","biz_dairy")
or die("connection error");
$q="select * from add_customer";
$result=mysqli_query($dbs,$q)
or die("error in query");
$data=mysqli_fetch_all($result);
mysqli_close($dbs);
$c=count($data);
echo "<tr><th>date</th><th>name</th><th>fanme</th><th>gender</th><th>mob_no</th><th>email</th><th>address</th><th>balance</th></tr>";
echo '<form name="register" method="POST" action="$_SERVER[\'PHP_SELF\']" >';
for ($i = 0; $i <= $c-1; $i++)
{
echo '<input type="checkbox" name="delete[]" value="delete" style="position:relative;top:34px;left:6px;" /><tr>';
echo '<td>'.$data[$i][0].'</td>';
echo '<td>'.$data[$i][1].'</td>';
echo '<td>'.$data[$i][2].'</td>';
echo '<td>'.$data[$i][3].'</td>';
echo '<td>'.$data[$i][4].'</td>';
echo '<td>'.$data[$i][5].'</td>';
echo '<td>'.$data[$i][6].'</td>';
echo '<td>'.$data[$i][7].'</td>';
echo '</tr><br />';
}
echo "</form>";
echo "</table>";
echo "</div>";
echo '<input type="submit" value="delete" name="submit" style="position:absolute;top:820px;left:600px;">';
echo " </form> ";
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
To submit a form without JavaScript/jQuery we must need to use form open/close tags and submit button.
You forgot to use the form open tag and submit button for the form:
Form open tag:
<form action="" method="post">
Submit button to submit the form:
<input type="submit" name="submit" value="search">.
I have edited your code with comments, Please try the below updated script:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Stack - QA</title>
<style media="screen">
#listdiv1{
position: relative;
display:block;
left:15%;
}
body{ background-color: rgb(231, 187, 82); }
th {
font-variant: small-caps;
font-weight: lighter;
color:red;
}
</style>
</head>
<body>
<div id="listdiv1" style="background-
color:red;width:1400px;height:900px;position:relative;top:20px;">
<div id="listDivIn2" style="background-color:blue;width:1400px;height:900px;display:inline-block;position: absolute;">
<!-- form open tag with action= path-to-action-page and method = get/post attribute -->
<form action="" method="post">
<h1 style="margin-left:500px;font-family:Trebuchet MS;font-variant: small-caps;"> Customers List</h1>
<div style="position:absolute;top:80px;margin-left:60px;">
<label style="font-family:Trebuchet MS;color:rgb(187, 218, 177);">Customer_Name</label><input type="text" name="cn_tosearch" placeholder="enter name" style="position: absolute;width:300px;margin-left:14px" /></br>
<label style="margin-left:30px;font-family:Trebuchet MS;color:rgb(187, 218, 177);">Date</label><input type="text" name="Date_tosearch" placeholder="enter date" style="position: absolute;margin-left:68px;width:300px;" /></div></br>
<input type="submit" class="btn btn-secondary" name="submit" value="Search" style="position:absolute;top:150px;left:280px;">
</form>
<div id="divtable" style="background-color:black;width:1200px;height:570px;position:absolute;top:220px;margin-left:90px;" >
<table style="width:100%;position:absolute;color:red;margin-left:35px;top:10px;" >
<?php
$dbs=mysqli_connect("localhost","root","","biz_dairy")
or die("connection error");
$q="select * from add_customer";
$result=mysqli_query($dbs,$q)
or die("error in query");
$data=mysqli_fetch_all($result);
mysqli_close($dbs);
$c=count($data);
echo "<tr><th>date</th><th>name</th><th>fanme</th><th>gender</th><th>mob_no</th><th>email</th><th>address</th><th>balance</th></tr>";
echo '<form name="register" method="POST" action="$_SERVER[\'PHP_SELF\']" >';
for ($i = 0; $i <= $c-1; $i++)
{
echo '<input type="checkbox" name="delete[]" value="delete" style="position:relative;top:34px;left:6px;" /><tr>';
echo '<td>'.$data[$i][0].'</td>';
echo '<td>'.$data[$i][1].'</td>';
echo '<td>'.$data[$i][2].'</td>';
echo '<td>'.$data[$i][3].'</td>';
echo '<td>'.$data[$i][4].'</td>';
echo '<td>'.$data[$i][5].'</td>';
echo '<td>'.$data[$i][6].'</td>';
echo '<td>'.$data[$i][7].'</td>';
echo '</tr><br />';
}
?>
</table> <!-- close tabel -->
</div>
<!-- scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>

Form Data will not parse into database

I have the following form asking for simple information, yet the data will not parse to my database. I have similar forms on other parts of my site, and they are connected to the database and retrieving data perfectly. Have pasted the code below and believe that MYSQL script is written as it is supposed to be. Why is the data not being retrieved once a use presses the submit button?
<?php
// Written by KV Ghumaan
session_start(); // Start session first thing in script
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
?>
<?php
// Parse the form data and add inventory item to the system
if(isset($_POST['fName'])){
$id = mysql_real_escape_string($_POST['id']);
$fName = mysql_real_escape_string($_POST['fName']);
$lName = mysql_real_escape_string($_POST['lName']);
$address = mysql_real_escape_string($_POST['address']);
$city = mysql_real_escape_string($_POST['city']);
$state = mysql_real_escape_string($_POST['state']);
$zipCode = mysql_real_escape_string($_POST['zipCode']);
//Add this product into the database now
$sql = mysql_query("INSERT INTO checkoutInfo (id, fName, lName, address, city, state, zipCode)
VALUES('$id','$fName','$lName','$address','$city','$state','$zipCode')") or die (mysql_error());
$pid = mysql_insert_id();
}
?>
<html>
<head>
<!--JQUERY-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="jqueryui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.structure.css"/>
<link rel="stylesheet" type="text/css" href="jqueryui/jquery-ui.theme.css"/>
<!--GOOGLE FONT & EXTERNAL LIBS-->
<link href="https://fonts.googleapis.com/css?family=Raleway:100" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CHECKOUT</title>
</head>
<body>
<?php include_once("template_header.php");?>
<table width="100%" height="76vh" border="10%" cellspacing="10" style="padding: 2vh 10vw 0vh 10vw; border-style:none;">
<tr height="75%" cellspacing="0" style="border-style:none;">
<td width="30%" style="border-style:none; padding-top: 10vh;">
<form class="form" action="confirmation.php" enctype="multipart/form-data" name="checkoutForm" id="checkoutForm" method="POST">
<div id="billingQuestions">
<h3><strong>BILLING ADDRESS:</strong></h3>
<div id="formQuestions">
<label>First Name:*</label><br />
<input type="text" name="fName" size="40vw" required>
</div>
<div id="formQuestions">
<label>Last Name:*</label><br />
<input type="text" name="lName" size="40vw" required>
</div>
<div id="formQuestions">
<label>Address 1:*</label><br />
<input type="text" name="address" size="40vw" required>
</div>
<div id="formQuestions">
<label>Address 2:*</label><br />
<input type="text" size="40vw">
</div>
<div id="formQuestions">
<label>City: *</label><br />
<input name="city" type="text" size="40vw" required>
</div>
<div id="formQuestions">
<label>State: *</label><br />
<input name="state" type="text" size="40vw" required>
</div>
<div id="formQuestions">
<label>Zip Code: *</label><br />
<input name="zipCode" type="text" size="40vw" required>
</div>
<input type="submit" value="Submit"/>
</div>
</form>
</td>
</tr>
</table>
<?php include_once("template_footer.php");?>
</body>
</html>

Fetch data from database in php

Hi In my application I designed one form with HallTicketNo if i click the submit button it will goto result page based on the hallticket no i want to fetch all the details.My proble is result.php it showing blank page fetching is not working can anyone help me
index.php:
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style_register.css" />
<link rel="stylesheet" type="text/css" media="all" href="css/responsive.css">
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/validation_script.js"></script>
</head>
<body>
<hr>
<img src="images/banner1.jpg" width="100%" />
<hr>
<section id="container">
<form id="result form" action="result.php" method="POST" enctype="multipart/form-data">
<div>
<label class="desc" id="title1" >Hall Ticket No.</label>
<div>
<input id="name" name="uname" type="text" class="field text fn" value="" size="8" tabindex="1">
<span class="val_name"></span>
</div>
</div>
<div>
<div>
<input type="submit" name="submit_registration" value="Submit" /><input type="reset" name="reset" value="Reset" />
</div>
</div>
</form>
</section>
</body>
</html>
result.php:
<?php
session_start();
if (isset($_SESSION['id'])) {
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style_register.css" />
<link rel="stylesheet" type="text/css" media="all" href="css/responsive.css">
</head>
<body>
<img src="images/banner.jpg" width="100%" />
<section id="container">
<?php
include "../db.php";
$hallticket = $_REQUEST["uname"];
$query = mysql_query("SELECT * FROM results where Hall_Ticket_No='$hallticket'");
$row = mysql_fetch_array($query);
?>
<div id="title" align="center"><h3>Exam Results</h3></div>
<div id="tab">
<table align="center">
<tr><td><b>HallTicketNo</b></td><td> : <?php echo $row['HallTicketNo'];?></td></tr>
<tr><td><b>RNO</b></td><td> : <?php echo $row['RNO'];?></td></tr>
<tr><td><b>FirstName</b></td><td> : <?php echo $row['FirstName'];?></td></tr>
<tr><td><b>LastName</b></td><td> : <?php echo $row['LastName'];?></td></tr>
<tr><td><b>ClassID</b></td><td> : <?php echo $row['ClassID'];?></td></tr>
<tr><td><b>ClassName</b></td><td> : <?php echo $row['ClassName'];?>
<tr><td><b>ExamID</b></td><td> : <?php echo $row['ExamID'];?></td></tr>
<tr><td><b>ExamName</b></td><td> : <?php echo $row['ExamName'];?></td></tr>
<tr><td><b>ClassResult</b></td><td> : <?php echo $row['ClassResult'];?></td></tr>
<tr><td></td></tr>
</table>
<br>
<div id="sign" align="right"><img src="images/sign.png" height=100 width=80></div>
<br>
<center><input type="button" value="home" /></center>
</div>
</section>
</body>
</html>
<?php
}
?>
Than you
In index.php you are not starting session and not registering session id. That is why the if condition of your result.php is not executing.
In index.php do add this line.
<?php
session_start();
$_SESSION['id']= "1213"; //your id here
?>

JavaScript for validate only filed which is checked

I have some PHP code in which is using codeigniter. How can I check validation on the filed that are marked check? My code is below.
Can you please let me know how can I check if item is checked and force the validation accordingly?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/site.css"></link>
</head>
<body>
<script type="text/Javascript">
$(function () {
$('.checkall').click(function () {
$(this).parents('fieldset:eq(0)').
find(':checkbox').attr('checked', this.checked);
});
});
</script>
<? $attributes = array('class' => '', 'id' => ''); ?>
<? echo form_open('ShoppingListController', $attributes); ?>
<div class="divTable">
<fieldset>
<!-- these will be affected by check all -->
<div class="divRow">Product Name | Quantity | Packages</div>
<div class="divRow"><input type="checkbox" size="100" class="checkall"> Check all</div>
<br>
<?php foreach ($records as $rec) {
?>
<div class="divRow"><input type="checkbox">
<input size="5" type="hidden" value="<? echo $rec->id; ?>" name="id"></input>
<input size="20" type="text" value="<? echo $rec->name; ?>" name="name"></input>
<label for="quantity">Value <span class="required">*</span></label>
<span class="required"><?php echo form_error('quantity'); ?></span>
<input size="5" type="text" value="" name="quantity"></input>
<select name="package">
<option name="case">Case</option>
<option name="box">Box</option>
<option name="box">Single Bottle</option>
</select>
</div>
<br>
<?
}
?>
</fieldset>
</div>
<div><input type="submit" name="submit"/></div>
</form>
</body>
you can use code below:
var divRows = $('.divRow');
var count = divRows.length;
divRows.each(function() {
if ($(this).find('input[type=checkbox]').is(':checked')) {
count--;
}
});
if (count != 0) {
alert(count + ' checkboxes not checked');
}
http://jsfiddle.net/SKgA8/

How to pass an image value from one form to another form?

i have an image at promotions.php . When i clicked on 'edit' link, the variables like 'title', 'description' and 'image' would be passed on to doEditPromotion.php's page form.
I can pass 'title' and 'description' to be displayed on doEditPromotion.php's page form but not the image value.
Can anyone help me with this? Thanks!
doEditPromotion.php -->
<?php
session_start();
include "dbfunction.php";
$id = $_REQUEST['id'];
$query = "SELECT title, description, image, promotionID FROM promotion WHERE promotionID = '$id'";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_array($result);
$title = $row['title'];
$description = $row['description'];
$image = $row['image'];
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['save']))
{
$title_save = $_POST['title'];
$description_save = $_POST['description'];
$target = 'images/';
$target = $target.basename($_FILES['photo']['name']);
$pic = ($_FILES['photo']['name']);
move_uploaded_file($_FILES['photo']['tmp_name'], $target);
// check that firstname/lastname fields are both filled in
if ($title_save == '' || $description_save == '' || $pic == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
echo $error;
}
else
{
// save the data to the database
$query = "UPDATE promotion SET title = '$title_save', description = '$description_save', image = '$pic' WHERE promotionID = '$id'";
$result = mysqli_query($link, $query);
// once saved, redirect back to the view page
header("Location: promotions.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="codes.css"/>
<link href="styles.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="picture-zoom/css/dg-picture-zoom.css" type="text/css" />
<script type="text/javascript" src="picture-zoom/js/external/mootools-1.2.4-core-yc.js"></script>
<script type="text/javascript" src="picture-zoom/js/external/mootools-more.js"></script>
<script type="text/javascript" src="picture-zoom/js/dg-picture-zoom.js"></script>
<script type="text/javascript" src="picture-zoom/js/dg-picture-zoom-autoload.js"></script>
<script>
function myFunction()
{
alert("Are you sure you want to proceed?");
}
</script>
<title>Eco Canteen - Promotions</title>
</head>
<body>
<div id="wrap">
<div id="header">
<div id="logo">
<br/>
<?php
if(isset($_SESSION['username']))
{
?>
<p align="right"><font color="white">Logout</font></p>
<?php
}
else
{
?>
<form align="right" name="form" action="doIndex.php" method="post">
<p><label for="username"><font color="white"> Username: </font></label>
<input name="username" type="text"></input>
<label for="password"><font color="white"> Password: </font></label>
<input name="password" type="password"></input>
<input name="submit" value="Login" type="submit"/></p>
<?php
}
?>
</form>
</div>
<div id='menu'>
<ul>
<li><a href='index.php'><span>Home</span></a></li>
<li><a href='promotions.php'><span>Promotions</span></a></li>
<li><a href='outlets.php'><span>Outlets</span></a></li>
<li><a href='feedback.php'><span>Feedback</span></a></li>
<li class='has-sub '><a href='#'><span>Career</span></a>
<ul>
<li><a href='stall.php'><span>Stall Leasing</span></a></li>
<li><a href='career.php'><span>Career Opportunity</span></a></li>
</ul>
</li>
<li><a href='contactUs.php'><span>Contact Us</span></a></li>
</ul>
</div>
</div>
<br/>
<br/>
<p class="slogan"></p>
<div id="intro">
<h2><b>ECO CANTEEN</b></h2>
</div>
<br/>
<div class="wid_center">
<div id="content">
<div class="gao">
<h3>Promotion > <b>Edit Promotion</b></h3>
<fieldset stype='width:500px'>
<legend><b>Promotion Details</b></legend>
<form method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Promotion Title:</td>
<td><input type="text" name="title" size='36' value="<?php echo $title;?>"/></td>
</tr>
<tr>
<td>Description:</td>
<td><input type="text" name="description" style='width: 300px;height:80px' value="<?php echo $description;?>"/></td>
</tr>
<tr>
<td>Image:</td>
<td><input type='file' name='upfile' id='image' src='images/<?php echo $_REQUEST['$image']?>'></input></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="save" value="Save"/></td>
</tr>
</table>
</form>
</fieldset>
</div>
<br/>
<br/>
<hr class="clear" />
</div>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div id="footer">
<p> <br />
Copyright © 2012 EcoCanteen<br />
</p></div>
</div>
</body>
</html>
You named the uploaded file upfile, and then tried to access it as photo. Do print_r($_FILES) and then change one of the following:
$_FILES['photo']['name'] // Either change photo to upfile
...
<input type='file' name='upfile' id='image' src='...' /> // Or upfile to photo

Categories