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>
Related
I have an assignment to create the web page. One of the points is to make able to change the style of the text through checkboxes. Web programming is not my primary areas, (I am mostly in C#). I don't know how to do it through PHP, as we have started learning recently.
There is my PHP code.
<?php
$firstName = "Yaroslav";
$lastName = "Yatsyk";
$studentID = "101343887";
$checks = [];
$courses = array("COMP1230"=>"Advanced Web Programming", "COMP2129" => "Advanced Object-Oriented Programming", "COMP2130" => "Application Development using Java",
"COMP2138" => "Advanced Database Development","COMP2147" => "System Analysis, Design And Testing", "GSCI1003" => "Statistics");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Assignment 1</title>
<meta name="description" content="Sending data by GET/POST method">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Yaroslav Yatsyk">
<link rel="stylesheet" href="101343887.css">
</head>
<body>
<h1>
<?php
echo $firstName . " " . $lastName . " - " . $studentID;
?>
</h1>
<form action="101343887.php" action="POST">
<section id="textFiled">
Name: <input type="text" value="<?php echo $firstName?> " name="name" required>
<br><br>
Surname: <input type="text" value="<?php echo $lastName?>" name="surname" required>
<br><br>
Student ID: <input type="text" value="<?php echo $studentID?>" name="id" required>
<br><br>
Class: <input list = "classes" name="classes" id="classes" required>
<datalist id="classes">
<?php
foreach($courses as $key=>$value){
echo "<option>".$key."</option>"."<br />";
}
?>
</datalist>
</section>
<br>
<section id="checkBoxes">
<input type="checkbox" name="check[]" id="Strong" value="strong">
<label for="Strong">Strong</label>
<br><br>
<input type="checkbox" name="check[]" id="Underline" value="underline">
<label for="Underline">Underline</label>
<br><br>
<input type="checkbox" name="check[]" id="Uppercase" value="uppercase">
<label for="Uppercase">Uppercase</label>
</section>
<br><br>
<section id="radios">
<input type="radio" name="12ptx" id="12ptx" value="12pt">
<label for="12ptx">12pt</label>
<br><br>
<input type="radio" name="18ptx" id="18ptx" value="18pt">
<label for="18ptx">18pt</label>
<br><br>
<input type="radio" name="24ptx" id="24ptx" value="24pt">
<label for="24ptx">24pt</label>
</section>
<br>
<input type="submit" value="Submit">
</form>
<section id="output" style="height: 150px; width: 150px;">
<h2>
<?php
if(filter_input(INPUT_POST,'name',FILTER_SANITIZE_STRING) && filter_input(INPUT_POST,'surname',FILTER_SANITIZE_STRING) && (
filter_input(INPUT_POST,'id',FILTER_SANITIZE_STRING)
))
{
$firstName = $_POST['name'];
$lastName = $_POST['surname'];
$studentID = $_POST['id'];
if(isset($_POST['check']) && !empty($_POST['check'])) {
$checks = $_POST['check'];
// Add code
}
}
echo $firstName . " " . $lastName . " " . $studentID;
?>
</h2>
</section>
<div>
<?php
if(isset($_POST["classes"])) {
$key = $_POST["classes"];
}
echo $courses[$key];
?>
</div>
<?php
echo "<hr>";
echo show_source("101343887.php");
?>
<script src=https://my.gblearn.com/js/loadscript.js></script>
</body>
</html>
There is my CSS code
#textFiled input[type=text] {
width: 25%;
height: 25%;
padding: 10px 15px;
margin: 8px 0;
box-sizing: border-box;
}
#textFiled input[type=checkbox] {
width: 25%;
height: 25%;
padding: 10px 15px;
margin: 8px 0;
box-sizing: border-box;
}
.uppercase {
text-transform: uppercase;
}
.underline {
text-decoration: underline;
}
.strong {
font-weight: bold;
}
Please do not be toxic, or do not put minus scores, as I have just begun learning programming at college, and not all things are understandable. I am willing to be better, but I need professional assistance to approach it.
Thank you
I want to pass start and end value to data.php using form . Before passing when i print it, it gives me [object HTMLInputElement] .
and from data.php ,i try to using $_POST['start'] and $_POST['end'] to get the start and end value but get nothing
code as below ,
<!DOCTYPE html>
<html>
<head>
<base href="http://demos.telerik.com/kendo-ui/datepicker/rangeselection">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }
</style>
<title></title>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.607/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.607/styles/kendo.material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.607/styles/kendo.default.mobile.min.css" />
<script src="//kendo.cdn.telerik.com/2016.2.607/js/jquery.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.2.607/js/kendo.all.min.js">
</script>
</head>
<body>
<div id="example">
<div class="demo-section k-content">
<form action="data.php" method="post">
<h4>Start date:</h4>
<input id="start" style="width: 100%;" value="" />
<h4 style="margin-top: 2em">End date:</h4>
<input id="end" style="width: 100%;" value=""/>
<input name="" type="submit" >
</form>
</div>
<script>
$(document).ready(function() {
function startChange() {
var startDate = start.value(),
endDate = end.value();
if (startDate) {
startDate = new Date(startDate);
startDate.setDate(startDate.getDate());
end.min(startDate);
} else if (endDate) {
start.max(new Date(endDate));
} else {
endDate = new Date();
start.max(endDate);
end.min(endDate);
}
}
function endChange() {
var endDate = end.value(),
startDate = start.value();
if (endDate) {
endDate = new Date(endDate);
endDate.setDate(endDate.getDate());
start.max(endDate);
} else if (startDate) {
end.min(new Date(startDate));
} else {
endDate = new Date();
start.max(endDate);
end.min(endDate);
}
}
var start = $("#start").kendoDatePicker({
change: startChange
}).data("kendoDatePicker");
var end = $("#end").kendoDatePicker({
change: endChange
}).data("kendoDatePicker");
start.max(end.value());
end.min(start.value());
});
</script>
</div>
</body>
</html>
but it's nothing .
Would you suggest me any solution. Thanks in advance.
Set name attribute in your input elements(name="start", name="end", name="submit"), then you can access their values through $_POST['start'] and $_POST['end']
<form action="data.php" method="post">
<h4>Start date:</h4>
<input name="start" id="start" style="width: 100%;" value="" />
<h4 style="margin-top: 2em">End date:</h4>
<input name="end" id="end" style="width: 100%;" value=""/>
<input name="submit" type="submit" >
</form>
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>
I have a register and login PHP script, that uses sessions and will display each users name when they log in. I also have a form that they can fill and is added to a mysql database. Is it possible so that only the user that filled in THEIR form can see it when its displayed? Currently whenever any user fills the form its displayed to every user.
<?PHP
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title></title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css">
</head>
<body>
<div id='fg_membersite_content'>
<h2>Product control page</h2>
<p>
Logged in as: <?= $fgmembersite->UserFullName() ?>
</p>
<p>Here you can see your Current Products:</p>
<?php
$con = mysql_connect("localhost","root","password");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("trackerweb",$con);
$result = mysql_query("SELECT Name_of_Product FROM Product_Tracker");
while ($row = mysql_fetch_assoc($result)) {
echo $row['Name_of_Product'];
echo "<br />";
mysql_query($query);
}
mysql_close($con);
?>
<p>
<a href='add_customer.php'>Add a new product </a>
</p>
<p>
<a href='view.php'>View all product details</a>
</p>
<p>
<a href='login-home.php'>Home</a>
</p>
</div>
</body>
</html>
I only need to display the name of the product when they fill in the form on the same page.
This is the form:
<?php
require_once("/extlib/vdaemon/vdaemon.php");
require_once("./core/config.php");
$_SESSION['user']= ['$fgmembersite->UserFullName'];
?>
<html>
<head>
<style type="text/css">
body {
background: #e4e4e4;
}
.form {
width: 600px;
margin: 0 auto;
background: #fff;
padding: 45px;
border: 1px solid #c2c2c2;
}
.error {
color: #AA0000
}
.controlerror {
background-color: #ffffdd;
border: 1px solid #AA0000;
}
.input {
width: 300px;
height: 35px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="form">
<?php
$msg = $_GET['msg'];
if ( $msg == '1' ) {
echo '<p>Your information was submitted successfully.</p>';
}
?>
<form action="core/process.php" method="post" id="registration" >
<input type="hidden" name="formID" value="Product_Tracker" />
<p>Name of product:<input type="text" name="Name of Product" class="input" />
<p>Please select the tests that were done on the product.</p>
<p>In Circuit Test (ICT): Yes: <input type="radio" name="ICT" value="yes" /> No: <input type="radio" name="ICT" value="no" /></p>
<p>Visual Inspection: Yes: <input type="radio" name="Visual Inspection" value="yes" /> No: <input type="radio" name="Visual Inspection" value="no" /></p>
<p>XRAY: Yes: <input type="radio" name="XRAY" value="yes" /> No: <input type="radio" name="XRAY" value="no" /></p>
<p>Automated Optical Inspection (AOI): Yes: <input type="radio" name="AOI" value="yes" /> No: <input type="radio" name="AOI" value="no" /></p>
<!--<p>Checkbox1 <input type="checkbox" name="checkbox" value="checkbox1" /> Checkbox2: <input type="checkbox" name="checkbox" value="checkbox2" /></p>-->
<input type="submit" value="Submit" />
<p>
<a href='access-controlled.php'>Back</a>
</p>
</form>
</div>
</body>
</html>
<?php VDEnd(); ?>
I have 2 forms in 1 page that need submitting i seem to be limited because it is for a hotspot by mikrotik.
The login.html in mikrotic router is
<html>
<head><title>...</title></head>
<body>
$(if chap-id)
<noscript>
<center><b>JavaScript required. Enable JavaScript to continue.</b></center>
</noscript>
$(endif)
<center>If you are not redirected in a few seconds, click 'continue' below<br>
<form name="redirect" action="http://domain.name/login.php" method="post">
<input type="hidden" name="mac" value="$(mac)">
<input type="hidden" name="ip" value="$(ip)">
<input type="hidden" name="username" value="$(username)">
<input type="hidden" name="link-login" value="$(link-login)">
<input type="hidden" name="link-orig" value="$(link-orig)">
<input type="hidden" name="error" value="$(error)">
<input type="hidden" name="chap-id" value="$(chap-id)">
<input type="hidden" name="chap-challenge" value="$(chap-challenge)">
<input type="hidden" name="link-login-only" value="$(link-login-only)">
<input type="hidden" name="link-orig-esc" value="$(link-orig-esc)">
<input type="hidden" name="mac-esc" value="$(mac-esc)">
<input type="submit" value="continue">
</form>
<script language="JavaScript">
<!--
document.redirect.submit();
//-->
</script></center>
</body>
</html>
so then my login.php is this
<?php
$mac=$_POST['mac'];
$ip=$_POST['ip'];
$username=$_POST['username'];
$linklogin=$_POST['link-login'];
$linkorig=$_POST['link-orig'];
$error=$_POST['error'];
$chapid=$_POST['chap-id'];
$chapchallenge=$_POST['chap-challenge'];
$linkloginonly=$_POST['link-login-only'];
$linkorigesc=$_POST['link-orig-esc'];
$macesc=$_POST['mac-esc'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>mikrotik hotspot > login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<style type="text/css">
body {color: #737373; font-size: 10px; font-family: verdana;}
textarea,input,select {
background-color: #FDFBFB;
border: 1px solid #BBBBBB;
padding: 2px;
margin: 1px;
font-size: 14px;
color: #808080;
}
a, a:link, a:visited, a:active { color: #AAAAAA; text-decoration: none; font-size:
10px; }
a:hover { border-bottom: 1px dotted #c1c1c1; color: #AAAAAA; }
img {border: none;}
td { font-size: 14px; color: #7A7A7A; }
</style>
<script language="JavaScript">
function fnSubmit (){
var form1Content = document.getElementById("form1").innerHTML;
var form2Content = document.getElementById("form2").innerHTML;
var form3Content = document.getElementById("form3").innerHTML;
document.getElementById("toSubmit").innerHTML=form1Content+form2Content;
document.forms.toSubmit.submit();
}
</script>
</head>
<body>
<!-- $(if chap-id) -->
<form name="sendin" action="<?php echo $linkloginonly; ?>" method="post" id="form1">
<input type="hidden" name="username" />
<input type="hidden" name="password" />
<input type="hidden" name="dst" value="<?php echo $linkorig; ?>" />
<input type="hidden" name="popup" value="true" />
</form>
<script type="text/javascript" src="./md5.js"></script>
<script type="text/javascript">
<!--
function doLogin() {
<?php if(strlen($chapid) < 1) echo "return true;\n"; ?>
document.sendin.username.value = document.login.username.value;
document.sendin.password.value = hexMD5('<?php echo $chapid; ?>' + document.login.password.value + '<?php echo $chapchallenge; ?>');
document.sendin.submit();
return false;
}
//-->
</script>
<!-- $(endif) -->
<div align="center">
Hotspot
</div>
<table width="100%" style="margin-top: 10%;">
<tr>
<td align="center" valign="middle">
Please log on to use the mikrotik hotspot service
</div><br />
<table width="240" height="240" style="border: 1px solid #cccccc; padding: 0px;" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="bottom" height="175" colspan="2">
<!-- removed $(if chap-id) $(endif) around OnSubmit -->
<form method="POST" action="signin.php" id="form2">
First Name<p><input type="text" name="firstname" size="30"></p>
Surname<p><input type="text" name="lastname" size="30"></p>
Email address <font color="red"> (required)</font><p><input type="text" name="email" size="30"></p>
<input type="submit" value="submit" onclick="javascript:fnSubmit();"/>
</form>
<form name="login" id="form3 action="<?php echo $linkloginonly; ?>" method="post" onSubmit="return doLogin()" >
<input type="hidden" name="dst" value="<?php echo $linkorig; ?>" />
<input type="hidden" name="popup" value="true" />
<table width="100" style="background-color: #ffffff">
<tr><td align="right"></td>
<td><input type="hidden" style="width: 80px" name="username" type="text" value="user2"/></td>
</tr>
<tr><td align="right"></td>
<td><input type="hidden" style="width: 80px" name="password" type="password" value="user2"/></td>
</tr>
<tr><td> </td>
<td><td></td></td></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<!-- $(if error) -->
<br /><div style="color: #FF8080; font-size: 9px"><?php echo $error; ?></div>
<!-- $(endif) -->
</td>
</tr>
</table>
<script type="text/javascript">
<!--
document.login.username.focus();
//-->
</script>
</body>
</html>
as you can see im trying to auto submit the username and password
so that the user only inputs his email address, to do this i want to store the email in
a database
with signin.php
which is this
<?php
ini_set('display_errors', 'On');
// Receiving variables
#$pfw_ip= $_SERVER['REMOTE_ADDR'];
#$firstname = addslashes($_POST['firstname']);
#$lastname = addslashes($_POST['lastname']);
#$email = addslashes($_POST['email']);
#$date = addslashes($_POST['date']);
// Validation
if (! ereg('[A-Za-z0-9_-]+\#[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}
if (strlen($email) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}
/* adding user information to the userinfo table */
#$pfw_strQuery = "INSERT INTO userinfo (firstname, lastname, email, creationdate) values ".
"('$firstname', '$lastname', '$email', NOW())";
#$pfw_host = "localhost";
#$pfw_user = "dbusername";
#$pfw_pw = "dbpassword";
#$pfw_db = "database";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}
//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);
header('Location: http://www.google.co.uk');
?>
what happens is that the email address is stored in the mysql table
but the form which stores the username and password, does not pass through, and i end up at the login page
what am i missing?
Thanks all
Ok the answer was to eliminate all the javascript in login.php and use a simple form with the signin.php passing through the username and password using pap login. All working and happy a happy bunny