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'].
Related
I have created a database in phpMyAdmin with table for topics such as Math, Physics etc. Each topic has a topic_id as primary key in table tb_topic. Each topic can have multiple videos. Admin can add videos to each topic which requires topic_id as foreign key in table tb_video_management to store videos against a topic.
Backend:
There is a button to add videos in form.php
form.php:
<?php
$query = "SELECT topic_id, topic_name,aid FROM tb_topic";
$result = $con->query($query);
while($query_row = mysqli_fetch_assoc($result)) {?>
<tr>
<td><form action='edit.php' method='get'>
<button type='submit' name='edit' id = 'edit' value='<?php echo $query_row['topic_id'];?>' class='btn btn-success'>EDIT</button><br />
</form></td>
</tr>
<?php
} ?>
When this button is clicked, page is navigated to another page "edit.php" which has 2 buttons, one for add new video and second for viewing video gallery.
edit.php:
$id = $_GET['edit'];
echo 'topic id----> ' . $id;
<form action='add_video.php' method='get'>
<button type='submit' name='add' id = 'add' value='<?php echo $id;?>' class='btn btn-success'>ADD NEW VIDEO</button>
</form>
<form action="video.php" method="get">
<button type="submit" name="goback" id="goback" value="submit" class="btn btn-primary">VIEW GALLERY</button>
</form>
The class where videos are added has a form for topic name, details etc.
add_video.php
$id = $_GET['add'];
echo 'topic id----> ' . $id;
<form action="add_video.php" method="post">
Video Title: <input type="text" name="video_name"><br />
Video Detail: <input type="text" name="video_detail"><br />
Video Question: <input type="text" name="video_question"><br />
Video Link: <input type="text" name="video_link"><br />
<input type="submit" name="submit" value = "Submit"><br />
</form>
When "submit" button is clicked, following code executes:
if(isset($_POST['submit'])) {
if(!(empty($_POST['video_name']) || empty($_POST['video_detail']) || empty($_POST['video_question']) || empty($_POST['video_link']))) {
$name = $_POST['video_name'];
$detail = $_POST['video_detail'];
$question = $_POST['video_question'];
$link = $_POST['video_link'];
$insert = "INSERT INTO tb_video_management(topic_id, video_name, video_detail, video_question,video_link) VALUES ('$id','$name','$detail', '$question','$link')";
if(!mysqli_query($con,$insert))
echo "error";
header('location:edit.php');
}
}
The problem I am facing is, when I click submit button, the value in $id is lost (may be because another button (submit) is pressed) and it fails to insert the record as there is no value for "topic_id" anymore. I cannot resolve this issue of keeping foreign key value even after pressing submit button.
So far I have been creating extra table to hold value for topic_id which is definitely not the right approach.
To use the $id into another page, you must have to store that in such a way that it will be remain exist after submit.That can be done by using the hidden field.
You may set the value of $id like:
<input type="hidden" name="topic_id" value="<?php echo $id?>">
Once you submit and redirect to add_video.php, you may get the value of $id same as another field video_detail.
On submit look like:
if(isset($_POST['submit'])) {
$topic_id = $_POST['topic_id'];
}
I am trying to get my page to redirect after deleting a record from the database but it wont redirect. It is echoing out text and also deleting the record but it just reloads me on the same page with a form that no longer has information in it.
Here is the button im using
echo '<form>';
echo '<br /><br /><input style="cursor:pointer" class="button" type="submit" value="Delete Event" name="delete" id="delete" />';
echo '</form>';
Here is the PHP im using to delete the row from the DB
if (isset($_POST['delete'])){
$mysqli->query('DELETE FROM information WHERE id = '.intval($_GET['id']));
header('Location: index.php');
}
I have no idea whats wrong with it.
The header doesn't work, probably because there's already another one.
I suggest you to use a little part of Javascript:
if (isset($_POST['delete'])){
$mysqli->query('DELETE FROM information WHERE id = '.intval($_GET['id']));
echo "<script type='text/javascript'>window.location.href = 'index.php'</script>";
}
I assume that both the code snippets are present in a single PHP file. Then, your form will by default post to the same file using GET method.
Change your PHP code to look like this:-
<?php
if (isset($_GET['delete'])){
$mysqli->query('DELETE FROM information WHERE id ='.intval($_GET['id']));
header('Location: index.php');
}
echo '<form>';
echo '<br /><br /><input style="cursor:pointer" class="button" type="submit" value="Delete Event" name="delete" id="delete" />';
echo '</form>';
?>
Your form tag is completely empty. You check if $_POST["delete"] is set, but you haven't even specified the method of communication between your form and your PHP file on your form. Try changing your starting form tag to this:
<form method = "POST" action = "YOUR PHP FILE.php">
Your PHP file seems fine as long as index.php is on the same level as the form.
You can also redirect your page to somewhere else this way:
echo "<meta http-equiv="refresh" content="1;url=index.php"/>"
<form>
Delete id <input type = "text" name ="deleteid" id ="deleteid"/>
<input type ="submit" name = "submit" />
</form>
<?php
if (isset($_POST['submit'])){
$id = $_POST['deleteid'];
$query = "DELETE FROM information WHERE id = $id";
//rest Execute the query
header('Location: xyx.php');
}
<?
I am trying to run the below query which basically create a submit button. However when I am trying to click the Accept Request button it is not resolving the if condition and directly echo what is written in else condition.
Can someone help why this would be happening?
<?php
if(isset($_POST['acceptrequest'.$user_from]))
{
echo "you are now freind !";
} else
{
echo 'Error in reading - acceptrequest'.$user_from;
}
?>
<form action = "friend_request.php" method = "POST">
<input type="submit" name = "acceptrequest<?php echo $user_from;?>"
value="Accept Request" style = "margin-left: 5px;" />
<input type="submit" name = "ignorerequest<?php echo $user_from;?>"
value="Ignore Request" style = "margin-left: 5px;" />
</form>
In general, you ought not use variables to define the name of a form input.
Specifically because of the "variable" nature of variables, you can't be sure that the name posted will match the name you're looking for.
In order to keep your application stateless, you should instead post the variable kn its own hidden input.
Below, I modified your form to post user_from as its own input, separate from acceptrequest and ignorerequest.
This should fix any state issues that you were experiencing before.
<?php
if (isset($_POST['acceptrequest')) {
echo "You are now friend with {$_POST['user_from']}!";
} else if (isset($_POST['ignorerequest')) {
echo "You ignored the request from {$_POST['user_from']}!";
} else {
echo 'Error in reading - acceptrequest'.$user_from;
}
?>
<form action = "friend_request.php" method="POST">
<input type="hidden" name="user_from"
value="<?php echo $user_from;?>" />
<input type="submit" name="acceptrequest"
value="Accept Request" style = "margin-left: 5px;" />
<input type="submit" name="ignorerequest"
value="Ignore Request" style = "margin-left: 5px;" />
</form>
Maybe You haven't set all variables. Try to define that and use: $
So create something like: $acceptrequest == something
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.
I am trying to create a "report" that can be filtered using a form on the top of the page. The options to filter the results is the Fiscal Year which is the current FY by default and multiple categories (check boxes) which are all checked by default. The page generates properly with the default data but when the form is submitted the page will "refresh" but there is no POST data generated. I tried creating a copy of the page and setting it as the action URL but it still did not have any POST data and used the defaults. I will include my code below and will try to narrow it down to just the necessary parts to make it easier but can share all of it if need be. Thank you in advance for any help offered.
<body>
<?php
if(isset($_POST['submit'])){echo"SET";} else{echo"NOT SET";}
// Establish Connection and Variables
// Connection
include "./include/class/DBConnection.php";
DBConnection::$dsn;
DBConnection::$user;
DBConnection::$pass;
DBConnection::getDBConnection();
// The Current Fiscal Year
$today = getdate();
$month = $today['month'];
// seperate first and second half of fiscal year
$old = array('January','February','March','April','May','June');
if (in_array($month,$old)) {
$year = $today['year'] + 1;
}
else {
$year = $today['year'];
}
// Create SQL Query Variables - Removed for post
// Set filter criteria
// Retrieve array of possible categories and create SQL WHERE statment
$catAllCxn = DBConnection::$cxn->prepare($SQL_Categories);
$catAllCxn->execute();
$catAllCxn->setFetchMode(PDO::FETCH_ASSOC);
$catAllArray = array();
while($catAllRow = $catAllCxn->fetch()) {
$cat = $catAllRow['Category'];
array_push($catAllArray, $cat);
}
$catAllInQuery = implode(',',array_fill(0,count($catAllArray),'?'));
// Create array for category filter IF form was submitted to itself
if (isset($_POST['submit'])){ // if page is submitted to itself
$catFilterArray = $_POST['Category'];
$catFilterInQuery = implode(',',array_fill(0,count($catFilterArray),'?'));
}
// Switch for ALL or Filtered report
if(!isset($_POST['submit'])) { // if page is not submitted to itself
$FiscalYear = $year;
// $DiscludedDepartmentNumbers = "21117";
$catArray = $catAllArray;
$IncludedCategories = $catAllInQuery;
}
else {
$FiscalYear = $_POST["FiscalYear"];
// $DiscludedDepartmentNumbers = "21117";
$catArray = $catFilterArray;
$IncludedCategories = $catFilterInQuery;
}
?>
<!-- Filter Form -->
<div id="filters" style="border: 1px solid;">
<form name="filter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST">
Fiscal Year: <input type="text" name="FiscalYear" value="<?php echo $FiscalYear; ?>" /> <?php if(isset($_POST['submit'])){echo"SET";} else{echo"NOT SET";}?>
<br />
<fieldset>
<legend>Select Categories</legend>
<?php
foreach($catAllArray as $catAllRow) {
if (!isset($_POST['submit'])) {
echo "<input type=\"checkbox\" name=\"Category\" value=\"".$catAllRow."\" checked=\"checked\" />".$catAllRow." \n";
}
else if(in_array($catAllRow,$catArray)) {
echo "<input type=\"checkbox\" name=\"Category\" value=\"".$catAllRow."\" checked=\"checked\" />".$catAllRow." \n";
}
else {
echo "<input type=\"checkbox\" name=\"Category\" value=\"".$catAllRow."\" />".$catAllRow." \n";
}
}
?>
</fieldset> <br />
<input type="submit" value="submit" />
</form> <!-- End: filter -->
</div> <!-- End: filters -->
From here the original code continues to output results into a table but this works properly and I don't think it is the problem. I can share more if asked.
You need to give the submit button a name, if that's what you're using to check if the form is submitted...
<input type="submit" value="submit" name="submit" />
Or if you dont want to change the submit button, you can check isset on the category input instead
if(isset($_POST['Category'])){echo"SET";} else{echo"NOT SET";}
I think that your check if there is a _POST value is wrong. try this:
if(isset($_POST['FiscalYear']))
And see if that works
you need to name your submit button if you want to check for it
<input type="submit" value="submit" name="submit" />
otherwise php will not place it in the $_POST array