I'm working with a group in my Comp. Sci class on this website project with PHP, mySQL and HTML, and we're having some trouble with a search function.
Here is the full code:
<html>
<head>
<title>US Cities Database</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="index.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<script>
function doWhenReady () {
$('a').click(showMap);
};
function showMap(event) {
var element = $(event.currentTarget);
var lat = element.attr('lat');
var long = element.attr('long');
var url = "https://maps.google.com/maps?q="+lat+","+long+"&h1=es&z=12&t=m&output=embed";
$('iframe').attr('src', url);
}
$(document).ready(doWhenReady);
</script>
<body class="container">
<h4>US Cities Zip Code and Latitude / Longitude Locator</h4>
<p><strong>Make sure to enter the smaller Zip Code in the first box, and the larger Zip Code in the second box.</strong></p>
<form action="index.php" method="POST" class="form-inline">
<div class="form-group">
<label for="city">City</label>
<input type="text" class="form-control" name="city" />
</div>
<div class="form-group">
<label for="state">State</label>
<input type="text" class="form-control" name="state" />
</div>
<div class="form-group">
<label for="zipFrom">Zipcode from:</label>
<input type="text" class="form-control" name="zipFrom" />
</div>
<div class="form-group">
<label for="zipTo">to:</label>
<input type="text" class="form-control" name="zipTo" />
</div>
<button type="submit" class="btn btn-default btn-primary">Search</button>
</form>
<hr>
<div class="row">
<div class="col-md-5 scrollable">
<div class="search-results">
<h4>Search results:</h4>
<?php
$host = 'localhost';
$username = 'caleyhalpern';
$password = '';
$dbName = 'project224';
$db = mysqli_connect ($host, $username, $password, $dbName);
if (!$db) {
die("Failed to connect to MySQL: (" . mysqli_connect_errno() . ") " . $mysqli->connect_error);
}
$searchCity = $_POST['city'];
$searchState = $_POST['state'];
$searchZipCode = $_POST['zipcode'];
if ((isset($searchCity) || isset($searchState)) && (($searchCity != '') || ($searchState != '')))
$query = 'SELECT * FROM zips WHERE city LIKE "%'.$searchCity.'%" AND state LIKE "%'.$searchState.'%"';
$results = mysqli_query($db, $query);
$resultArray = mysqli_fetch_all($results, MYSQLI_ASSOC);
?>
<table class="table table-striped table-condensed small">
<thead>
<tr>
<th>Show</th>
<th>Zip</th>
<th>State</th>
<th>City</th>
<th>Lat</th>
<th>Long</th>
</tr>
</thead>
<tbody>
<?php
foreach($resultArray as $city) {
echo "<tr>";
echo '<td>Show</td>';
echo "<td>".$city['zip']."</td>";
echo "<td>".$city['state']."</td>";
echo "<td>".$city['city']."</td>";
echo "<td>".$city['lat']."</td>";
echo "<td>".$city['lng']."</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<?php
}
?>
</div>
</div>
<div class="col-md-7">
<div class="map">
<h4>Map:</h4>
<iframe src=""></iframe>
</div>
</div>
</div>
</body>
</html>
Sorry it's kind of lengthy, but if you scroll down to the PHP section, you'll see the "if((isset(...", and that's where we are having trouble. We have the search function for the cities and states, yet we're having trouble with the Zip Codes search function. We're trying to make it so the user inputs two zip codes, the smaller zip code going in the first search box, and the larger zip code going in the second search box. (For ex: 1st: 82190, and 2nd: 92120). And it will search for every zip code in between those two that the user put in. I understand that the search function will be similar to that of the city's/state's- we're just new to PHP and MySQL and are struggling a bit.
First, you need to check that the two zip code fields are numeric, and if not, then set a default value, say 00000 for $zipFrom and 99999 for $zipTo.
$zipFrom = $_POST['zipFrom'];
if (!is_numeric($zipFrom))
$zipFrom = 0;
Handle the value of $zipTo similarly. You should also check that $zipFrom <= $zipTo and swap them if not. (Always, always, always program defensively!) After that, the query itself is simple. Here's how to do it with a prepared statement:
$query = 'SELECT * FROM zips
WHERE zipcode >= ?
AND zipCode <= ?';
$stmt = $db->prepare($query);
$stmt->bind_param('ii', $zipFrom, $zipTo);
$stmt->execute();
$rslt = $stmt->get_result();
$resultArray = $rslt->fetch_all(MYSQLI_ASSOC);
The call to bind_param maps the two variables to the two question-mark placeholders in the query. The first argument ('ii') specifies the data types of the values.
I leave error handling as an exercise for the reader.
You could try something like this...
$query = "SELECT * FROM zips WHERE city LIKE '%".$searchCity."%')";
$result = mysqli_query($db, $query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo $row['zip'];
// echo any others you need
}
}
Related
How to display SQL result into text input?
When I press the generate button it should appear in the input text.
<?php
$random_name = "";
$conn = mysqli_connect("localhost","root","","wordlist");
if(!$conn)
{
die("Connection Error!");
}
$query_random = "SELECT kata FROM list ORDER BY RAND() LIMIT 1";
$result = mysqli_query($conn,$query_random);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$random_name = $row["kata"];
}
}
mysqli_close($conn);
?>
</head>
<body>
<div class="container" >
<form action="#">
<h4>Word Generator : </h4>
<div class="form-group">
<input type="text" class="form-control">
</div><br>
<button id="generate-btn" type="submit" title="Generate Word">Generate</button>
</div>
</form>
You just need to add this in place of your input, your code is correct but you missed to print the value, that's all
<input type="text" class="form-control" value="<?php echo #$random_name ?>">
I am trying to upload pdf file into database using MySql and PHP but only images like jpeg/png are getting stored in the database. I failed to upload pdf file into the database and retrieve it. Here is my HTML code with form-
<form id="form" name="form" onsubmit="return validate()" action="http://localhost:81/wordpress/wp-content/themes/themify-ultra/submit.php" enctype="multipart/form-data" method="POST">
<div class="form-row">
<div class="name">Name</div>
<div class="value">
<div class="input-group">
<input class="input--style-5" type="text" name="name" required>
</div>
</div>
</div>
<div class="form-row">
<div class="name">Email</div>
<div class="value">
<div class="input-group">
<input class="input--style-5" type="email" name="email" required>
</div>
</div>
</div>
<div class="form-row">
<div class="name">Phone</div>
<div class="value">
<div class="input-group">
<input class="input--style-5" type="number" name="contact" required>
</div>
</div>
</div>
<div class="form-row">
<div class="name">Upload Your Resume</div>
<div class="value">
<div class="input-group">
<input class="input--style-5" type="file" name="myfile">
</div>
</div>
</div>
<div>
<button class="btn" name="btn" type="submit">Submit</button>
</div>
</form>
Validate function is below-
<script>
function validate()
{
var name = document.forms["form"]["name"];
var email = document.forms["form"]["email"];
var phone = document.forms["form"]["contact"];
var resume = document.forms["form"]["myfile"];
if (name.value == "")
{
window.alert("Please enter your name.");
name.focus();
return false;
}
if (email.value == "")
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf("#", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf(".", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (phone.value == "")
{
window.alert("Please enter your telephone number.");
phone.focus();
return false;
}
if(resume.value=="")
{
window.alert("Please upload your resume.");
resume.focus();
return false;
}
return true;
}</script>
PHP code to upload data into the database is this-
<?php
$conn = new PDO('mysql:host=localhost;port=3306;dbname=test',
'root',
'',
array(PDO::ATTR_PERSISTENT => true));
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
if(isset($_POST['btn']))
{
$name2 = $_POST['name'];
$email2 = $_POST['email'];
$contact2 = $_POST['contact'];
$allowedExts = array("pdf");
$name=$_FILES['myfile']['name'];
$type=$_FILES['myfile']['type'];
$data=file_get_contents($_FILES['myfile']['tmp_name']);
$data = addslashes($data);
$query = "INSERT INTO wp_form (name,email,phone_number,file_name,type,data,description) VALUES (?,?,?,?,?,?,NOW())";
$result = $conn->prepare($query);
$result->execute(array($name2,$email2,$contact2,$name,$type,$data));
header("Location: https://www.example.com/thankyou");
}
?>
PHP to fetch data from the database is this-
<!DOCTYPE html>
<html>
<head>
<title></title>
<!DOCTYPE html>
<html>
<head>
<title>Catalog</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
</body>
</html>
<?php
$conn = new PDO('mysql:host=localhost;port=3306;dbname=test',
'root',
'',
array(PDO::ATTR_PERSISTENT => true));
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$query = "SELECT * from wp_form";
$result = $conn->prepare($query);
$result->execute();
echo "<table border='1' cellpadding='0' cellspacing='0'>
<tr height='50'>
<td align='center' width='150'><b>S.No</b></td>
<td align='center' width='150'><b>Name</b></td>
<td align='center' width='300'><b>Email</b></td>
<td align='center' width='150'><b>Phone Number</b></td>
<td align='center' width='150'><b>Resume</b></td>
<td align='center' width='150'><b>Description</b></td>
</tr></table>";
while ($row=$result->fetch()) {
echo "<table border='1' cellpadding='0' cellspacing='0' ><tr height='50'>
<td align='center' width='150'>".$row['id']."</td>
<td align='center' width='150'>".$row['name']."</td>
<td align='center' width='300'>".$row['email']."</td>
<td align='center' width='150'>".$row['phone_number']."</td>
<td align='center' width='150'><a target='_blank' href='http://localhost:81/wordpress/wp-content/themes/themify-ultra/view.php?id=".$row['id']."'>".$row['file_name']." </a></td>
<td align='center' width='150'>".$row['description']."</td>
</tr>
</table>";
}
?>
Images are getting stored in the database but when I am trying to upload pdf file it doesn't work. Anyone can please tell me where I am getting wrong.
Question,
What is the size and datatype of the column where you want to store the content of the file? you can't use large content in a smaller length. Some times, this is the real problem and not the code itself.
Why not convert the content of the file to hexa decimal then save it to the database? like: $data=file_get_contents($_FILES['myfile']['tmp_name']);
$hexa = bin2hex($data);
. Then you can just create the file again after you retrieve the stored hexadecimal using file streaming in PHP.
Hope that it will help.
I'm having a small college project about discussion room service. Right now I'm being tasked to implement autocomplete feature of name that orders it. I already google some tutorials. I'm not sure what went wrong, when i try to type a name, there's no data being typed ahead.
Here's my form code:
<?php
$host = "localhost";
$user = "root";
$pass = "";
$name = "pinjamruang";
$koneksi = mysqli_connect($host, $user, $pass, $name);
//Periksa apakah koneksi berhasil
if(mysqli_connect_errno()){
echo "Error: ";
echo mysqli_connect_error();
echo "<br /> Error Code: ";
echo mysqli_connect_errno();
die();
}
$sql = "SELECT * FROM ruangan
WHERE id = $_GET[id]";
$hasil = mysqli_query($koneksi,$sql);
$row = mysqli_fetch_assoc($hasil);
$sql2 = "SELECT * FROM shift
WHERE id = $_GET[shift]";
$hasil2 = mysqli_query($koneksi,$sql2);
$row2 = mysqli_fetch_assoc($hasil2);
?>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(function() {
$( "#typeahead" ).autocomplete({
source: 'typeaheads.php';
});
});
</script>
<h1> Konfirmasi Pemesanan Ruang <?php echo $row['kode']; ?></h1><br>
<form class="form-horizontal" action="process/process-order-ruang.php" method="post">
<div class="form-group">
<label for="inputNamaPemesan" class="col-sm-2 control-label">Nama</label>
<div class="col-sm-10">
<input type="text" name="nama_pemesan" class="form-control" id="typeahead" placeholder="Nama Pemesan">
</div>
</div>
<div class="form-group">
<label for="inputKeperluan" class="col-sm-2 control-label">Keperluan</label>
<div class="col-sm-10">
<select name="keperluan" class="form-control" id="inputKeperluan">
<option value="Diskusi Belajar">Diskusi Belajar</option>
<option value="Diskusi Tugas">Diskusi Tugas</option>
<option value="Dokumentasi">Dokumentasi</option>
<option value="Lain-lain">Lain-lain</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputWaktu" class="col-sm-2 control-label">Waktu</label>
<div class="col-sm-10">
<input type="text" class="col-sm-5" name="waktu" value="<?php $row2['shift'];
$timestamp = strtotime($row2['shift']);
$waktuk = date('H.i A', $timestamp);
$int = (int)$waktuk;
echo $int; ?>:00" disabled> - <input type="text" class="col-sm-5"value="<?php $row2['shift'];
$timestamp = strtotime($row2['shift']);
$waktuk = date('H.i A', $timestamp);
$int = (int)$waktuk;
echo $int+2; ?>:00" disabled>
</div>
</div>
<?php $shift = $_GET['shift'];
$ruangan = $_GET['id'];?>
<input type="hidden" value="<?php $int2 = (int)$shift;?>" name="shift">
<input type="hidden" value="<?php $int3 = (int)$ruangan;?>" name="ruangan">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Pesan</button>
</div>
</div>
</form>
and here is my code which should return json data from my table
<?php
$host = "localhost";
$user = "root";
$pass = "";
$name = "pinjamruang";
$koneksi = mysqli_connect($host, $user, $pass, $name);
//connect with the database
//get search term
$searchTerm = $_GET['term'];
//get matched data from table
$query = $koneksi->query("SELECT * FROM user
WHERE nama LIKE '%".$searchTerm."%' ORDER BY nama ASC");
while ($row = $query->fetch_assoc()) {
$data[] = $row['nama'];
}
//return json data
echo json_encode($data);
?>
Any help would be much appreciated. Thanks a lot!
Use below code in script. remove semicolon from source. You can use colon for other parameters.
<script>
$(function() {
$( "#typeahead" ).autocomplete({
source: 'typeaheads.php'
});
});
</script>
So work on a school project, and I'm trying to create a way to update an existing product on a page, only it's price and description that I want to update. I just can't work out where I'm going wrong. Thanks in advance.
Now on the update.php page I have created a function so that it dynamically display products in a option, selection form.
This is the error,
query failedYou have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'WHERE product = SAMSUNG 60" FULL HD QUAD CORE 3D SMART LCD LED TV' at line 1.
This is my update function
function updateData() {
if(isset($_POST['submit'])) {
global $db;
$itemName = $_POST['product'];
$itemprice = $_POST['itemPrice'];
$itemDescription = $_POST['itemDescription'];
$query = "UPDATE products SET ";
$query .= " price = `$itemprice`, ";
$query .= " description = `$itemDescription`, ";
$query .= " WHERE product = `$itemName` ";
$result = mysqli_query($db, $query);
if(!$result) {
die("query failed" . mysqli_error($db));
} else {
echo "Your details have been updated";
}
}
}
and here is my update.php page
require_once ("Includes/simplecms-config.php");
require_once ("Includes/connectDB.php");
include("Includes/header.php");
include("functionsphp.php");
confirm_is_admin();
updateData();
// max file size for the html upload form
$max_file_size = 50 * 1024 * 1024; // size in bytes
// directory that will recieve the uploaded file
$dir = 'Images/products/';
?>
<div id="container">
<div id="admin">
<h1>update Product</h1>
<form id="product_form" class="dialogform"
action="editProduct.php" method="post" enctype="multipart/form-
data">
<div class="form_description">
<p>Fill in the details below to update details to the
catalog item.</p>
<select class="description" name="product" id="">
<?php ShowProduct();?>
</select>
</div>
<div id="container">
<div id="admin">
<h1>update Product</h1>
<form id="product_form" class="dialogform"
action="addProduct.php" method="post" enctype="multipart/form-
data">
<div class="form_description">
<p>Fill in the details below to update the product to
the catalog.</p>
</div>
<label class="description" for="itemPrice">Price</label>
<div>
<input id="itemPrice" name="itemPrice" type="text"
maxlength="255" />
</div>
<label class="description"
for="itemDescription">Description</label>
<div>
<textarea style="width: 350px; height: 108px;"
id="itemDescription" name="itemDescription"></textarea>
</div>
<input id="submit_button" class="button_text"
type="submit" name="submit" value="Submit" />
</form>
</div>
</div>
$query = "
UPDATE products
SET price = $itemprice
, description = '$itemDescription'
WHERE product = '$itemName'
";
Now see about prepared and bound queries. And as has been mentioned, the where clause should reference the primary key
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
In html code:
<select name="123023d">
<option value="default">Not Share</option>
<option value="read">Read Only</option>
<option value="edit">Editable</option>
</select>
In php code:
$rights=$_POST['123023d'];
Why i can not retrieve the value of this select box?
Notice: Undefined index: 123023d in C:\xampp\htdocs\fyp\list\add.php on line 87
Thank you.
I am sure it is in the form and it is a post method. It is located after foreach ($result as $set) as you can see i draw some sql value to generate that select box and the name of the select box is userID
Whole part:
<form id="addlist" method="post" action="add.php" >
<h1>Create your new subscriber list</h1>
<p>Create a new list before adding subscriber <label class="right"><em class="dot">*</em> indicates required</label></p>
<label><em class="dot">*</em> List name:
<span class="small">Add your list name</span>
</label>
<input id="lname" name="lname" class="required" />
<div class="spacer"></div>
<label>Reminder:
<span class="small">Remind the details of your list</span>
</label>
<textarea id="creminder" name="creminder" cols="52" ></textarea>
<div class="spacer"></div>
<div class="spacer"></div>
<p>Email me when ...</p>
<label>People subscribe:</label> <input type="checkbox" class="checkbox" name="subscribe" value="1">
<label>People unsubscribe:</label> <input type="checkbox" class="checkbox" name="unsubscribe" value="1">
<div class="spacer"></div>
</div>
</br>
<div id="stylized" class="myform">
<p>Permission Setting ...</p>
<label>Open to other users:</label> <input type="checkbox" class="checkbox" name="public" value="1">
Or
<div class="spacer"></div>
Select the permission for individual user:
<?
$sql =
"SELECT UserID,Name,Rights,Position
FROM user
WHERE UserID != ?
AND Rights != 'Admin'
";
$stmt = $conn->prepare($sql);
$stmt->execute(array($_SESSION['username']));
$num_rows= $stmt->rowCount();
if ($num_rows != 0){
$result = $stmt->fetchAll();
?>
<table width="100%" class="display" id="viewSub">
<thead>
<tr>
<th field="col1" width="40%">Name:</th>
<th field="col2" width="40%">Position:</th>
<th field="col2" width="20%">Permission:</th>
</tr>
</thead>
<tbody>
<?
foreach ($result as $set)
{
echo "<tr><td>".$set['Name']."</td><td>".$set['Position']."</td><td><select name=".$set['UserID']."><option value='default'>Not Share</option><option value='read'>Read Only</option><option value='edit'>Editable</option></select></td></tr>";
}
?>
</tbody>
</table>
<?
}
else
echo "There is no another user in this system";
?>
<input class="submit" type="submit" name="submit" value="Submit"/>
<div class="spacer"></div>
</form>
add.php which is the form and the result process
<?
include("../connection/conn.php");
session_start();
if($_SERVER['REQUEST_METHOD'] == "POST"){
print_r($_POST);
exit();
if (!isset($_POST['subscribe']))
$_POST['subscribe']=0;
if (!isset($_POST['unsubscribe']))
$_POST['unsubscribe']=0;
if (!isset($_POST['public']))
$_POST['public']=0;
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$listName = $_POST['lname'];
$listRemindSub = $_POST['subscribe'];
$creator = $_SESSION['username'];
$listRemindUnSub = $_POST['unsubscribe'];
$isPublic = $_POST['public'];
$listReminder = $_POST['creminder'];
$query="INSERT INTO list (ListID,ListName,Creator,IsRemindSub,IsRemindUnSub,IsPublic,CreateDate,Reminder) VALUES ('',?,?,?,?,?,CURDATE(),?)";
$stmt = $conn->prepare($query);
$stmt->bindParam(1, $listName , PDO::PARAM_STR);
$stmt->bindParam(2, $creator, PDO::PARAM_STR);
$stmt->bindParam(3, $listRemindSub, PDO::PARAM_INT);
$stmt->bindParam(4, $listRemindUnSub, PDO::PARAM_INT);
$stmt->bindParam(5, $isPublic, PDO::PARAM_INT);
$stmt->bindParam(6, $listReminder, PDO::PARAM_STR);
$stmt->execute();
}
catch(PDOException $e)
{
die ($e->getMessage().' Back');
$conn->rollBack();
}
try {
$lastID=$conn->lastInsertId();
$query="INSERT INTO require_attributes (ReqID,ListID,Attribute,Tag) VALUES ('',$lastID,'Email','{email}')";
$stmt = $conn->prepare($query);
$stmt->execute();
$query="INSERT INTO require_attributes (ReqID,ListID,Attribute,Tag) VALUES ('',$lastID,'FirstName','{fname}')";
$stmt = $conn->prepare($query);
$stmt->execute();
$query="INSERT INTO require_attributes (ReqID,ListID,Attribute,Tag) VALUES ('',$lastID,'LastName','{lname}')";
$stmt = $conn->prepare($query);
$stmt->execute();
}
catch(PDOException $e)
{
die ($e->getMessage().' Back');
$conn->rollBack();
}
try{
$sql = '
SELECT UserID
FROM user
WHERE Rights != ?';
$stmt = $conn->prepare($sql);
$stmt->execute(array('admin'));
$result= $stmt->fetchAll();
}
catch(PDOException $e)
{
die ($e->getMessage().' Back');
}
foreach ($result as $set)
{
if ($set['UserID']==$_SESSION['username'])
$rights='edit';
else
{$rights=$_POST[$set["UserID"]];
$rights=$_POST['123023d'];}
if ($rights != 'default' || $set['UserID']==$_SESSION['username'] || $_POST['public']==0)
{
$user=$set['UserID'];
try {
$query="INSERT INTO user_list(UserID,ListID,UserRights) VALUES ('$user',$lastID,'$rights')";
$stmt = $conn->prepare($query);
$stmt->execute();
}
catch(PDOException $e)
{
die ($e->getMessage().' Back');
$conn->rollBack();
}
}
}
$conn = null;
?>
<div id="stylized" class="myform">
<div style="text-align:center;font-weight:bold;">You have created a list. By default Mail Address, First Name , Last Name is in your list. Add more field if you want. <a href='add.php'>Back</a></div>
<div class="spacer"></div>
</div>
<?
}else{?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#import "../plugin/easyui/themes/default/easyui.css";
#import "../plugin/easyui/themes/icon.css";
#import "../style/form.css";
#import "../plugin/datatable/media/css/demo_page.css";
#import "../plugin/datatable/media/css/demo_table.css";
</style>
<script src="../plugin/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="../plugin/easyui/jquery.easyui.min.js"></script>
<script src="../plugin/jquery.validate.min.js"></script>
<script type="text/javascript" src="../plugin/datatable/media/js/jquery.dataTables.js"></script>
<script src="../plugin/jquery.form.js"></script>
<script>
$(document).ready(function(){
$("#addlist").validate();
});
$(document).ready(function() {
$('#viewSub').dataTable();
} );
</script>
</head>
<body>
<div id="stylized" class="myform">
<form id="addlist" method="post" action="add.php" >
<h1>Create your new subscriber list</h1>
<p>Create a new list before adding subscriber <label class="right"><em class="dot">*</em> indicates required</label></p>
<label><em class="dot">*</em> List name:
<span class="small">Add your list name</span>
</label>
<input id="lname" name="lname" class="required" />
<div class="spacer"></div>
<label>Reminder:
<span class="small">Remind the details of your list</span>
</label>
<textarea id="creminder" name="creminder" cols="52" ></textarea>
<div class="spacer"></div>
<div class="spacer"></div>
<p>Email me when ...</p>
<label>People subscribe:</label> <input type="checkbox" class="checkbox" name="subscribe" value="1">
<label>People unsubscribe:</label> <input type="checkbox" class="checkbox" name="unsubscribe" value="1">
<div class="spacer"></div>
</div>
</br>
<div id="stylized" class="myform">
<p>Permission Setting ...</p>
<label>Open to other users:</label> <input type="checkbox" class="checkbox" name="public" value="1">
Or
<div class="spacer"></div>
Select the permission for individual user:
<?
$sql =
"SELECT UserID,Name,Rights,Position
FROM user
WHERE UserID != ?
AND Rights != 'Admin'
";
$stmt = $conn->prepare($sql);
$stmt->execute(array($_SESSION['username']));
$num_rows= $stmt->rowCount();
if ($num_rows != 0){
$result = $stmt->fetchAll();
?>
<table width="100%" class="display" id="viewSub">
<thead>
<tr>
<th field="col1" width="40%">Name:</th>
<th field="col2" width="40%">Position:</th>
<th field="col2" width="20%">Permission:</th>
</tr>
</thead>
<tbody>
<?
foreach ($result as $set)
{
echo "<tr><td>".$set['Name']."</td><td>".$set['Position']."</td><td><select name=".$set['UserID']."><option value='default'>Not Share</option><option value='read'>Read Only</option><option value='edit'>Editable</option></select></td></tr>";
}
?>
</tbody>
</table>
<?
}
else
echo "There is no another user in this system";
?>
<input class="submit" type="submit" name="submit" value="Submit"/>
<div class="spacer"></div>
</form>
<div class="spacer"></div>
</div>
<br><br><br>
<div id="stylized" class="myform">
<?
try{
$sql = '
SELECT *
FROM list,user_list
WHERE user_list.UserID=?
AND list.ListID=user_list.ListID
';
$stmt = $conn->prepare($sql);
$stmt->execute(array($_SESSION['username']));
$result= $stmt->fetchAll();
$num_rows= $stmt->rowCount();
}
catch(PDOException $e)
{
die ($e->getMessage().' Back');
}
$conn = null;
if ($num_rows == 0) {
echo '<div style="text-align:center;font-weight:bold;">You have not created any list yet.</div>';}
else {
echo '<h1>Your Subscriber List</h1> <p>You have created '.$num_rows.' list(s).</p>';
foreach ($result as $set)
{
echo '<div style="font-weight:bold;">List Name : '.$set['FromName'].'</div><br>';
echo '<div style="font-weight:bold;">Subscriber : </div><br>';
echo '<div style="font-weight:bold;">Create Date : '.$set['CreateDate'].'</div><br>';
echo '<hr>';
}}
?>
<div class="spacer"></div>
</div>
</div>
</body>
</html>
<?
}
?>
Note the method you are using to submit the form. There are two general ways
GET Method <form method="GET" ... >
This is generally retrieved by using
echo $_GET['123023d'];
POST Method <form method="POST" ... >
This is generally retrieved by using
echo $_POST['123023d'];
If no method is defined, by default, it will be submitted using GET method so, use
$rights=$_GET['123023d'];
Update
I found your problem, there is no quotes in the title of select box
<select name=".$set['UserID'].">
Change it to this. You have to provide the quotes and escape them as well.
<select name=\"".$set['UserID']."\">
Update 2
Credit to #zerkms
The another problem was starting the name with a numeric value instead of a alphabetically character.
<select name="123023d">
Make sure you dont start with numbers like
<select name="a123023d">
How to retrieve value from a select box?
it is stored in the $_POST['123023d'] or $_GET['123023d'] variable depends on the method used.
If it is a 'post' request , use :
$rights=$_POST['123023d'];
For 'get' requests :
$rights=$_GET['123023d'];