Php Variable Data Allocation - php

I wonder why the 2nd output $devNO gives me bool(false) which is empty. i have no idea about it. Am I wrong at the mysql_query() part?
$developer = $_POST['dev'];
$platform = $_POST['plat'];
$genre = $_POST['gen'];
var_dump($developer);
echo "<br>";
$devNO = mysql_query("SELECT No FROM developer WHERE Developer = $developer");
$platNO = mysql_query("SELECT No FROM platform WHERE Platform = $platform");
$genNO = mysql_query("SELECT No FROM genre WHERE Genre = $genre");
var_dump($devNO);
Here's my output:
Here I will show my full code for "games.php":
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<html>
<head lang="en">
<meta charset="utf-8" />
<title>Game List</title>
<link rel="stylesheet" href="css.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<style>
legend {font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif}
</style>
</head>
<body>
<div id="big_wrapper">
<header id="top_header">
<h1>Dandy's Game Library</h1>
</header>
<nav id="top_menu">
<ul>
<li><strong></stron>Home</strong></li>
<li><strong>Game List</strong></li>
</ul>
</nav>
<div id="game_wrapper">
<section id="filter">
<form action="games.php" method="post" name="search_form">
<fieldset>
<legend><h3><strong>Search</strong></h3></legend>
<strong>Developer</strong><br>
<select name="dev">
<option value="">--Select--</option>
<?php
include("dbConnection.php");
mysql_connect("localhost","root","");
mysql_select_db("games");
$sql = mysql_query("SELECT Publisher FROM publisher");
while($row = mysql_fetch_array($sql)){
echo "<option value='".$row['Publisher']."'>" .$row[Publisher]. "</option>";
}
?>
</select>
<br/><br/><strong>Game Platform</strong><br>
<select name="plat">
<option value="">--Select--</option>
<?php
$sql = mysql_query("SELECT Platform FROM platform");
while($row = mysql_fetch_array($sql)){
echo "<option value='".$row['Platform']."'>" .$row[Platform]. "</option>";
}
?>
</select>
<br/><br/><strong>Genre</strong><br>
<select name="gen">
<option value="">--Select--</option>
<?php
$sql = mysql_query("SELECT Genre FROM genre");
while($row = mysql_fetch_array($sql)){
echo "<option value='".$row['Genre']."'>" .$row[Genre]. "</option>";
}
$developer = $_POST['dev'];
$platform = $_POST['plat'];
$genre = $_POST['gen'];
?>
</select>
<br><br><input type="submit" name="search" value="Search"></input>
</fieldset>
</form>
</section>
<aside id="items">
<fieldset>
<legend><h3><strong>Game List</strong></h3></legend>
<?php
var_dump($developer);
$devNO = mysql_query("SELECT No FROM developer WHERE Developer = $developer");
$platNO = mysql_query("SELECT No FROM platform WHERE Platform = $platform");
$genNO = mysql_query("SELECT No FROM genre WHERE Genre = $genre");
var_dump($devNO);
$sql = sprintf("SELECT Title, Release_Year, Language, Price FROM games WHERE Developer_NO = $devNO");
$result = mysql_query($sql);
$game_title = 'Title';
$game_year = 'Release_Year';
$game_lan = 'Language';
$game_price = 'Price';
?>
<div id="gamelist">
<?php
if(!$result) {
die(mysql_error());
}
while($row = mysql_fetch_array($result)) {
?>
<div class="row">
<div class="cell"><?php echo $row[$game_title]?></div>
<div class="cell"><?php echo "Year : ".$row[$game_year]?></div>
<div class="cell"><?php echo "Language : ".$row[$game_lan]?></div>
<div class="cell"><?php echo "Price : RM".$row[$game_price]?></div>
</div>
<?php
}
?>
</div>
</fieldset>
</aside>
</div>
</div>
<div id="btm_wrapper">
<footer id="foot">
<strong></strong>
</footer>
</div>
</body>
</html>
The full output will be like this after i search from dropdown:

