value $_POST from others page can't pass throught isset form - php

I have a problem on pass value $result from different page into another page.
when I POST the value $result into this page. It works fine and I echo it out.
but if i try to pass this $result into isset() form and post it back to self.
The value will become Undefined index.
PAGE1
<?PHP
$connect=mysql_connect('localhost', 'root', '');
$db=mysql_select_db('survey', $connect);
$SQL="SELECT * FROM question";
$data=mysql_query($SQL);
$num=mysql_num_rows($data);
$start=0;
?>
<style type="text/css">
#survey{
width:100%; height:50px;
background:#e6e6e6; border-bottom:solid 1px white;
}
#survey form{
position:relative;
left:320px; top:15px;
float:left;
}
#survey form a{
text-decoration:none;
color:black;
}
.submit{
background-color: transparent;
border: none;
cursor: pointer;
}
</style>
<html>
<div id="container">
<?PHP
if($num<3){
echo "
<div id='create'><a href='question.php'>+ Create a Survey</a></div>
";
}
?>
<?PHP
while($start<$num){
$result=mysql_result($data, $start, 'ID');
$list_num=$start+1;
$ID=$result['ID'];
$list="
<div id='survey'>
<span style='font-size:24px; color:gray; position:relative; float:left; left:10px; top:13px;'>
SURVEY 0$list_num
</span>
<form action='survey.php' method='POST'>
<input class='submit' type='submit' name='submit1' value='View' />
<input type='hidden' name='result' value='$ID'/>
</form>
<form action='update.php' method='POST'>
<input class='submit' type='submit' name='submit2' value='Edit' />
<input type='hidden' name='result' value='$ID'/>
</form>
<form action='delete.php' method='POST'>
<input class='submit' type='submit' name='submit3' value='&#10005 Delete' />
<input type='hidden' name='result' value='$ID'/>
</form>
</div>
";
echo $list;
$start++;
}
?>
</div>
</html>
PAGE2
<?PHP
$result=$_POST['result'];
$error="";
if(isset($_POST['submit'])){
$question=$_POST['question'];
$answer_a=$_POST['a'];
$answer_b=$_POST['b'];
$answer_c=$_POST['c'];
if($question && $answer_a && $answer_b && $answer_c){
$connect=mysql_connect("localhost", "root", "");
$db=mysql_select_db("survey", $connect) or die("");
$SQL="UPDATE question SET question='$question', answer_a='$answer_a', answer_b='$answer_b', answer_c='$answer_c'
WHERE ID='$result'";
mysql_query($SQL);
$SQL="UPDATE answer SET question='$question', answer_a='0', answer_b='0', answer_c='0'
WHERE ID='$result' ";
mysql_query($SQL);
header("location:create.php");
}
else{$error="<div style='color:white; background:gray; width:200px; height:20px; text-align:center; line-height:20px;'>"
. "Please fill all the field." . "</div>";}
}
?>
<style>
body{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}
</style>
<html>
<form action="update.php" method="POST">
Question<br /><input type="text" name="question" placeholder=" Enter your question here" maxlength="50" /><br/><br/>Answer<br/>
a<input type="text" name="a" placeholder=" Answer a" maxlength="50"/>
b<input type="text" name="b" placeholder=" Answer b" maxlength="50"/>
c<input type="text" name="c" placeholder=" Answer c" maxlength="50"/>
<input type="submit" name="submit" value="SAVE"/>
</form>
<?PHP echo $error; ?>
</html>

Hi All thank you very much for help
I have found the solution
I think the problem is when I pass the value to 2nd form, I will need to resend the value again. Here is what I did.
1st one is from previous page, 2nd one is form post to itself
if(isset($_POST['result'])){
$result=$_POST['result'];
echo $result;
}
if(isset($_POST['data'])){
$ID=$_POST['data'];
echo $ID;
}
add another hidden in the form and resend the value
<input type="hidden" name="data" value="<?PHP echo $result;?>"/>
change the mysql value
WHERE... ID='$ID'";

