I have a form with two radio buttons as "yes" and "No"
I m bringing the "name" of the input from PHP variable I get from the DB.
But however, it echoes in the form but when submitting gives the error.
My HTML code goes as:
<form action="phpfile.php" method="post">
<?php
$sql6 = "SELECT * FROM subadminpriv WHERE subadmin_id = '$sa_id'";
$result6 = $conn->query($sql6);
if ($result6->num_rows > 0) {
while($row6 = $result6->fetch_assoc()) {
$sa_id = $row6["subadmin_id"];
$privilege = $row6["privilege"];
$status = $row6["status"];
?>
<div class="togglebutton m-t-30" >
<label >
<strong>⇒ <?php echo $privilege; ?> </strong> <br>
<input name="<?php echo $privilege; ?>" value="1" type="radio">Yes
<input name="<?php echo $privilege; ?>" value="0" type="radio">No
</label>
</div>
<hr>
<?php } }else { } ?>
<button class="btn button" type="submit">Assign Privileges</button>
</form>
Where the $privilege is "Can See Vendors"
So in here, I'm trying to get the fields "sa_id, privilege, status" from the DB and echo as many radio(yes/no) as the fields in DB.
It works, however, and I echoed the "name" field in the input with PHP variable when I inspect it, it gives the value form the DB, but when I submit and echo it, it gives an error.
The PHP phpfile.php page goes as :
<?php include ('../db.php'); ?>
<?php
$priv1 = $_POST['privilege1'];
echo $priv1;
?>
Here "privilege1" is the actual privilege name from the DB field.
while it gives error as "Notice: Undefined index: privilege1 in D:\xampp\htdocs\blah blah blah/pIpfile.php on line 6"
While I Was expecting value I given to radio button like 1 or 0;
Hope i m Clear with my problem. Any Help is Appreciated...
Don't know how I missed it.
The name in the input field won't accept space, so I changed it to "Can_See_Vendors"
Solved
Related
I created a form where as soon as I click on the input of the submit, it writes me a value on the column to the database table.
So far everything is fine, but when the current page reloads, I can't see the result that was written to the database.
I can only see the result if I submit the form for the second time on the same page.
My code:
<?php
$increId = $_order->getRealOrderId();
$pathAss = 'My file';
$connectionresource = Mage::getSingleton('core/resource');
$connectionWrite = $connectionresource->getConnection('core_write');
$table = 'sales_flat_order';
$query = "UPDATE ".$table." "
. "SET upload_file_1='" . $pathAss . "'"
. " WHERE increment_id='".$increId."'";
$connectionWrite->query($query);
?>
<form id="abbLogoOrder" action="" method="post" enctype="multipart/form-data">
<a href="<?php echo $_order->getupload_file_1(); ?>"
title="<?php echo basename($_order->getupload_file_1()); ?>">
<?php echo basename($_order->getupload_file_1()); ?>
</a> //THIS VALUE RETURNS EMPTY AFTER FIRST SUBMIT FORM
<b>
<?php
/* $testget = ['getupload_file_'.$count.'()'];
echo $_order->$testget; */
?>
</b>
<div class="upload-btn-wrapper">
<button class="btn" style="font-size:13px;">SELECT YOUR FILES</button>
<input type="file" name="abbFile<?php echo $count; ?>[]" id="abbFile<?php echo $count; ?>" multiple="multiple" />
<input type="submit" value="SEND" />
</div>
</form>
What am I doing wrong?
You are not re-fetching the order details after the save function. So the details are getting from the initial state, so the result is old, but the next reload it changes to updated value and shows the right output.
But still it's unclear where you are loading the order object.
guys. I was going ok with my app until I got to this type of form, written below. I have 2 items in this table and the ID's are "1" and "2". Even though, if I press "Submit" on the "1" ID item, it prints me "2" every time. Does anyone have a clue what might be the problem? Thank you.
<form method="POST">
<?php
$query = "SELECT * FROM table";
while($row = $query->fetch_array())
{
$id = $row['id'];
?>
<input type="hidden" name="id" value="<?php echo $id; ?>" >
<input type="submit" name="submit">
<?php } ?>
</form>
<?php
if(isset($_POST['submit']))
{
echo $_POST['id'];
}
?>
You're outputting two items into the same form with the same name. When you click the Submit button, it gathers all of the fields in the form based on the name attribute and sends them on to wherever the form is being posted.
If you want to have a button that submits each ID with a separate button, you'd want to try having a new form for each ID. There are other ways of doing this too, but based on your current code, try something like this:
<?php
$query = "SELECT * FROM table";
while($row = $query->fetch_array())
{
$id = $row['id'];
?>
<form method="POST">
<input type="hidden" name="id" value="<?php echo $id; ?>" >
<input type="submit" name="submit">
</form>
<?php } ?>
<?php
if(isset($_POST['submit']))
{
echo $_POST['id'];
}
?>
I am currently doing up a list of names that has signed up for a activity which is then needed to go through another selection process and to be put into the database. I have currently done the getting and displaying of names from the people that has signed up.
However, I am not too sure on the process of how I can get those checked which is being selected in the selection process.
This is currently the codes that I have done to get and display the names of the people who have signed up. Upon clicking submit, it would go to another page which would then process, get those checked and marked as 1 or true to the database (MySQL) or either set as 0 or false if it has not been checked.
<?php
if ($totalShortlist > 0) {
?>
<?php
while ($row = mysqli_fetch_assoc($result)) {
$firstName = $row['first_name'];
$lastName = $row['last_name'];
?>
<form id="selectionProcess" action = "doShortlistProcess.php?id=<?php echo $id ?>" method = "post">
<fieldset data-role="controlgroup">
<label><input type="checkbox" name="selectionProcess" id="selectionProcess" value="<?php echo $id ?>"/><?php echo $firstName; ?> <?php echo $lastName; ?></label>
</fieldset>
<?php
}
?>
<input type="submit" class="btnSelect" data-theme="b" data-inline="true" name="shortlistCandidate" value="Submit Shortlisted Candidates"/>
</form>
<?php
}
// end for loop
else {
echo "No candidates to be shortlisted";
}
mysqli_close($link);
?>
The $id as shown is the brought over from the list of categories on the previous page, which allows to get all the names in that categories to be displayed.
Your code places the form in the wrong place compared to the while loop. The action also doesn't need you to compose a query string. Better code (careful, I've also cut out some presentation):
if ($totalShortlist > 0) {
?>
<form id="selectionProcess" action = "doShortlistProcess.php" method = "post">
<fieldset>
<?php
// use while loop to display a tick box for each item
while ($row = mysqli_fetch_assoc($result)) {
$firstName = $row['first_name'];
$lastName = $row['last_name'];
?>
<label>
<input type="checkbox" name="selectionProcess" id="selectionProcess" value="<?php echo $id ?>"/>
<?php echo $firstName; ?> <?php echo $lastName; ?>
</label>
<?php
} // end of while loop
?>
</fieldset>
<input type="submit"/>
</form>
<?php
} // end of shortlist > 0
I recommend you test this code using the GET method. It will show you what form the submission takes.
To process the result, you should use the list of responses, process it and turn it into one or more SQL statements.
An alternative would be to use an action for each checkbox, but then use ajax to a php page that would modify the status of single subscriber. The change would be made immediately as users click.
here is my code:
<?php
ob_start();
session_start();
require 'connection.php';
require 'core.inc.php';
?>
<?php
$take_thread_pid_query = #mysql_query(" select pid from threads ");
$row_take_thread_pid = mysql_fetch_array($take_thread_pid_query);
$pid = $row_take_thread_pid['pid'];
while($row_take_thread_pid = #mysql_fetch_array($take_thread_pid_query))
{
?>
<form action="kill_threads.php" method="POST" >
<label> <?php echo "<br/><br/>thread".$row_take_thread_pid['pid']; ?><input type="submit" value = " <?php echo $row_take_thread_pid['pid'];?> " name = " <?php echo
$row_take_thread_pid['pid']; ?> " /> </label>
<?php }?>
</form>
<?php
$t = "4756";//[4756 is on of the pids in my thread table].this is for testing but doesnt works,it cant find any button with this name.
if ( isset($_POST[$t] ) ) echo "im a killed thread..";
?>
The big problem is that im trying to give different names to each button i create,but it seems this is not working because when im trying to see if a button isset['???']
What i have to do...?
For example
thread 1 [button 1]
thread 2 [button 2]
thread 3 [button 3 ]
So if now i click button 1 i want thread1 row deleted from database.
phpmyadmin works like this.
Im so complicated..please help,thanks in advance.
Your code is:
value = " <?php echo $row_take_thread_pid['pid'];?> "
name = " <?php echo $row_take_thread_pid['pid']; ?> "
You are placing spaces before and after the php text so you either have to remove the spaces or code for them
I would suggest you to use another hidden input element within the form instead of doing it with submit form, in this way you can kill all the threads with one if block by passing thread id to it.
while($row_take_thread_pid = #mysql_fetch_array($take_thread_pid_query))
{
?>
<form action="kill_threads.php" method="POST" >
<label> <?php echo "<br/><br/>thread".$row_take_thread_pid['pid']; ?>
<input type="hidden" name="pid" value="<?php echo $row_take_thread_pid['pid'];?>" />
<input type="submit" value = "Delete" name = "delete_thread" /> </label> <?php }?>
</form>
<?php
$t = "4756";//[4756 is on of the pids in my thread table].this is for testing but doesnt works,it cant find any button with this name.
if ( isset($_POST[$t] ) ) echo "im a killed thread..";
?>
Another problem you may come across is using multiple forms without name and id. So add a dynamic number in the form tag like like this
<form name="<?php echo $i; ?>" id="<?php echo $i; ?>" action="kill_threads.php" method="POST" >
Here $i is counter variable or you can use $row_take_thread_pid['pid'] for this purpose.
I'm going to make edit menu in my web. so I direct the page from product into edit page. What I'm confused is how to get the productID from product's page to use in edit page?
Here is my code in product
<?php $query= "SELECT * FROM game";
$rs = mysql_query($query);
while($data = mysql_fetch_array($rs)) { ?>
<div class="gameBox">
<div style="margin:5px;">
<?php echo "<image src=\"images/".$data['gameId'].".png\" alt=\"gameImage\" </image>"?>
<div class="cleaner"></div>
<div class="myLabel">Name</div><div>: <?php echo $data['gameName'];?></div>
<div class="myLabel">Developer</div><div>: <?php echo $data['gameDeveloper']; ?></div>
<div class="myLabel">Price</div><div>: $ <?php echo $data['gamePrice']; ?></div>
<br />
<a href="edit.php" <?php $id=$data['gameId'];?>><input type="button" value="Edit"/></a>
<input type="button" value="Delete"/>
</div>
</div>
<?php } ?>
and it's my code in edit page
<?php include("connect.php");
$id[0] = $_REQUEST['id'];
$query = "SELECT * FROM game WHERE gameId=".$id."";
$rs = mysql_query($query);
while($data = mysql_fetch_array($rs)) { ?>
<form action="doUpdate.php" method="post">
<?php echo "<image src=\"images/".$id.".png\" alt=\"gameImage\" </image>"?>
<div class="cleaner"></div>
<div class="myLabel">Name</div><div>: <input type="text" value="<?php echo $data['gameName'];?>" id="gameName" name="gameName"/></div>
<div class="myLabel">Developer</div><div>: <input type="text" value="<?php echo $data['gameDeveloper'];?>" id="gameDeveloper" name="gameDeveloper"/></div>
<div class="myLabel">Price</div><div>: <input type="text" value="<?php echo $data['gamePrice'];?>" id="gamePrice" name="gamePrice"/></div>
<br/>
<div id="txtError">
<!--error message here-->
</div>
<input type="submit" value="Submit"/>
<input type="button" value="Cancel"/></span>
<?php } ?>
When I try to access edit page, there's an error it said
"Undefined index:$id[0] = $_REQUEST['id'];"
in edit page.
Could anyone help me?
It looks like you're confusing two methods of passing data between pages, forms and query strings in <a href...>s.
Forms:
Data is in <input>-type elements (or friends) and inside a <form...> tag.
For example
<form action="handler.php">
<input type="text" name="var1" />
<input type="text" name="var2" />
<input type="submit">
</form>
Usually passed via POST and accessed in PHP via $_POST.
For example, the values in the text boxes referenced above would be accessed with something like:
<?php
echo $_POST['var1']; // First text box
echo $_POST['var2']; // Second text box
Links:
Passed as query strings in <a href...>, for example:
Click Me
Usually passed via GET and accessed in PHP via $_GET.
For example, the values in the query string provided above would be accessed with something like
<?php
echo $_GET['var1']; // "foo"
echo $_GET['var2']; // "bar"
So in this case it looks like you're hyperlinking an input button -- which is not the usual way to do things, but you would fix it by changing this:
<a href="edit.php" <?php $id=$data['gameId'];?>><input type="button" value="Edit"/></a>
To, this
<input type="button" value="Edit"/>
And then reference the variable in edit.php as $_GET['id'].
But since you know it's going to be an integer and nothing else, something like:
$id = (int)$_GET['id'];
Is good enough sanitation (at least for that variable).
Lastly, I notice you assign a variable to $id[0] but then reference $id. Assigning a variable to $id[0] is not the same as assigning it to $id, as $id is an array in the former and an integer in the latter. It seems to me that you can just drop the [0] w.r.t. $id in your edit.php
You can pass through the query string
<a href="edit.php?<?php $id=$data['gameId'];?>>
In this case your PHP code will get change to
$id[0] = $_SERVER['QUERY_STRING'];
Add the id as a parameter to your edit url:
<input type="button" value="Edit"/>
also at the top of your edit.php:
$id = $_REQUEST['id'];