The method mysql_query() , if successful, returns a resultset, which has to be made an array even if only a single value is being returned from the query.
Ideally there should be a for-each iteration on this array to get result, however if you're sure you'll get at least one value, the first row with desired index('No' in your case).
$dataset= mysql_query("SELECT No FROM developer WHERE Developer = '$developer'");
$row = mysql_fetch_assoc($dataset);
$devNO = $row['No'];
Also note the quote I've used for varchar. It was correctly pointed in the other answer. Try Now.

If $developer is a string use quotes. You need to first fetch results from result set and than use it in code:
<?php
$devNOResult = mysql_query("SELECT No FROM developer WHERE Developer = '$developer'");
$platNOResult = mysql_query("SELECT No FROM platform WHERE Platform = '$platform'");
$genNOResult = mysql_query("SELECT No FROM genre WHERE Genre = '$genre'");
$devNO = mysql_fetch_row($devNOResult);
$sql = sprintf("SELECT Title, Release_Year, Language, Price FROM games WHERE Developer_NO = $devNO");
$result = mysql_query($sql);
$game_title = 'Title';
$game_year = 'Release_Year';
$game_lan = 'Language';
$game_price = 'Price';
?>
<div id="gamelist">
<?php
if(!$result) {
die(mysql_error());
}
while($row = mysql_fetch_array($result)) {
?>

Related

link to mysql single record from search with pagination

I am trying to link through to the single row record information in my mysql database from my search using php/ajax_pagination and the code that I am trying to get to work is:
<div id="posts_content">
<?php
//Include pagination class file
include('Pagination.php');
//Include database configuration file
include('dbConfig.php');
$limit = 3;
//get number of rows
$queryNum = $db->query("SELECT COUNT(*) as postNum FROM posts");
$resultNum = $queryNum->fetch_assoc();
$rowCount = $resultNum['postNum'];
//initialize pagination class
$pagConfig = array(
'totalRows' => $rowCount,
'perPage' => $limit,
'link_func' => 'searchFilter'
);
$pagination = new Pagination($pagConfig);
//get rows
$query = $db->query("SELECT * FROM posts ORDER BY id DESC LIMIT $limit");
if($query->num_rows > 0){ ?>
<div class="posts_list">
<?php
while($row = $query->fetch_assoc()){
$postID = $row['id'];
?>
<div class="list_item"><h2><?php echo $row["title"]; ?></h2></div>
<?php } ?>
</div>
<?php echo $pagination->createLinks(); ?>
<?php } ?>
</div>
There is obviously something wrong with my href link:
<h2><?php echo $row["title"]; ?></h2>
OR my file.php page:
<?php
// GET ID FROM THE URL
$id = $_GET['id'];
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Ajax Pagination with Search and Filter in PHP</title>
<link href='style.css' rel='stylesheet' type='text/css'>
<script src="jquery.min.js"></script>
<script type="text/javascript"></script>
</head>
<body>
<?php
$sql =mysql_query("select * from posts where id='".$id."'");
while($row = mysql_fetch_array($sql)){
?>
<tr>
<th>title:</th>
<th>created:</th>
<th>modified:</th>
<th>statusr:</th>
</tr>
<tr>
<td><?=$row['title']?></td>
<td><?=$row['created']?></td>
<td><?=$row['modified']?></td>
<td><?=$row['status']?></td>
</tr>
<?php
}
?>
But I cannot understand why as everything else seems to be working fine, maybe I have been looking at this to long and missed something blatently obvious... but any help would be greatly appreciated.
Use Below Code:
<div class="list_item"><h2><?php echo $row["title"]; ?></h2></div>

Updating a MySQLi database using php and HTML5 forms

On my website i have an admin page where i want to be able to update information in the database, using a form.
This is the code im using to enter information and update what is in my database:
adminform.php
<html>
<head>
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body>
<header id="header">
<h1>SafeTNet</h1>
<nav id="nav">
<ul>
<li>Admin Page Only</li>
<li></li>
<li>Logout </li>
</ul>
</nav>
</header>
<h1> Select a member </h1>
<br />
<select name="members" onchange="showUser(this.value)">
<option value="">Select a member email</option>
<?php
$query = "SELECT * FROM members";
$mysqli = new mysqli('localhost','root','root','SafeTNetD');
$result = $mysqli->query($query);
while($row = $result->fetch_assoc())
echo '<option value="'.$row["email"].'">'.$row["email"].'</option>';
?>
</select>
<div id="signup">
<h2>Update Your Member Information</h2>
<form method="post" action="admin1.php">
<table>
<tr>
<td>Email</td>
<td><input type="text" name="email" required="required"></td>
</tr>
<tr>
</tr>
<tr>
<td>City </td>
<td><input type="text" name="city"></td>
</tr>
<tr>
</tr>
<tr>
</table>
<br><br>
<div id="buttons">
<input type="submit">
</div>
</body>
</html>
admin1.php
<html>
<head>
<title>Admin</title>
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body>
<header id="header">
<h1>SafeTNet</h1>
<nav id="nav">
<ul>
<li>Admin Page Only</li>
<li></li>
<li>Logout</li>
</ul>
</nav>
</header>
<br />
<?php
$query = "SELECT * FROM members";
$mysqli = new mysqli('localhost','root','root','SafeTNetD');
$result = $mysqli->query($query);
while($row = $result->fetch_assoc())
echo '<option value="'.$row["email"].'">'.$row["email"].'</option>';
?>
</select>
<br />
<?php
$q=$row["email"];
$mysqli = new mysqli('localhost','root','root','members');
$sql = "SELECT * FROM members WHERE email='".$q."'";
if(array_key_exists('_submit_check', $_POST))
{
$email = $_POST['email'];
$city = $_POST['city'];
$sql = "UPDATE members SET city = '$city' WHERE email = '$q'";
if($mysqli->query($sql) === TRUE)
{
echo 'Record updated successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
$mysqli->close();
}
?>
<br><br><br>
<footer id="footer">
<img src="logo.jpg" height="50px">
<ul class="copyright">
<li>© SafeTNet. All rights reserved.</li><li> 2016</li>
</ul>
</footer>
</body>
</html>
I can get the form to run but cant get the information to change in the database or echo to the screen.
Thank you in advance.
if(array_key_exists('_submit_check', $_POST))
{
$email = $_POST['email'];
$city = $_POST['city'];
$sql = "UPDATE members SET city = '$city' WHERE email = '$q'";
if($mysqli->query($sql) === TRUE)
{
echo 'Record updated successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
$mysqli->close();
}
There is no element called '_submit_check' in your form. I guess you forgot the name attribute of your submit-button.
Your script is very vulnerable to SQL-Injection. You really should not simply throw the userinput into your query. You can use mysqli_real_escape_string() or Prepared Statements to protect your application.
To improve the readability of your code you could change the structure a little. In your admin1.php you should do the business logic before outputting any html. So you would first check if the form has been sent, then you do the database operation. The result of the check or the success/error-message of the database operation can be written into a variable until you output the content of your site.
This way everybody who starts reading the code immediately knows 'alright, this script is the target of some form and accesses the database for some write-operation'.

"echo" not shown in php

I am trying to display some variables and forms like a inbox type messages with "echo".
The problem is that the echo is not displayed and don't know how to repair it.
When i click on subject field on the subject title should show the "echo" but it doesn't.
Bellow is the code:
<?php
if(isset($_GET['msg_id'])){
$get_id = $_GET['msg_id'];
$sel_message = "select * from messages where msg_id='$get_id'";
$run_message = mysqli_query($con, $sel_message);
$row_message = mysqli_fetch_array($run_message);
$msg_subject = $row_message['msg_sub'];
$msg_topic = $row_message['msg_topic'];
$reply_content = $row_message['reply'];
//updating the unread message to read
$update_unread = "update messages set status='read' where msg_id='$get_id'";
$run_unread = mysqli_query($con, $update_unread);
echo "
<center><br />
<hr>
<h2>$msg_subject</h2><br/>
<p><b>Message:</b>$msg_topic</p><br />
<p><b>My reply:</b>$reply_content</p><br/>
<form action='' method='post'>
<textarea cols='60' rows='10' name='reply'></textarea><br /><br />
<input type='submit' name='msg_reply' value='Reply to this' />
</form>
</center>
";
}
if(isset($_POST['msg_reply'])){
$user_reply = $_POST['reply'];
if($reply_content!='no_reply'){
echo "<h2 align='center'>This message was already replied!</h2>";
exit();
} else {
$update_msg = "update messages set reply='$user_reply' where msg_id='$get_id'";
$run_update = mysqli_query($con, $update_msg);
echo "<h2 align='center'>Message was replied!</h2>";
}
}
}
?>
Bellow is the all code from my_messages.php. I decided to put it here all the code to avoid any questions regarding missing code information. Maybe will help to get the error.
The problem is at the end of the code when i try to click on my inbox and the messages are not displayed when i click on the sender subject. The form is not shown with the echo function.
<?php
session_start();
include("includes/connection.php");
include("functions/functions.php");
if(!isset($_SESSION['user_email'])){
header("location: index.php");
}
else{
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Welcome User!</title>
<link rel="stylesheet" type="text/css" href="styles/home_style.css" media="all">
</head>
<body>
<!-- Container starts -->
<div class="container">
<!-- Header Wrapper Starts -->
<div id="head_wrap">
<!-- Header Starts -->
<div id="header">
<ul id="menu">
<li>Home</li>
<li>Memebers</li>
<strong>Topics:</strong>
<?php
$get_topics = "select * from topics";
$run_topics = mysqli_query($con, $get_topics);
while($row= mysqli_fetch_array($run_topics)){
$topic_id = $row['topic_id'];
$topic_title = $row['topic_title'];
echo "<li><a href='topic.php?topic=$topic_id'>$topic_title</a></li>";
}
?>
</ul>
<form method="get" action="results.php" id="form1">
<input type="text" name="user_query" placeholder="Search a topic"/>
<input type="submit" name="search" value="Search"/>
</form>
</div>
<!-- Header Ends -->
</div>
<!-- Header Wrapper Ends -->
<!-- Content area starts -->
<div class="content">
<!-- User timeline starts -->
<div id="user_timeline">
<div id="user_details">
<?php
$user = $_SESSION['user_email'];
$get_user = "select * from users where user_email='$user'";
$run_user = mysqli_query($con, $get_user);
$row = mysqli_fetch_array($run_user);
$user_id = $row['user_id'];
$user_name = $row['user_name'];
$user_country = $row['user_country'];
$user_image = $row['user_image'];
$register_date = $row['register_date'];
$last_login = $row['last_login'];
$user_posts = "select * from posts where user_id='$user_id'";
$run_posts = mysqli_query($con, $user_posts);
$posts = mysqli_num_rows($run_posts);
//getting the number of unread messages
$sel_msg = "select * from messages where receiver='$user_id' AND status='unread' order by 1 DESC";
$run_msg = mysqli_query($con, $sel_msg);
$count_msg = mysqli_num_rows($run_msg);
echo "
<center><img src='user/user_images/$user_image' width='240' height='240'/></center>
<div id='user_mention'>
<p><strong>Name:<strong> $user_name</p>
<p><strong>Country:<strong> $user_country</p>
<p><strong>Last Login:<strong> $last_login</p>
<p><strong>Member Since:<strong> $register_date</p>
<p><a href='my_messages.php?inbox&u_id=$user_id'>Messages ($count_msg)</a></p>
<p><a href='my_posts.php?u_id=$user_id'>My Posts ($posts)</a></p>
<p><a href='edit_profile.php?u_id=$user_id'>Edit My Account</a></p>
<p><a href='logout.php'>Logout</a></p>
</div>
";
?>
</div>
</div>
<!-- User timeline ends -->
<!-- Content timeline starts -->
<div id="msg" align="center">
<p align="center">
My Inbox ||
Sent Items
</p>
<?php
if(isset($_GET['sent'])){
include("sent.php");
}
?>
<?php if(isset($_GET['inbox'])){ ?>
<table width="800" align="center">
<tr>
<th>Sender:</th>
<th>Subject</th>
<th>Date</th>
<th>Reply</th>
</tr>
<?php
$sel_msg = "select * from messages where receiver='$user_id' order by 1 DESC";
$run_msg = mysqli_query($con, $sel_msg);
$count_msg = mysqli_num_rows($run_msg);
while($row_msg= mysqli_fetch_array($run_msg)){
$msg_id = $row_msg['msg_id'];
$msg_receiver = $row_msg['receiver'];
$msg_sender = $row_msg['sender'];
$msg_sub = $row_msg['msg_sub'];
$msg_topic = $row_msg['msg_topic'];
$msg_id = $row_msg['msg_id'];
$msg_date = $row_msg['msg_date'];
$get_sender = "select * from users where user_id='$msg_sender'";
$run_sender = mysqli_query($con, $get_sender);
$row = mysqli_fetch_array($run_sender);
$sender_name = $row['user_name'];
?>
<tr align="center">
<td>
<a href="user_profile.php?u_id=<?php echo $msg_sender; ?>" target="_blank">
<?php echo $sender_name; ?>
</a>
</td>
<td><?php echo $msg_sub; ?></td>
<td><?php echo $msg_date; ?></td>
<td>Reply</td>
</tr>
<?php } ?>
</table>
<?php
if(isset($_GET['msg_id'])){
$get_id = $_GET['msg_id'];
$sel_message = "select * from messages where msg_id='$get_id'";
$run_message = mysqli_query($con, $sel_message);
$row_message = mysqli_fetch_array($run_message);
$msg_subject = $row_message['msg_sub'];
$msg_topic = $row_message['msg_topic'];
$reply_content = $row_message['reply'];
//updating the unread message to read
$update_unread = "update messages set status='read' where msg_id='$get_id'";
$run_unread = mysqli_query($con, $update_unread);
echo "<center><br/><hr>
<h2>$msg_subject</h2><br/>
<p><b>Message:</b>$msg_topic</p><br/>
<p><b>My reply:</b>$reply_content</p>
<br/>
<form action='' method='post'>
<textarea cols='60' rows='10' name='reply'></textarea><br/><br/>
<input type='submit' name='msg_reply' value='Reply to this'/>
</form>
</center>
";
}
if(isset($_POST['msg_reply'])){
$user_reply = $_POST['reply'];
if($reply_content!='no_reply'){
echo "<h2 align='center'>This message was already replied!</h2>";
exit();
}
else{
$update_msg = "update messages set reply='$user_reply' where msg_id='$get_id'";
$run_update = mysqli_query($con, $update_msg);
echo "<h2 align='center'>Message was replied!</h2>";
}
}
}
?>
</div>
</div>
<!-- Content area ends -->
</div>
<!-- Container ends -->
</body>
</html>
<?php } ?>
var_dump( $row_message)
after fetching from database to see what's in it.
Please consider changing this line
$row_message = mysqli_fetch_array($run_message);
To this
$row_message = mysqli_fetch_assoc($run_message);
mysqli_fetch_array does not return associative array as you want to access further in your code.
Please Make sure you are passing msg_id in query string like someurl?msg_id=1, else you won't see anything inside
if(isset($_GET['msg_id'])){
/* get msg_id details from db and show */
}
this is because here we are checking if msg_id is set then show content. ;)

PHP and HTML not updating the page with onchange

So basically I have a page built with php inline with html. When I select a new option from my dropdown or enter a new value in a text box I need it to change. I had this working when I was echoing all my HTML in php (noobish mistake I know) but now that I attempted to clean it up it seems to have stop working. Also all my database connections are working just fine so Im not sure whats going on. Full code listed below. Thanks for any help at all and please remember I am a bit new to this.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Megapixel Calculator</title>
<meta name="Megapixel Calculator" content="">
<meta name="Matthew Stair" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body style="background:#99CCFF;overflow:hidden;">
<?php
$host = "localhost";
$username = "root";
$pass = "";
$database = "database_camcalc";
$conn = mysql_connect($host, $username, $pass) or die (mysql_error());
mysql_select_db($database, $conn);
$query = "SELECT camera FROM camlist";
$result = mysql_query($query) or die (mysql_error());
if (isset($_POST['cameraDD']))
{
$camSelect = $_POST['cameraDD'];
}else{
$camSelect = 'SNV-5200';
}
$horiQuery = mysql_query("SELECT hori FROM camlist WHERE camera = '$camSelect'");
if (!$horiQuery) {
die("Failed: " . mysql_error());
}
$hori = mysql_fetch_row($horiQuery);
$sensorSize = mysql_query("SELECT sensor_size FROM camlist WHERE camera = '$camSelect'");
if (!$sensorSize) {
die("Failed: " . mysql_error());
}
$sensorQuery = mysql_query("SELECT camlist.width FROM camlist WHERE camlist.camera = '$camSelect'");
$sensorRow = mysql_fetch_array($sensorQuery);
$sensorWidth = floatval($sensorRow['width']);
if(isset($_POST['horizontalFOV'])){
if($_POST['horizontalFOV'] != 0){
$horiFOV = $_POST['horizontalFOV'];
}else{
$horiFOV = 20;
}
}else{
$horiFOV = 20;
}
if(isset($_POST['distToObj'])){
if($_POST['distToObj'] != 0){
$distObj = $_POST['distToObj'];
}else{
$distObj = 35;
}
}else{
$distObj = 35;
}
$lensCalc = ($distObj / $horiFOV) * $sensorWidth;
$lensCalcFix = number_format($lensCalc);
$ppfCalc = $hori[0] / $horiFOV;
?>
<div style="width:1000px; margin:auto;">
<div style="width:50%;float:left;">
<div style="float:left; width:100%;">
<?php
print("Select Camera: <select name='cameraDD' value='$camSelect' onchange='this.form.submit()'>");
while($row = mysql_fetch_assoc($result)) {
if($row['camera'] == $camSelect)
print("\r\n<option selected='selected' value='{$row['camera']}'>{$row['camera']}</option>");
else
print("\r\n<option value='{$row['camera']}'>{$row['camera']}</option>");
}
?>
</select>
</div>
<div style="float:left;width:50%;">
Lens Focal Length: <?php print("$lensCalcFix"); ?> MM
</div>
<div style="float:left;width:50%;">
<?php
print("Horizontal Field of View: <input style='width:50px;' type='text' name='horizontalFOV' value='$horiFOV' onchange='this.form.submit()'>");
?>
</div>
<img style="width:100%" src="/images/example.gif" alt="Example of horizontal field of view and distance to object">
<div>
<?php
print("Distance to Object: <input style='width:50px;' type='text' name='distToObj' value='$distObj' onchange='this.form.submit()'> Feet");
?>
</div>
</div>
<div style="width:40%;float:left;margin-left:10px;">
<div>
<?php
echo 'Pixels per Foot: ',
round($ppfCalc),
' PPF';
?>
</div
<div>
<?php
if ($ppfCalc < 19){
echo "<p style ='font-weight:bold;'>Level of detail: Too Low</p>";
echo "<img src='images/noimg.gif' alt='Pixel Per Foot Too Low'>";
}elseif ($ppfCalc >= 19 and $ppfCalc <=39){
echo "<p style ='font-weight:bold;'>Level of detail: Observation</p>";
echo "<img src='images/20ppf.gif' alt='Observation Level'>";
}elseif ($ppfCalc >=40 and $ppfCalc <=59){
echo "<p style ='font-weight:bold;'>Level of detail: Forensic Review</p>";
echo "<img src='images/40ppf.gif' alt='Forensic Review Level'>";
}elseif ($ppfCalc >=60 and $ppfCalc <=79){
echo "<p style ='font-weight:bold;'>Level of detail: Identification</p>";
echo "<img src='images/75ppf.gif' alt='Identification Level'>";
}elseif ($ppfCalc >=80){
echo "<p style ='font-weight:bold;'>Level of detail: Fine</p>";
echo "<img src='images/100ppf.gif' alt='Fine Level'>";
}
?>
<div style="width:300px;">
<p style="text-decoration:underline;font-weight:bold;">Observation (General Security) = 20 PPF</p>
<p> Allows for recognition of male/female, color of clothes, approximate height, color of skin, etc...</p>
<p style="text-decoration:underline;font-weight:bold;">Forensic Review (forensic detail)= 40 PPF</p>
<p>Allows for basic identification of forensic details</p>
<p style="text-decoration:underline;font-weight:bold;">Identification (high detail)= 60 PPF</p>
<p>Allows for facial recognition, point-of-sale tracking, etc...</p>
<p style="text-decoration:underline;font-weight:bold;">Fine = 80 PPF</p>
<p>Allows for detailed facial recognition such as license plate number, scars, birth marks, eye color, tattoos, etc...</p>
</div>
</div>
</div>
</div>
</body>
</html>

My php form will not submit through jQuery-Mobile

I have a fully working piece of PHP, HTML code but when I place it into my website that is styled using jQuery Mobile the submit button will not display the query. Does anybody know how to fix this or even why it is happening
SCRIPT
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>The School of Computing and Mathematics</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="themes/project1.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile.structure-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>
PHP
<body>
<div data-role="page">
<?php
// Create connection
$con=mysqli_connect('localhost', '', '', 'timetabledb');
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$course_dropdown ="";
$query_course = "SELECT * FROM course";
$result_course = mysqli_query($con,$query_course) or die(mysqli_error());
while($row = mysqli_fetch_assoc($result_course))
{
$course_dropdown .= "<option value='{$row['CourseName']}'>{$row['CourseName']}</option>";
}
$module_dropdown ="";
$query_module = "SELECT * FROM module";
$result_module = mysqli_query($con,$query_module) or die(mysqli_error());
while($row = mysqli_fetch_assoc($result_module))
{
$module_dropdown .= "<option value='{$row['ModuleName']}'>{$row['ModuleName']}</option>";
}
$day_dropdown ="";
$query_day = "SELECT * FROM days ";
$result_day = mysqli_query($con,$query_day) or die(mysqli_error());
while($row = mysqli_fetch_assoc($result_day))
{
$day_dropdown .= "<option value='{$row['Day']}'>{$row['Day']}</option>";
}
echo "<table border='1'>
<tr>
<th>Course Name</th>
<th>Module Name</th>
<th>Type of Class</th>
<th>Lecturer</th>
<th>Time</th>
<th>Day</th>
<th>Room</th>
</tr>";
if (isset($_POST['button']) && $_POST['button'] == 'Submit') {
$course = mysqli_real_escape_string($con, $_POST['Course']);
$module = mysqli_real_escape_string($con, $_POST['Module']);
$day = mysqli_real_escape_string($con, $_POST['Day']);
$query = "SELECT * FROM course_module WHERE CourseName = '$course' AND ModuleName = '$module' AND Day = '$day'";
$result = mysqli_query($con,$query);
while($row1 = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td>" . $row1['CourseName'] . "</td>";
echo "<td>" . $row1['ModuleName'] . "</td>";
echo "<td>" . $row1['ClassType'] . "</td>";
echo "<td>" . $row1['Lecturer'] . "</td>";
echo "<td>" . $row1['Time'] . "</td>";
echo "<td>" . $row1['Day'] . "</td>";
echo "<td>" . $row1['Room'] . "</td>";
echo "</tr>";
}
}
?>
HTML
<h1>School of Computing and Mathematics</h1>
<h2>Mobile website<h2>
<h2>Current students</h2>
<div data-role="collapsible-set" data-theme="c" data-content-theme="d">
<div data-role="collapsible">
<h3>Section 1</h3>
<p>I'm the collapsible content for section 1</p>
</div>
<div data-role="collapsible">
<h3>Section 2</h3>
<p>I'm the collapsible content for section 2</p>
</div>
<div data-role="collapsible">
<h3>Timetabling</h3>
<p>Select your Course</p>
<form action="current.php" method="post" data-ajax="false">
<select name="Course">
<option>Select Course</option>
<?php echo $course_dropdown; ?>
</select>
<select name="Module">
<option>Select Module</option>
<?php echo $module_dropdown; ?>
</select>
<select name="Day">
<option>Select Day</option>
<?php echo $day_dropdown; ?>
</select>
<input id ="button_timetable" name="button" value="Submit" type="submit">
</form>
</div>
<div data-role="footer" data-id="foo1" data-position="fixed">
<div data-role="navbar">
<ul>
<li>Home</li>
<li>News</li>
<li class="ui-btn-active ui-state-persist">Current students</li>
<li>Prospective students</li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</div>
</body>
</html>
Please keep in mind that this script is fully implemented on a plain HTML site. I am only having issues with the jQuery mobile library.
Thank You in advance
Let me give you an answer, I found everything going through your code.
Inside a index.php:
data-ajax="false" should be added as a form attribute, it prevents jQuery Mobile from using ajax to submit data.
Incorrect jQuery Mobile css was initialized in a HEAD
table tag was not closed
But, through and trough this is well built page.

Categories