I have a site in which an Admin User looks at rows of invoices which have been submitted by users, when they click on an 'Approve Invoice' button from one of these rows it will take them on the page below.
Once the Admin User approves this invoice, they hit the 'yes' radio button and submit at the bottom of the page which enters the value 'AUDITED' under the 'npc_active' column in that row. It then multiplies the quantity and points and inserts the total onto a new row in 'tally_points' (along with their user id and sales id). This is all working fine, but...
What I am trying to do, however, is make a condition in which once the sale is audited, that it can't be re-audited. ie the 'This invoice has been audited' print should show once the submission has taken place, but it isn't working.
I'm close but can't seem to figure out what the problem is. The code in which I think I am having the problem is below, the full page code is at the bottom of this post.
$str ='<form method="post" action="audit_invoice.php">
<font style="font-size:11px;">
<em>Is this invoice approved?<br />';
if($approved == "AUDITED") {
$str .='Please select carefully as this action cannot be undone.</em>
<em>Yes:</em><input type="radio" value="AUDITED" name="npc_active"> <em>No:</em>
<input type="radio" value=" " name="npc_active">
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="submitted" value="TRUE" />
<input type="hidden" name="id" value="' . $id . '" />
</font>
</form></tr>';
}
else {
$str .='This invoice has been audited';
}
echo $str;
If I put the '==' before "AUDITED" it will show up with the echo 'The invoice has been audited' in each instance, if I put '=' in front of "AUDITED" it will show the yes button and submit button in each instance.
#AdamMC the = operator is only used when assigning data.
You are comparing a data, therefore you are correct when using ==
if($approved == "AUDITED")
I would like to request what exactly your $approve variable contains.
As of right now I can only make an assumption that this code implies
if invoice is approved it would equal audited which then would trigger it to echo "this invoice has been audited"
To stackoverflow users: please do not downvote, I cannot comment because my reputation does not permit it. Just trying to help
Related
I've been trying to build a program using PHP cookies. The user interface basically looks like this.
My basic program
The logic is this. When the user enters the product name, price and quantity and clicks on the "Add" button, the total value which is price*quantity will fall on the "Total bill value" textbox. The user can go on adding more and more values for "Price" and "Quantity" and each time he clicks on "Add", all the values get added. So this should be done by using cookies. The "Clear" button will reset the cookie, and the "Print" button will also be using the same cookie to print out everything the user has entered upto that point.
Anyways I just started coding, and I'm already stuck. I'm not sure what my mistake is. When I click on the "Add" button, the value doesn't get added every time I enter a price and quantity. Instead the page refreshes to give only the product of the price and quantity entered at one time. This is my code.
`
<form method="POST" >
<ul style="list-style-type:none;">
<li>
Product Name: <input type="text" name="ProductName"> <br>
Price: <input type="number" name="Price" value="price"> <br>
Quantity: <input type="number" name="Quantity" value="qty"><br>
<input type="submit" name="btnClick" value="Add">
<input type="submit" name="btnReset" value="Clear">
<input type="submit" name="btnPrint" value="Print"><br>
Total Bill Value: <input type="text" name="Bill">
</li>
</ul>
</form>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$result=0;
if(isset($_POST["btnReset"]))
{
setCookie("result", $result);
}
elseif(isset($_POST["btnClick"]))
{
if(isset($_COOKIE["result"]))
{
$result=$_COOKIE["result"];
}
$result= $_POST["Price"]*$_POST["Quantity"];
echo $result;
setCookie("result", $result);
}
else
{
echo "Product: ".$_POST["ProductName"];
echo "Price: ".$_POST["Price"];
echo "Quantity: ".$_POST["Quantity"];
}
}
?>
</body>
`
I'm sure that this is a stupid mistake I'm struggling on. However I am an absolute beginner and would so appreciate if somebody could point out my mistake and explain it to me.
So there are two things I want to know mainly:
Why is my cookie not being set when the Add button is clicked?
How to put the value calculated in PHP back to the html form, so that the "Total Bill Value" textbox will have the total value?
Thanks in advance!
Edit: I did figure out my mistake. I should have put $result=$result + $_POST["Price"]*$_POST["Quantity"];
Then the values get added up.
However would like to know how to put the total bill value calculated in PHP back to the HTML form
You should call setcookie() before you output any HTML, so move the PHP code above the rest.
To set the form input:
<?php
if (isset($result)) {
$bill = $result;
} else {
$bill = '';
}
?>
Total Bill Value: <input type="text" name="Bill" value="<?php echo $bill; ?>">
please use setcookie instead of setCookie
This will work
Happy Coding
I've seen many forums, but couldn't figure this out. Please help and guide.
When I click the submit button, I am taken to a href file location ... no problem with this. Simultaneously I want to add details of the event to a table named 'docdownloads'. My code looks like this. Currently my table is getting updated without clicking the submit button. I want both the events to occur together and be triggered by the single click.
<?php
echo "<input type='submit' value='Click Here To Download' ". $downloaddisabled." onclick='window.location.href=\"$docpath\"'>";
echo '<br>';
if ($downloaddisabled!="disabled" ) {
$sql4="INSERT INTO docdownloads (accno, username, userid, downloadtime, filename) VALUES('$accno', '$uname', '$uid', '$downloadtime', '$docpath')";
if (!mysqli_query($con1, $sql4)) {
die('Error: ' . mysqli_error($con1));
}
echo "one record added";
}
?>
The Way I do things.
Create a seprate page for recording things in MySQL and when your things are done redirect it to downloadable item.
Original Page:
<?
echo "<input type='submit' value='Click Here To Download' ".
$downloaddisabled."
onclick='window.location.href=\"$docpath_special_Page\"'>";
echo '<br>';
?>
docpath_special_Page:
<?php
$sql4="INSERT INTO docdownloads (accno, username, userid, downloadtime,
filename) VALUES('$accno', '$uname', '$uid', '$downloadtime',
'$docpath')";
if (!mysqli_query($con1, $sql4)) {
die('Error: ' . mysqli_error($con1));
}
header("Location:/".$docpath);
exit(0);
?>
One solution is to have three pages
Page one: contains the submit button (with link to page 2). Also, make the $downloaddisabled a session variable so that it can be accessed on other pages
Page two: Checkes the session variable for being equal to disabled, if yes.. executes SQL.
This page also redirects to the third page automatically
Page three: Your final destination
I had similar issue am not sure how exactly is to mine but I had to submit form details to PayPal , save the same detail to database and send email of the details...
This is what you have to do:
Create form that will send details to database and you can put values hidden if you wish for normal user to see the details.
<form name="insert_to_table_docdownloads" method="post" id="msend" action="insert.php" target="_main">
<input type="hidden" name="accno" value="">
<input type="hidden" name="username" value="">
</form>
were insert.php contain sql insert command
Create another form which will view details you want to see
<form name="download" id="download" >
<input type="text" value="">
</form>
Then create JavaScript button to submit both form by id
<input type="image" src="button_img.png" onclick="document.getElementById ('msend').submit();document.getElementById('download').submit();" />
Tell me if it works for you.
I am trying to create a registration website where the users chooses amongst three options on the first page and after selecting, can move onto the second page where it is displays different information depending on the option selected previously.
On Registration_1.php this is the code:
<?php
$clicked = $_POST["Next"];
if(isset($_POST['Reg_type']))
{
header('Location:Registration_2.php');
}
elseif(isset($_POST['Next']))
{
header('Location:Registration_1.php');
echo "Error! You must select an option!";
// display form again here
}
?>
<form name="frmtype" action="Registration_2.php" method="post" >
<input type="radio" name="Reg_type" value="1"/> Registering myself with credit card or bank account <br/>
<input type="radio" name="Reg_type" value="2"/> Registering multiple people using credit card or bank account <br/>
<input type="radio" name="Reg_type" value="3"/> Registering multiple people using a purchase order <br/>
<input type="submit" name="Next" value="Submit"/>
</form>
How can I redirect the user back to this page if they simply click submit without choosing an option and possible display a error message, and send them to page 2 if they choose an option? Thank you
Edit: Added if block, but still moved to next page regardless of selecting an option or not. Is the header() not the correct method to move to another page?
if(isset($_POST['Reg_type']))
{
// execute some code
// go to page 2
}
else
{
echo "Error! You must select an option!";
// display form again here
}
Documentation: $_POST variable
When my user searches for game in my DB, I present them with a list of the games that match their search term, and then i want to add a button to each item that allows the user to select "have it" or "want it" then have a single "add" button that adds their selections to their profile.
because you cant have it and want it at the same time, i assumed a radio button would be the best choice.
but now i am lost as to how to handle the buttons. When i click on one selection from the search, it will deselect when i choose have or want on another game.
I understand that i should be creating a separately name form for each search result, but then how would i manage the data when sending it to my controller? Maybe i need incrementing form names and then count how many results and use that in my controller?
Also, i need the gameID associated with the selections so i need to send a hidden value with that data for each selection
maybe i am going about this the wrong way...
heres my code
echo '<div id="UserSearchGameResults">';
echo '<form action="#" method="Post">';
$x = 0;
while($gamesLike != null)
{
$x++;
echo '<div id="game_search_list_item">'.$x.'. '.$gamesLike['title'].'</div>
<span class="gamelistblue">
<input type="radio" name="haveOrWant" value="have" />Have it
</span>
<span class="gamelistorange">
<input type="radio" name="haveOrWant" value="want" />Want it
</span>
<input type="hidden" name="gameID" value="'.$gamesLike['ID'].'" />';
$gamesLike = $statement->fetch();
}
$statement->closeCursor();
echo '<br /> <input type="submit" value="Add Game(s)" />';
echo '</div></form>';
any help is appreciated with the subject
new ideas on how to handle my needs are welcome too.
Dan
Use arrays for the input names. Something like
<input type="radio" name="game' . $gamesLike['ID'] . '[haveOrWant]" value="have" />Have it
Okay... I'm having the following problem - in my facebook application I let people add quotes sending them to my DB with their user_id, post_id and date. Then there's a browse page where people see the posts - so far, so good. But then I add a button that lets my users set the said post as their status. Still all good. However when I hit the button what it does is setting all the posts in the DB as my status, one by one until they all print out as my statuses. I'm sure that it is because of the 'while' function I use and because I am not sure how to print out all posts and being able to add to each the said button, holding only the specific post_id from the db ._.'
So in other words, it is a PHP/MySQL problem mainly, so even if you are not familiar with FBML, you can still help me out with the code...
Think of it as a list of posts and each should have a button doing something and being somehow attached to only the specific post.
The code is the following:
.... some code here ....
$query = 'SELECT * FROM tb_table ORDER BY `time` DESC';
$results = mysql_query($query);
---some other code---
while($line = mysql_fetch_assoc($results)) {
echo '<TABLE BORDER=0><TR VALIGN=TOP><TD>';
echo "<fb:profile-pic uid=".$line['userid']." size='square' facebook-logo='true'></fb:profile-pic></TD>";
echo "<TD>".$line['postid']."<br>"."<br>"."Posted by: ".$data['first_name'].$data['last_name']."<br>".date("F j, Y, g:i a", $line['fb_time'])."</TD>";
//Problems start from here
echo $facebook->api_client->users_setStatus($line['postid']) ;
echo '<div id="statusdiv" style="display:<?=$visibility;?>;">
<form method="POST">
<input type="submit" value="change status" />
</form>
</div> ';
echo "</TR></TABLE><br>";
The thing you're doing now is every time you loop through your mysql resultset you call the users_setStatus function which then sets your status (for every iteration).
You want to add a hidden input field to the form which contains the $line['postid'] and then call users_setStatus after a POST of the form. In that way you only change your status once.
Update
Remove the call to users_setStatus from the while loop.
Change your form like this:
echo '<div id="statusdiv" style="display:<?=$visibility;?>;">
<form method="POST">
<input type="submit" value="change status" />
<input type="hidden" name="line" value="'.$line['postid]'.'" />
</form>
</div> ';
Then, catch the POST variable upon submitting. With something like:
if (isset($_POST['line'])) {
echo $facebook->api_client->users_setStatus($_POST['line']) ;
}
See http://www.w3schools.com/php/php_forms.asp for more info.