How to retrieve value on from in php? - php

I am trying to retrieve value on php page but it's not retrieving value.
Here is my code
retrieve
<html>
<body>
<?php
include('conn.php');
$per_page = 3;
if($_GET)
{
$page=$_GET['page'];
}
$start = ($page-1)*$per_page;
$select_table = "select * from clientreg order by id limit $start,$per_page";
$variable = mysql_query($select_table);
?>
<form name="frmUser" method="post" action="">
<div style="width:100%;">
<table border="0" cellpadding="10" cellspacing="1" width="100%" class="tblListForm">
<tr class="listheader">
<td></td>
<td width="230" >*****</td>
</tr>
<?php
$i=1;
$j=0;
while($row = mysql_fetch_array($variable))
{
if($j%2==0)
$classname="evenRow";
else
$classname="oddRow";?>
<tr class="<?php echo $classname;?>">
<td><input type="checkbox" name="users[]" value="<?php echo $row["id"]; ?>" ></td>
</tr>
<?php
$j++;}
?>
<tr class="listheader">
<td colspan="9"><input type="button" name="update" id="onclick" value="Update" /> <input type="button" name="delete" value="Delete" onClick="setDeleteAction();" />
<input type="button" name="assign" id="assign" value="Assign" onClick="setLeadAssignAction();" />
<?php
$sql = mysql_query("SELECT *FROM login where role=1");
while ($row = mysql_fetch_array($sql)){
?>
<tr class="listheader">
<td><input type="checkbox" name="eid[]" value="<?php echo $row["eid"]; ?>" ><?php echo $row["username"]; ?></td>
</tr>
<?php
}
?>
</td>
</tr>
</table>
</div>
</form>
<form class="form" method ="Post"action="" id="contact">
<?php
if(isset($_POST["submit"]) && $_POST["submit"]!="") {
$rowCount = count($_POST["users"]);
for($i=0;$i<$rowCount;$i++) {
$result = mysql_query("SELECT * FROM clientreg WHERE Id='" . $_POST["users"][$i] . "'");
$row[$i]= mysql_fetch_array($result);
echo "shakti";
echo $row[$i]['id'];
}
}
?>
<img src="button_cancel.png" class="img" id="cancel"/>
<div id="left" style="height:400px;width:47%;float:left;margin-left:20px;margin-top:15px;border-radius:10px;">
<label>Lead Owner: <span>*</span></label>
<br/>
<input type="text" name="leadowner[]" id="lead" placeholder="Lead Owner"value=""/><br/>
<br/>
<label>First Name: <span>*</span></label>
<br/>
<input type="text" name="fname"id="fname" placeholder="Fname"/><br/>
<br/>
<label>Last Name: <span>*</span></label>
<br/>
<input type="text" name="lname" id="lname" placeholder="Lname"/><br/>
<br/>
<label>Mobile No: <span>*</span></label>
<br/>
<input type="text" name="mobile"id="mobile" placeholder="Mobile"/><br/>
<br/>
<label>Email Id: <span>*</span></label>
<br/>
<input type="text"name="email" id="email" placeholder="Email"/><br/>
</div>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Where am I wrong in this code?
Please sort out my problem
My problem is here
if(isset($_POST["submit"]) && $_POST["submit"]!="") {
$rowCount = count($_POST["users"]);
Any help will be appreciated
I have updated my code and added submit button.

You have two forms. Only the second form has a submit.
Form 1:
<form name="frmUser" method="post" action="">
<input type="checkbox" name="users[]" value="<?php echo $row["id"]; ?> ">
</form>
Form 2:
<form class="form" method ="Post"action="" id="contact">
<input type="submit" name="submit" value="Submit">
</form>
The if construct does not receive the $_POST["users"], because it receives only the POST of the second submitted form.
$rowCount = count($_POST["users"]);
$rowCount will always be 0.
Form 2:
...
<?php
$rowCount = 0;
if ($_POST["users"] != "") {
$rowCount = count($_POST["users"]);
} else if ($_POST["rowcount"] != "") {
$rowCount = $_POST["rowcount"];
}
?>
...
<form class="form" method ="Post"action="" id="contact">
...
<input type="submit" name="submit" value="Submit">
<input type="hidden" name="rowcount" value="<?php echo $rowCount; ?>">
</form>
Then the variable $rowCount will contain the count of the rows after the submit of any of the 2 forms.

Related

Update database from inserted table fields

I have made a table with editable fields and i have to add functionality to the update button. I have looked up many posts but cant seem to figure out how it works.
Heres what i have at this moment:
<?php
if (isset($_GET['update'])) {
$query = mysql_query("UPDATE iekartas SET
iernosauk='$Ierices_Nosaukums', tips='$Tips', razotajs='$Razotajs',
izgatdat='$Izgatavosanas_datums', adrese='$Adrese' where id='$Iekartas_ID'", $connection);
}
$query = mysql_query("select * from iekartas", $connection);
while ($row = mysql_fetch_array($query)) {
echo "<b><a href='iekartas.php?update={$row['Iekartas_ID']}'>{$row['Ierices_Nosaukums']}</a></b>";
echo "<br />";
}
?>
<tr>
<form action="ierices.php" method="post">
<td><input class="checkbox" type="checkbox" id="<?php echo $row['Iekartas_ID'] ?>" name="id[]"></td>
<td> <input type="text" name="iernosauk" value=" <?php echo $row["Ierices_Nosaukums"]; ?>"></td>
<td> <input type="text" name="tips" value=" <?php echo $row["Tips"]; ?>"></td>
<td> <input type="text" name="razotajs" value=" <?php echo $row["Razotajs"]; ?>"></td>
<td> <input type="text" name="izgatdat" value=" <?php echo $row["Izgatavosanas_datums"]; ?>"></td>
<td> <input type="text" name="adrese" value=" <?php echo $row["Adrese"]; ?>"></td>
<td> <input type="hidden" name="id" value=" <?php echo $row["Iekartas_ID"]; ?>"></td>
<?php
$i++;
}
?>
<button type="button" action="update.php" name="updatedb" class="btn btn-danger" id="updatedb" value=update>Atjaunot</button>
</tr>
</form>
Button is client side so your "update.php" won't be triggered when you click on button. What you have to do is change your button type to submit so your form will actually send a POST request when you click on the button and it will call the action on the form (ierices.php)
<form action="ierices.php" method="post">
...
<button type="submit" class="btn btn-danger" id="updatedb">Atjaunot</button>
</form

i want to update my database

1-now already i added some texts on my database then after i want to update my database
anybody can help me?
i hope someone can help me
<?php
mysqli_query($db,"INSERT INTO tasks (task,status)
VALUES ('$task','$status')");
header('location:SIMPLE.PHP');
}
}
if (isset($_GET['check_selected'])) {
foreach ($_GET['check_selected'] as $key => $value) {
$row = mysqli_query($db,"DELETE FROM tasks WHERE id =
$value;") or die(mysqli_error($db));
}
}
$tasks = mysqli_query($db,"SELECT * FROM tasks ORDER BY id DESC");
?>
<!DOCTYPE html>
<html>
<body>
<form method="GET" action="SIMPLE.PHP">
<input type="text" name="search" class="status_input" placeholder="TEXT" />
<input id='textbox' type='checkbox' value='1' name='status'>
<button type="submit" class="add_btn" name="submit">Add</button>
<p><?php echo $errors; ?></p>
</form>
<form action="SIMPLE.PHP" method="GET">
<tbody>
<tr>
<p><button type="submit" class="btn btn-success" name="save">DELETE</button></p>
<?php
foreach ($rows as $row_id => $row)
{
?>
<input name="check_selected[]" type="checkbox" value=<?php echo $row['id'];?>"/>
<input name = "checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['status'];?>"
<?PHP if($row['status']){echo 'checked';
}
?>
>
<td class= "task"><?php echo $row['task']?></td>
<?PHP
}
?>
</tr>
</tbody>
</form>
</body>
</html>

Dont clear textbox value in php

I am trying to GET the selected ID from the previous form and insert the id into another database. After inserting the data from the form the ID should not be cleared whereas other details can be cleared.
Here is the screenshot of from the form where ID has to be inserted
Screeshot
When the user clicks on Add image particular ID in which Add image is clicked as to be posted in another form.
After submitting the form the ID shouldnt be cleared. Whereas the other textbox can get cleared.
Here is the code
$query2 = "SELECT * FROM abc";
$result2=mysql_query($query2) or die("Query Failed : ".mysql_error());
if(isset($_POST['submit']))
{
$id= $_POST['id'];
if( ! ctype_alnum($id) )
die('invalid id');
$query = "SELECT id FROM `abc` WHERE `id` =$id";
$run = mysql_query($query);
if(mysql_num_rows($run)>0){
echo "<script>window.open('addimg.php?id=".$id."','_self')</script>";
}
else {
echo "<script>alert('No is Invalid!')</script>";
}
}
?>
<table width='300' align='center' border='1' cellpadding="5px" cellspacing="0px" style="color:#494949;font-size:12px; font-family:Cambria;">
<tr>
<td>ID</td>
<td>URl Small Image</td>
<td>URL Large Image</td>
<td>Add Image</td></tr>
<?php
while($row=mysql_fetch_array($result2))
{?>
<form method="post" action="report.php">
<tr><td>
<input type="text" name="id" class="input" size="20" value="<?php echo $row['id']; ?>" readonly></td>
<td>
<input type="text" name="s_img" class="input" size="20" value="<?php echo $row['s_img']; ?>" readonly></td>
<td>
<input type="text" name="l_img" class="input" size="20" value="<?php echo $row['l_img']; ?>" readonly></td>
<td> <input type="submit" name="submit" value="ADD IMAGE" class="button" /></td>
</form>
<?php
}
?>
Addimg.php
<form name="XIForm" id="XIForm" method="POST" action="addimg.php">
<h1>News Description</h1>
<p>
<label for="News_id" class="uname"> News_ID</label>
<input type="text" id="news_id" name="news_id" type="text" value="<?php if(isset($_GET['id'])) { echo $_GET['id']; } ?>" readonly> <br />
</p>
<label for="img1" class="uname"> Img1</label>
<input type="text" id="img1" name="img1" type="text"/> <br />
</p>
PHP code
if(isset($_POST['XIsubmit'])) {
$news_id = $_POST["news_id"];
$img1 = $_POST["img1"];
if($img1!="")
{
$query=("INSERT INTO images (news_id,img)VALUES('$news_id','$img1')") or die(mysql_error());
$retval = mysql_query( $query, $dbhandle );
echo ""
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
}
}
?>

Session variable can't be access to different page

I have a problem on getting the session variables to work on different pages
I have three php scripts
1. index.php (includes a html form)
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['billTo_email'] = $_POST['billTo_email'];
}
?>
<form id = 'form_submit' method="post" action = "NetworkOnline.php">
<td><input type="text" name="billTo_email" id="f_name2" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit"/></td>
</form>
?>
NetworkOnline.php
<?php
session_start();
$_SESSION['billTo_email'] = $_POST["billTo_email"];
?>
$f_name=$_POST["f_name"];
$l_name=$_POST["l_name"];
$billTo_country=$_POST["billTo_country"];
$billTo_city=$_POST["billTo_city"];
$billTo_state=$_POST["billTo_state"];
$billTo_street1=$_POST["billTo_street1"];
$billTo_pin=$_POST["billTo_pin"];
$billTo_email = $_SESSION["billTo_email"];
response.php
<?php
session_start();
$_SESSION["billTo_email"] = $_POST["billTo_email"];
?>
<form name = "form1" method = "post" action="mail.php" >
<input type="hidden" name="order" id="order" value="<?php echo $order ?>" >
<input type="hidden" name="bank" id="bank" value="<?php echo $bank ?>" >
<input type="hidden" name="amount" id="amount" value="<?php echo $amount ?>" >
<input type = "test" name= "email" id ="email" value= "<?php echo $billTo_email ?>">
<input type="submit" id="submit" value="submit" name="submit">
</form>
Try this,
index.php:
<html>
<form id = 'form_submit' method="post" action = "NetworkOnline.php">
<td><input type="text" name="billTo_email" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit"/></td>
</form>
</html>
NetworkOnline.php:
<?php
session_start();
$_SESSION['billTo_email'] = $_POST["billTo_email"];
header('Location: response.php');
?>
response.php:
<?php
session_start();
$billTo_email=$_SESSION["billTo_email"]
?>
<form name = "form1" method = "post" action="mail.php" >
<br />
<br />
<input type = "test" name= "email" value= "<?php echo $billTo_email ?>">
<input type="submit" id="submit" value="submit" name="submit">
</form>
Try below,
Your closing tags are wrong in place,
index.php
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['billTo_email'] = $_POST['billTo_email'];
}
?>
<form id = 'form_submit' method="post" action = "NetworkOnline.php">
<td><input type="text" name="billTo_email" id="f_name2" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit"/></td>
</form>
NetworkOnline.php
<?php
session_start();
$_SESSION['billTo_email'] = $_POST["billTo_email"];
$f_name=$_POST["f_name"];
$l_name=$_POST["l_name"];
$billTo_country=$_POST["billTo_country"];
$billTo_city=$_POST["billTo_city"];
$billTo_state=$_POST["billTo_state"];
$billTo_street1=$_POST["billTo_street1"];
$billTo_pin=$_POST["billTo_pin"];
$billTo_email = $_SESSION["billTo_email"];
?>
response.php
<?php
session_start();
$_SESSION["billTo_email"] = $_POST["billTo_email"];
?>
<form name = "form1" method = "post" action="mail.php" >
<input type="hidden" name="order" id="order" value="<?php echo $order; ?>" >
<input type="hidden" name="bank" id="bank" value="<?php echo $bank; ?>" >
<input type="hidden" name="amount" id="amount" value="<?php echo $amount; ?>" >
<input type = "test" name= "email" id ="email" value= "<?php echo $billTo_email; ?>">
<input type="submit" id="submit" value="submit" name="submit">
</form>
UPDATE:
your index.php
<form id = 'form_submit' method="post" action = "NetworkOnline.php">
<td><input type="text" name="billTo_email" id="f_name2" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit"/></td>
</form>
NOTE: NO need to check if (isset($_POST['submit'])) { ... } here, because index.php send data to NetworkOnline.php.
Your NetworkOnline.php:
<?php
ob_start(); // turn on output buffering
session_start();
if( isset( $_POST['billTo_email'] ) ) { // work only if **billTo_email** has some value
$_SESSION['billTo_email'] = $_POST["billTo_email"];
}
// ?> <-- remove this closing tag
$f_name=$_POST["f_name"]; // this line of code shows undefined variable,
//because in your index.php there is no any f_name field presnet.
// your remaining codes
?>

