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
Related
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>
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(); ?>
<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/
I'm try to run a while loop, i also want jquery form to process it so the page doesn't refresh. So far the code work, but it only used the jquery function on the first loop and for the others loops it open new page. I need some help solving this problem. thanks in advance...
(code)
$query = mysql_query("SELECT * FROM linkUP_message WHERE to_mem='$from_mem'
AND to_mem_burn='2' AND new_message='3' ORDER BY id DESC");
$num_rows = mysql_num_rows($query);
if ($num_rows < 1) {
echo '<div id="new_message" class="addlinkuplinks a"> You have no
message at this time. </div>';
}else {
while($row = mysql_fetch_array($query)){
$msg_id = $row['id'];
$msg_to_mem = $row['to_mem'];
$msg_from_mem = $row['from_mem'];
$msg_from_memID = $row['from_memID'];
$msg_subject = $row['subject'];
$msg_content = $row['content'];
$msg_date = $row['date'];
$msg_from_mem_burn = $row['from_mem_burn'];
$msg_to_mem_burn = $row['to_mem_burn'];
$sqlName=mysql_query("SELECT * FROM prociallinkup_members WHERE
email<>'$from_mem' AND email='$msg_from_mem' LIMIT 1")or die ("Sorry we
have a mysql error!");
while($row=mysql_fetch_array($sqlName)){
$msg_from_memAccount=$row["accountType"];
$msg_from_memID=$row["hdw_id"];
$msg_from_memEmail=$row["email"];
$msg_from_memfirstName=$row["firstName"];
$msg_from_memlastName=$row["lastName"];
$msg_from_mem_pic=$row["profile_pic"];
$gender=$row["gender"];}
echo '
<div id="linkUPmsg" class="linkUPmsg">
<table width="100%">
<tr>
<tr><td width="60%"align="left" valign="top"><span style="font-size:
12px; color: #CCCCCC;">Read Date:</span></td>
<td width="40%"align="right" valign="top"><span style="font-size: 12px;
color: #CCCCCC;">'.$msg_date.'</span></td>
</tr>
<table width="100%">
<tr>
<td width="5%" align="left">'.$profile_pic.'</td>
<td width="87%"align="left" ><span style="font-size: 14px; font-weight:
bold; color: #999999;">'.$msg_from_memfirstName.' '.$msg_from_memlastName.'</span>
<div id="requestlinkUP_text">Send you this message!</div>
<div id="requestlinkUP_text"">Subject: <span style="font-size: 12px;
font-weight: bold; color: #0066CC;">'.$msg_subject.'</span></div>
</td>
<div id="readmember_msg"></div>
<td width="3%" align="right"><div id="linkUPmsg_readR"><form id="readForm"
action="read_message.php" class="readform" method="get" enctype="multipart/form-data"
name="acceptlinkUP">
<input name="RfirstName" id="RfirstName" type="hidden"
value="'.$msg_from_memfirstName.'" />
<input name="RlastName" id="RlastName" type="hidden"
value="'.$msg_from_memlastName.'" />
<input name="Remail" id="Remail" type="hidden"
value="'.$msg_from_memEmail.'" />
<input name="Rdate" id="Rdate" type="hidden" value="'.$msg_date.'" />
<input name="Rcontent" id="Rcontent" type="hidden"
value="'.$msg_content.'" />
<input name="Rsubject" id="Rsubject" type="hidden"
value="'.$msg_subject.'" />
<input name="Rmsg_id" id="Rmsg_id" type="hidden" value="'.$msg_id.'" />
<input name="Rto_mem" id="Rto_mem" type="hidden" value="'.$msg_from_mem.'"
/>
<input name="read_linkUPmsg" class="msgAction" type="image"
src="/image/read_mail.png" width="25" height="25"/>
</form></div></a>
</td>
<td width="5%" align="right"><div id="linkUPmsg_burnR"
class="addlinkuplinks"><form id="burnForm_read" action="/burn_message.php"
class="burnForm_read" method="get" enctype="multipart/form-data"
name="burnlinkUP">
<input name="msg_id" type="hidden" value="'.$msg_id.'" />
<input name="to_mem" type="hidden" value="'.$msg_from_mem.'" />
<input name="burn_linkUPmsg" class="msgAction" type="image"
src="/image/burn_sign.png" width="20" height="25"/>
</form></div><div id="burnmember_msg"></div></a>
</td>
</tr>
</table>
</span>
</div>
<script type="text/javascript" src="/jquery.js"></script>
<script type="text/javascript" src="/jquery.form.js"></script>
<script type="text/javascript" src="/jquery.validate.js"></script>
<script type="text/javascript">
$("document").ready(function()
{
$("#burnForm_read").ajaxForm( {
target: "#burnmember_msg",
success: function() {
$("#linkUPmsg_readR").hide();
$("#linkUPmsg_burnR").hide();
}
});
});
</script>
';
}
}
You need to use array for input type names , as;
<input name="Rdate[]" id="Rdate" type="hidden" value="'.$msg_date.'" />
//do this for all your input fields
//and the on php side do
print_r($_POST);
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']