Try editing on page 2 this
<html>
<form action="update.php" method="POST">
To this
<html>
<form action="" method="POST">

Related

How to add a CSS class on HTML button via PHP

I have registration form and I need to hide submit button. This button will be visible after action in PHP.
I tried to use CSS classes and it works, but I don't know how to add a class with PHP.
Here is button with class I want to change:
<form method="post" action="register.php" name="registerform">
<input type="submit" name="register" value="registrovat" id="button8" class=I don't know what /><br><br>
</form>
My CSS:
#button8{
visibility: hidden;
font-family: century gothic;
color: #0099FF;
border: 2px solid #0099FF;
background: transparent;
}
#button8.visible{
visibility: visible;}
I need to change to button8.visible but in PHP (I have condition depend on MySQL data).
EDIT:
I need it because, the button will be visible based on code. User put the code, press a button. This action will run PHP: connect to mySQL find if this code is in database. If yes I need my button to be visible. Because of my low knowledge, I want to use if condition in the same PHP session where is mySQL. Here is the whole code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<title>Panákovač 4.0</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
</head>
<body>
</body>
</html>
<?php
// show potential errors / feedback (from registration object)
if (isset($registration)) {
if ($registration->errors) {
foreach ($registration->errors as $error) {
echo $error;
}
}
if ($registration->messages) {
foreach ($registration->messages as $message) {
echo $message;
}
}
}
?>
<!-- register form -->
<form method="post" action="register.php" name="registerform">
<input id="login_input_username" class="login_input" type="text" pattern="[a-zA-Z0-9]{2,64}" name="user_name" placeholder="uživatelské jméno" required /><br>
<input id="login_input_password_new" class="login_input" type="password" name="user_password_new" pattern=".{6,}" placeholder="heslo (min. 6 znaků)" required autocomplete="off" /><br>
<input id="login_input_password_repeat" class="login_input" type="password" name="user_password_repeat" pattern=".{6,}" placeholder="zopakujte heslo" required autocomplete="off" /><br>
<input id="login_input_firstname" class="login_input" type="text" name="user_firstname" placeholder="jméno" required /><br>
<input id="login_input_lastname" class="login_input" type="text" name="user_lastname" placeholder="příjmení" required /><br>
<input id="login_input_email" class="login_input" type="email" name="user_email" placeholder="e-mail" required /><br>
<input id="login_input_company" class="login_input" type="text" name="user_company" placeholder="firma" required /><br>
<input type="submit" name="register" value="registrovat" id="button8" class= /><br><br>
</form>
<form method="post" action="register.php" name="registerform">
<input id="login_input_code" class="login_input" type="text" name="user_code" placeholder="ověřovací kód" required /><br>
<input type="submit" name="kod" value="ověřit kód"/><br>
</form>
<?php
if(isset($_POST['kod'])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "login";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$user_code = $_POST['user_code'];
$sql = "SELECT `used`,`code` FROM `regcode` WHERE `code` LIKE '$user_code' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "kód: " . $row["code"]. " - použito: " . $row["used"]. $zob . "<br>";
$pouzito = $row["used"];
MY CONDION FOR CLASSES
}
} else {
echo "chybný kód" . $user_code;
}
$conn->close();
}
?>
You can add a php if condition inside the html content like this:
<form method="post" action="register.php" name="registerform">
<input type="submit" name="register" value="registrovat" id="button8"
class="<?php if(condition) { echo 'classname'; } ?>" />
</form>
In this case if the condition is true it will echo the class inside the class attribute, there are other ways to do it but this is the most intuitive way for new PHP developers.
Like #Jordi Nebot told you can just do the short version like:
<input class="<?= ($condition) ? 'classname' : ''"> ?>
only way in PHP is to echo the output
echo '<input type="submit" name="register" value="registrovat" id="button8"
class="class1">';
echo '<input type="submit" name="register" value="registrovat" id="button8"
class="class2">';
etc...
or
$class = "class1";
?>
input type="submit" name="register" value="registrovat" id="button8"
class="<?php echo $class; ?>">
<?php
$class = "class2";
?>
input type="submit" name="register" value="registrovat" id="button8"
class="<?php echo $class; ?>">
<?php
<?php $classname = condition ? 'class8' : 'defaultClass'; ?>
<form method="post" action="register.php" name="registerform">
<input type="submit" name="register" value="registrovat" id="button8" class="<?php echo $classname; ?>" /><br><br>
</form>
You can use ternary operator like:
<form method="post" action="register.php" name="registerform">
<input type="submit" name="register" value="registrovat" id="button8" class"<?= $condition ? 'classvisible' : 'classhidden'"?> />
</form>
I got it. I didn't know, that PHP has to be placed above HTML if i want to use variable from PHP.
IN PHP:
...//some condition
If ($row["used"] == 0){
$myclass ="zobrazeno";
}
...
In HTML
<input type="submit" name="register" value="registrovat" id="button8" class=<?php echo $myclass; ?> /><br><br>
In CSS:
#button8{
visibility: hidden;
font-family: century gothic;
color: #0099FF;
border: 2px solid #0099FF;
background: transparent;
#button8.zobrazeno{
visibility: visible;