Multiple forms on same page - If empty

I'm currently in the process of coding a MySQL search page and I'm unable to work out how to make it so that if there's no data put in one form it'll do nothing, and if there's data in the other form it'll search the database for that value.
<?PHP
echo '<h3 class="hp-1">Kick Logs</h3><div class="wrapper">
<div class="logcol-1"><form name="form1" id="mainForm" method="post"enctype="multipart/form-data" action="' . $_SERVER['REQUEST_URI'] . '">
<input name="name" type="text" id="name" placeholder="Players Name">
</form>';
echo '<form name="form2" id="mainForm" method="post"enctype="multipart/form-data" action="' . $_SERVER['REQUEST_URI'] . '"><input name="reason" type="text" id="reason" placeholder="Kick Reason"></form>';
$name = mysql_real_escape_string($name);
$reason = mysql_real_escape_string($reason);
$kicklogname = mysql_query("SELECT * FROM `log1` WHERE `user` LIKE '%$name%'") or die(mysql_error());
$kicklogreason = mysql_query("SELECT * FROM `log1` WHERE `user` LIKE '%$reason%'") or die(mysql_error());
if($name == ""){
echo "You must enter a name to search"; }
else {
echo '<table width="700" border="0">
<tr class="listheader">
<td width="100" bgcolor="#afe6ff">Username</td>
<td width="220" bgcolor="#afe6ff">Reason</td>
</tr>';
while($row = mysql_fetch_array($kicklogname))
{
echo '<tr><td bgcolor="#daf4ff" class="contentleft">';
echo $row['user'];
echo '</td><td bgcolor="#eefaff" class="contentright">';
echo $row['reason'];
echo '</td></tr>';
}
echo '</table></div></div>';
}
?>
Update
Sorry, re-read the question. To check multiple forms on the same page you need to add a submit button to each form and give it a name:
<?php
if (!empty($_POST) && isset($_POST['reasonsubmit'])) {
echo 'Submitted reason form';
}
if (!empty($_POST) && isset($_POST['namesubmit'])) {
echo 'Submitted name form';
}
?>
<form action="reason.php" method="post">
<input type="text" name="reason" id="reason" />
<input type="submit" name="reasonsubmit" />
</form>
<form action="name.php" method="post">
<input type="text" name="name" id="name" />
<input type="submit" name="namesubmit" />
</form>
Alternatively, if you didn't want to give the submit button a name you can just add a hidden field to each form and you will get the same behavior.
<form action="reason.php" method="post">
<input type="hidden" name="reasonsubmit" id="reasonsubmit" />
<input type="text" name="reason" id="reason" />
<input type="submit" />
</form>
<form action="name.php" method="post">
<input type="hidden" name="namesubmit" id="namesubmit" />
<input type="text" name="name" id="name" />
<input type="submit" />
</form>

Categories