I really need help.
I am trying to have a setup wherein an admin could enable a client's button that is disabled by default.
So far, I have this code below for the admin. It updates the value column (0 by default) in the button table in the database. And this part is successful.
<input name="enable1" type="submit" id="button" value="Enable Button" />
<?php
if(isset($_POST['enable1'])){
mysql_query("UPDATE button SET value = '1' WHERE cat_no = 'cat1'"); }
?>
And the code for the user is written below. My plan is that, when the admin updates the column value into 1, the code below will echo the enabled button, as by the default, the button is disabled.
And this part is a failure, it does not enable the disabled button. And I noticed, that the first echo in the if statement doesn't work, the only thing that is working is the echo in the else statement where the button is disabled.
<?php
$sql="SELECT value FROM button WHERE cat_no = 'cat1'";
$result=mysql_query($sql) or die(mysql_error());
if ($result == '1'){
echo '<input name="enable2" type="submit" class="inputDisabled"
id="button" value="Proceed to Next Category" />' ;}
else {
echo '<input name="enable2" type="submit" class="inputDisabled"
id="button" disabled="disabled" value="Proceed to Next Category" />';}
?>
I also tried to search for alternatives like jQuery. But I can't make it work. And if possible, when the admin clicks the button, the user's page will refresh automatically.
Please help. I really need guidance. Thank you.
Well, Try this :
<?php
$sql="SELECT value FROM button WHERE cat_no = 'cat1'";
$result=mysql_query($sql) or die(mysql_error());
$result= mysql_result($result,0,"value"); // I added this line
if ($result == '1'){
echo '<input name="enable2" type="submit" class="inputDisable"
id="button" value="Proceed to Next Category" />' ;}
else {
echo '<input name="enable2" type="submit" class="inputDisabled"
id="button" disabled="disabled" value="Proceed to Next Category" />';}
?>
Is there only one client ? If not how will you check which client's button is enabled and which is not ?
Try this
$sql="select count(*) as total from button where cat_no = 'cat1'";
$runsql=mysql_query($sql) or die(mysql_die());
$data=mysql_fetch_object($runsql);
if($data->total==1){
echo '<input name="enable2" type="submit" class="inputDisabled" id="button" value="Proceed to Next Category" />';
}
else {
echo '<input name="enable2" type="submit" class="inputDisabled"
id="button" disabled="disabled" value="Proceed to Next Category" />';}
Hope it will help you.
Related
I have this piece of code in my PHP file to project the contents of a txt file as a drop down menu.
echo '<p style="text-align:center;"><form action="schedule.php" method="POST" name="theForm2" id="theForm2"></p>
<p style="text-align:center;"><select name="fh[]"></p>';
foreach($lines as $line) {
echo '<option value="'. urlencode($line).'">'.$line.'</option>';
}
echo '</select>
<input type="submit" name="scheduleButton" value="Schedule" />
<input type="submit" name="deleteButton" value="Delete" />
</form>';
And then i use this to get the selected value.
if (isset($_POST['deleteButton'])) {
$v = ($_POST['deleteButton']);
}
But the problem is that every time i get v = "Delete".
Any help would be much appreciated.
That's because the value of the deleteButton control is "Delete". The code is doing exactly what you asked it to.
If you want the value of the select control, you need $_POST["fh"] and to change your select to <select name="fh">.
$result = mysql_query('SELECT * FROM teams');
while($row = mysql_fetch_array($result))
{
$team= $row['team'];
$goals= $row['goals'];
$squadsize= $row['squadsize'];
$league= getTheirLeague($team);
echo $team. "</br>";
echo "Goals Scored " . $goals. "</br>";
echo "League " . $league. "</br>" . "</br>";
<form method="POST" action="football.php">
<button type="button">Edit</button>
<button type="button">Remove</button>
</form>
}
I am trying to add a remove and edit feature to my teams, for every team i print out i have a form being printed with 2 buttons. What i am unsure of is how i can tie the button clicks up to the definitive team that the button belongs too.
As each row (team) gets its own form, simply add a hidden field with the team identifier (assuming $row['team'] for this example).
Please note that IE has terrible <button> support in forms. I'd advise using submit inputs...
<form method="POST" action="football.php">
<input type="hidden" name="team"
value="<?php echo htmlspecialchars($row['team']) ?>">
<input type="submit" name="edit" value="Edit">
<input type="submit" name="remove" value="Remove">
</form>
You can then tell which team form was submitted by checking $_POST['team'] and which button was pressed using...
if (isset($_POST['edit']) {
// edit clicked
}
if (isset($_POST['remove']) {
// remove clicked
}
I have this PHP code:
$result = mysql_query("SELECT distinct om_quote_no from `porders` order by om_quote_no desc") or die(mysql_error());
echo '<select name="project_no">';
while ($row = mysql_fetch_array($result)) {
echo "<option value=".$row['om_quote_no'].">".$row['om_quote_no']."</option>";
}
echo '</select>';
?>
<input type="submit" value="Submit" />
</form>
<div id="table">
<?php
if($_GET){
So as you can see the PHP is forming a dropdown input and once submitted its going to execute some code, but what i need to do is have two dropdown inputs and therefore two submit buttons, however i'm not sure how to form the PHP if statement to distinguish which submit was pressed, so i'll have(pseudo):
if (submit1){
}
if (submit2){
}
Is that possible?
If you give your <input type="submit"> elements names, the one that is clicked will have its name and value sent to the server.
<input type="submit" value="Submit" name="submit1">
if clicked will send submit1=Submit to the server. You could therefore check with if ($_GET['submit1']) to see if it was pressed.
This isn't the best way but can do something like this too:
<select name="test" onchange="document.location ='test.php?submit=dropdown1'">
<option>test</option>
<option>test1</option>
</select>
<br><br>
<select name="test1" onchange="document.location ='test.php?submit=dropdown2'">
<option>test2</option>
<option>test3</option>
</select>
within test.php file:
if($_GET['submit'] == 'dropdown1')
{
print "One";
//statements to execute
}elseif($_GET['submit'] == 'dropdown2'){
//statements here to execute
print "Two";
}
<input type="submit" value="Submit 1" name="submit1"/>
<input type="submit" value="Submit 2" name="submit2"/>
<?php
if(isset($_POST['submit1'])){
//do stuff
//grab select option
$select_option=$_POST['project_no'];
}else if(isset($_POST['submit2'])){
//do stuff
}else{
//do stuff
}
?>
Or if your method is GET than change $_POST to $_GET :)
I have a PHP generated form which consists of a list of items, each with a button next to them saying "Remove This" it outputs similar to below:
Item A - [Remove This]
Item B - [Remove This]
...
I wish to be able to click Remove This and it will detect which item it is, and then remove that from the database. Here's my code so far:
selectPlaces.php
<?php
include 'data.php';
mysql_connect($host, $user, $pass) or die ("Wrong Information");
mysql_select_db($db) or die("Wrong Database");
$result = mysql_query("SELECT * FROM reseller_addresses") or die ("Broken Query");
while($row = mysql_fetch_array($result)){
$placeName = stripslashes($row['b_name']);
$placeCode = stripslashes($row['b_code']);
$placeTown = stripslashes($row['b_town']);
$outputPlaces .= "<strong>$letter:</strong> $placeName, $placeTown, $placeCode <input type=\"button\" onclick=\"removePlace()\" value=\"Remove This\" /><br />";
}
mysql_close();
?>
Coupled with my admin.php
<div id="content" style="display:none">
Remove a Place<br><br>
<?php include 'selectPlaces.php'; echo $outputPlaces; ?>
</div>
I know I need to add some javascript to detect which button is clicked but I can't seem to get it working. I tried modifying the onclick="removePlace()" by perhaps passing a variable in the function removePlace(placeID) or something like that, but I'm new to JavaScript and I have no idea how to receive this in the removePlace function.
This seems easier to do without JavaScript. For each entry instead of generating just a button, generate a form that posts to a PHP script that does the deleting.
<form action="deletePlace.php?id=<?php echo $idOfThePlace?>">
<input type="submit" value="Remove This" />
</form>
$idOfThePlace would be the ID with you use to identify the data row.
You don't need JavaScript for that. Try running this example:
<?php var_dump($_POST); ?>
<form action="post.php" method="post">
<p>
<input type="submit" value="a" name="action" />
<input type="submit" value="b" name="action" />
</p>
</form>
You'll see that $_POST['action'] will depend on which button was pressed. For your example, you just need to set the value to identify the item that needs to be deleted. It might be useful to use the <button> element for that: <button name="delete" type="submit" value="12345">delete item 12345</button>. It'll show up as $_POST['delete'] with 12345 as value when submitted.
I would like to know how can I add a button to enable user to register the available domain name? My idea is to a button linked to registration page next to the available domain name. When the user click the button, the name of the searched domain will be passed to the next page, which is the registration page.
I've added the following code, but it's not working.
function showDomainResult($domain,$server,$findText){
if ($this->tr == 0){
$this->tr = 1;
$class = " class='tr2'";
} else {
$this->tr = 0;
$class = "";
}
if ($this->checkDomain($domain,$server,$findText)){
echo "<tr $class><td>$domain</td><td>$this->daftar_tld($domain)</td></tr>";
}
else echo "<tr $class><td>$domain</td><td class='tak'>TAKEN</td></tr>";
}
// To display register button
function daftar_tld($domain){
?>
<form method=post action="http://www.com">
<center><input value=$_POST["$domain"]><input type="submit" name="butangDaftar" class="sbtn" value="Register" /></center>
</form>
<?php
}
?>
And the output that I get is this (image is provided at the link below):
http://lh5.ggpht.com/_d7N0eqyUoUw/TGgPvCt4B3I/AAAAAAAAAHY/T7e4KjVNT04/Screen%20shot%202010-08-14%20at%2012.53.59%20PM.png
I really hope that someone can help me. I've been working on this for days. Phewwww...
You haven't set a name or type for the input variable holding the domain:
Your code:
<center><input value=$_POST["$domain"]><input type="submit" name="butangDaftar" class="sbtn" value="Register" /></center>
Suggested code:
<center><input type="hidden" name="domainToRegister" value="<?php echo $_POST["$domain"]; ?>" /><input type="submit" name="butangDaftar" class="sbtn" value="Register" /></center>
The form will then submit the domain as $_POST['domainToRegister'].