Creating user specific tables?

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(); ?>

css for dynamic rows not working

<html>
<head>
<title>truck page</title>
<style type="text/css">
tr {
padding: 4px;
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$db = new mysqli("localhost", "root", "", "db1");
function getdata($form_element_name) {
$var = strip_tags($_GET[$form_element_name]);
return $var;
}
?>
<fieldset>
<legend> add a new truck </legend>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="GET">
<label>truck number <input type="text" name="truck_number" /></label>
<label>owner name <input type="text" name="truck_owner_name" /></label>
<label>owner phone <input type="text" name="truck_owner_ph" maxlength="10" /></label>
<input type="submit" name="truck_add" value="add" />
<input type="reset" />
</form>
<?php if(isset($_GET['truck_add'])) {
$truck_number = getdata('truck_number');
$truck_owner_name = getdata('truck_owner_name');
$truck_owner_ph = getdata('truck_owner_ph');
$sql_truck_add = "INSERT INTO truck (truck_number, truck_owner_name, truck_owner_ph)
VALUES ('$truck_number', '$truck_owner_name', '$truck_owner_ph' )";
$result_truck_add = $db->query($sql_truck_add);
header("Location: http://localhost/bkp/truckpage.php");
} ?>
</fieldset>
<table>
<tr>
<th>truck number</th>
<th>owner name</th>
<th>phone</th>
<th>operation</th>
<th></th>
</tr>
<?php
$sql_truck_retrieve = "SELECT * from truck";
$result_truck_retrieve= $db->query($sql_truck_retrieve);
while($row=$result_truck_retrieve->fetch_assoc()) {
$truck_num_current = $row['truck_number']; ?>
<tr id="<?php echo "{$truck_num_current}"; ?>">
<td><?php echo "{$row['truck_number']}"; ?></td>
<td><?php echo "{$row['truck_owner_name']}"; ?></td>
<td><?php echo "{$row['truck_owner_ph']}"; ?></td>
<td>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
<input type="hidden" name="truck_numcur" value="<?php echo "{$row['truck_number']}"; ?>" />
<input type="submit" name="truck_update" value="update" />
<input type="submit" name="truck_delete" value="delete" />
</form>
</td>
<td>
<?php // action to be taken if either update or delete is selected
if(isset($_GET['truck_update'])) {
$truck_numcur = $_GET['truck_numcur'];
if($truck_numcur == $truck_num_current) { ?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="GET">
<input type="hidden" name="truck_update_num" value="<?php echo "{$truck_numcur}"; ?>" />
<input type="text" name="truck_num_update" placeholder="truck number" />
<input type="text" name="owner_name_update" placeholder="owner name" />
<input type="text" name="owner_phone_update" placeholder="owner phone" />
<input type="submit" value="save" name="truck_update_yes" />
<input type="submit" value="cancel" name="truck_update_no" />
</form>
<?php }
}
else {
if(isset($_GET['truck_delete'])) {
$truck_numcur = $_GET['truck_numcur'];
if($truck_numcur == $truck_num_current) {
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
<span>confirm? </span>
<input type="hidden" name="truck_del_num" value="<?php echo "{$truck_numcur}"; ?>" />
<input type="submit" name="truck_delete_yes" value="yes" />
<input type="submit" name="truck_delete_no" value="no" />
</form>
<?php }
}
}
//
// action to be taken after delete confirmation
if(isset($_GET['truck_delete_yes'])) {
$truck_del_num = $_GET['truck_del_num'];
$sql_truck_del = "DELETE from truck WHERE truck_number = '{$truck_del_num}'";
$result_truck_del = $db->query($sql_truck_del);
header("Location: http://localhost/bkp/truckpage.php");
}
else {
if(isset($_GET['truck_delete_no'])) {
header("Location: http://localhost/bkp/truckpage.php");
//---------------------------------------------------------------------------
//header("Location: http://localhost/bkp/truckpage.php/#$truck_num_current");
//---------------------------------------------------------------------------
}
}
//
// action to be taken after update confirmation
if(isset($_GET['truck_update_yes'])) {
$truck_update_num = $_GET['truck_update_num'];
$truck_num_update = getdata('truck_num_update');
$owner_name_update = getdata('owner_name_update');
$owner_phone_update = getdata('owner_phone_update');
$sql_truck_update = "UPDATE truck SET truck_number = '$truck_num_update', truck_owner_name = '$owner_name_update', truck_owner_ph = '$owner_phone_update' WHERE truck_number = '{$truck_update_num}' ";
$result_truck_update = $db->query($sql_truck_update);
header("Location: http://localhost/bkp/truckpage.php");
}
else {
if(isset($_GET['truck_update_no'])) {
header("Location: http://localhost/bkp/truckpage.php");
}
}
//
?>
</td>
</tr>
<?php } ?>
</table>
</body>
I am trying to extract values from a db table and add them as table rows. The rows are being shown correctly but when I tried to add css styles for the table rows it did not work. I tried to give a border and padding.I am new to web development and cannot understand why the css part is not working.Can anyone please tell how to make the css part work in this php code?
The problem lies in that you cannot very effectively style tr elements. You will need to target the parent table or the child td elements to get the affect you're looking for.
Check out this JSFiddle example: http://jsfiddle.net/v6zNt/
CSS:
table {
border: 1px solid #000;
}
/* notice how these styles does not apply anywhere */
tr {
border: 1px solid green;
padding: 4px;
}
td {
border: 1px solid red;
padding: 4px;
}
HTML:
<table>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</table>
You can style tables, it's just that they have their own set of rules that you need to be mindful of. Here's a great introduction: http://css-tricks.com/complete-guide-table-element/

HTML PHP Help Form

I'm trying my best to generate a unique link with the following information from ID1 and ID2. I've even tested with echo and paste the following .html to the server and there weren't any respond and also tried it with echo also nothing.
I need help basically , thank you.
<form method="post" action="">
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Enter ID 1:</h1>
<input type="text" value="" name ="cid" id="cid" />
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Enter ID 2:</h1>
<input type="text" value="" name ="gid" id="gid"/>
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Copy Your Link Here</h1>
<textarea style="width:500px; height:50px;"></textarea><br /><br /><br />
<input type="submit" value="submit" name="submit" id="submit"/>
</form>
<?php
$cid = $_POST["cid"];
$gid = $_POST["gid"];
if(isset($_POST['submit']))
{
//I want to make a new link $url = "www.something.com/" together with the combination of ID 1 and ID2 .
Example : www.something.com/ID1+ID2 // I want like this if its possible
}
else
{
echo "You've failed";
}
?>
I need help if you don't mind
try this
<?php
$new_link = "";
if(isset($_POST['submit']))
{
if(isset($_POST['cid'],$_POST['gid']))
{
$cid = $_POST['cid'];
$gid = $_POST['gid'];
$new_link = "www.something.com/".$cid.$gid;
// if your input is integer and you want to add them then use this
// $new_link = "www.something.com/".($cid+$gid);
}
}
?>
<form method="post" action="">
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Enter ID 1:</h1>
<input type="text" value="" name ="cid" id="cid" />
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Enter ID 2:</h1>
<input type="text" value="" name ="gid" id="gid"/>
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Copy Your Link Here</h1>
<textarea style="width:500px; height:50px;"><?php echo $new_link;?></textarea><br /><br /><br />
<input type="submit" value="submit" name="submit" id="submit"/>
</form>
<form method="post" action="">
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Enter ID 1:</h1>
<input type="text" value="" name ="cid" id="cid" />
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Enter ID 2:</h1>
<input type="text" value="" name ="gid" id="gid"/>
<h1 style="color:#0CF; font-family:Arial, Helvetica, sans-serif;">Copy Your Link Here</h1>
<textarea style="width:500px; height:50px;"></textarea><br /><br /><br />
<input type="submit" value="submit" name="submit" id="submit"/>
</form>
<?php
if(isset($_POST['submit']))
{
$cid = $_POST["cid"];
$gid = $_POST["gid"];
//I want to make a new link $url = "www.something.com/" together with the combination of ID 1 and ID2 .
$emp = "Example : www.something.com/".$cid.$gid // I want like this if its possible
}
else
{
echo "You've failed";
}
?>

Submitting radio values in a PHP form to a MySQL table (updating value in table)

I am currently building a php form utilising the jQuery iPhone style radios (found at http://devgrow.com/iphone-style-switches/). By default the radio value is set to NO in the MySQL table for every new entry, but I am having difficulty submitting the form.
How will the form be able to tell the current status of the radio button (i.e. is it set to yes or no upon submission)? Also what MySQL code would I need to use to update the value in the table? This is the code I have so far.
PHP form code
<!--- iphone checkbox --->
<script type="text/javascript">
$(document).ready( function(){
$(".cb-enable").click(function(){
var parent = $(this).parents('.switch');
$('.cb-disable',parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox',parent).attr('checked', true);
});
$(".cb-disable").click(function(){
var parent = $(this).parents('.switch');
$('.cb-enable',parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox',parent).attr('checked', false);
});
});
</script>
<style type="text/css">
.cb-enable, .cb-disable, .cb-enable span, .cb-disable span { background: url(resources/switch.gif) repeat-x; display: block; float: left; }
.cb-enable span, .cb-disable span { line-height: 30px; display: block; background-repeat: no-repeat; font-weight: bold; }
.cb-enable span { background-position: left -90px; padding: 0 10px; }
.cb-disable span { background-position: right -180px;padding: 0 10px; }
.cb-disable.selected { background-position: 0 -30px; }
.cb-disable.selected span { background-position: right -210px; color: #fff; }
.cb-enable.selected { background-position: 0 -60px; }
.cb-enable.selected span { background-position: left -150px; color: #fff; }
.switch label { cursor: pointer; }
.switch input { display: none; }
</style>
</head>
<body style="text-align:left;">
<div style="padding: 15px;">
<span class="loginfail" style="font-size:24px; font-weight: bold">Notifications</span><p>
<?php include("progress_insertcomment.php"); ?>
<?php
// Make a MySQL Connection
mysql_select_db("speedycm_data") or die(mysql_error());
$query_comment = "select * from tbl_alert order by id desc limit 1";
$comment = mysql_query($query_comment, $speedycms) or die(mysql_error());
$row_comment = mysql_fetch_assoc($comment);
$totalRows_comment = mysql_num_rows($comment);
?>
<!--- add notification --->
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<span id="sprytextarea1">
<textarea id='comment' name="comment" style="height: 75px; width:330px;"><?php echo $row_comment['comment']; ?></textarea>
</span>
<p>
<button type="submit">Add</button>
<input type="hidden" name="notc" value="1"/>
</form>
<!--- notification history --->
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="0" cellspacing="2" cellpadding="2">
<?php
if ( $row_comment == 0 ) {
echo "<span style='font-size: 11px;'>No current alerts.</span>";
} else {
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM tbl_alert ORDER BY id DESC")
or die(mysql_error());
while($rows=mysql_fetch_array($result)){ ?>
<tr>
<td>
<?php
echo "<div class='bubble'><div class='pimped'>
<blockquote>" . $rows['comment'] . "
</blockquote></div>
<cite><strong>" . $rows['user'] . "</strong> # " . $rows['date'] . "</cite>
<span style='font-size: 10px;'>
<p>
<a href='editalert.php?id=". $rows['id'] ."' class='form' >Edit</a> • <a href='deletealert.php?id=". $rows['id'] ."' class='form'>Delete</a>
</span>
</div>
";
?>
</td>
<td valign="top" align="center"><div style="padding-left: 30px;"><span style="font-size: 10px;">Completed?</span>
<p class="field switch">
<!--- determine status of notification --->
<?php
$status = $rows['status'];
if ( $status == yes ) {
echo '<input type="radio" id="radio1" name="'.$rows['id'].'" value="no" checked/>
<input type="radio" id="radio2" name="'.$rows['id'].'" value="yes"/>
<label for="radio1" class="cb-enable selected"><span>Yes</span></label>
<label for="radio2" class="cb-disable"><span>No</span></label>';
} else {
echo '<input type="radio" id="radio1" name="'.$rows['id'].'" value="yes"/>
<input type="radio" id="radio2" name="'.$rows['id'].'" value="no" checked/>
<label for="radio1" class="cb-enable"><span>Yes</span></label>
<label for="radio2" class="cb-disable selected"><span>No</span></label>';
}
?>
</p>
</div></td>
</tr>
<tr>
<td></td>
<td align="center"><div style="padding-left: 30px;">
<button type="submit">Update</button>
<input type="hidden" name="notc2" value="1"/>
</div></td>
</tr>
<?php
}
}
?>
</table>
</form>
</div>
code to submit form
<?php
// 6) update notifications
if (array_key_exists('notc2',$_POST)) {
echo "<p style='font-size: 12px;'>Thank you. The notifications have been updated successfully.</p>";
echo "<span style='font-size: 12px;'>
<a onClick=\"history.go(-1)\" class='form'>Return</a>
<p></span>
";
exit;
};
?>
The information will be present within $_POST['<id>'] where <id> corresponds to the row in tbl_alerts as given in your php form:
echo '<input type="radio" id="radio1" name="'.$rows['id'].'" value="no" checked/>
<input type="radio" id="radio2" name="'.$rows['id'].'" value="yes"/>
(emphasis added)
You can (and should) verify that by adding a var_dump($_POST) up the top of your processing script.
It will be hard for your processing script to know the id value though so what you probably want is name the radio as some other name, and then add a hidden form field that will store the id.
ex. your radio buttons would appear:
<input type="radio" id="radio1" name="status" value="no" checked/>
<input type="radio" id="radio2" name="status" value="yes"/>
and then somewhere in your code you have:
echo '<input type="hidden" name="statusid" value="'.$rows['id'].'"/>';
That way, the radio button value will be in $_POST['status'] and the id of the row will be in $_POST['statusid']

Categories