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
Related
I currently have an edit form, where all values are echoed from the db as the "values" for each input, the user would then retype and "save" the value to append to the db. All echoes work but i have been unable to echo the database value for the options... anybody knows how to?
& Thanks
Code below:
<fieldset>
<form id="input-form" method="POST" action="../php/edit-import-record.php">
Airway Bill Number*:
<input type=text name=AwbNo size=30 class="input" value="<?php echo $awb ?>" required>
Client Code:
<?php //OPEN DROP DOWN BOX
include("../login/dbinfo.inc.php");
$comm=#mysql_connect(localhost,$username,$password);
$rs=#mysql_select_db($database) or die( "Unable to select database");
$sql= "SELECT DISTINCT ClientCode, ClientName FROM tbl_client ORDER BY ClientCode";
$result = mysql_query($sql);
echo "<select name='ClientCode'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['ClientCode'] ."'>" . $row['ClientName'] ."</option>";
}
echo "</select><br>"; //CLOSE DROP DOWN BOX
?><br>
Vessel Name*:
<input type=text name=VesselName class=form-control id=inputSuccess size=30 class="input" value="<?php echo $vsl ?>" required>
Number of Pieces:
<input type=number name=Pieces size=30 class="input" value="<?php echo $pcs ?>" >
Total Weight (kg):
<input type=number name=Weight size=30 class="input" value="<?php echo $wgt ?>" >
Carrier:
<input type=text name=Carrier size=30 class="input" value="<?php echo $car ?>" >
Sender:
<input type=text name=Sender size=30 class="input" value="<?php echo $snd ?>" >
Status:
<input type=text name=Status size=30 class="input" value="<?php echo $stt ?>" >
Arrival Date:
<input type=date name=ArrivalDate size=30 class="input" value="<?php echo $ard ?>" >
Customs:
<input type=text name=Customs size=30 class="input" value="<?php $ctm ?>" >
<br><small>Fields marked with * are required to be filled in.</small>
<div class="inputformbutton">
<button type="reset" class="btn btn-default btn-sm">Reset</button>
<button type="submit" class="btn btn-primary btn-sm">Create Record</button>
</div>
</fieldset>
I have a form page and when I submit this form all inputs are posting successfully except this one:
<input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()"
<?php if($this->data['kullanici_id']){echo 'readonly';} ?>
value="<?php echo $this->data['kullanici_id']?>">
But why?
-This is my .phtml file:
<html>
<head>
</head>
<body>
<form enctype="multipart/form-data" action="/admin/kaydet" method="post" onSubmit="javascript: beforeSubmit();">
<?php if(strlen($this->data['id'])):?>
<input type="hidden" name="id" value="<?php echo $this->data['id']?>">
<?php endif;?>
<font color="green"><h3>DÜZENLE</h3></font>
<img src="/foto/<?php echo $this->data['fotograf']?>" height="110" width="110" align="left" />
<table class="table">
<tr>
<td>T.C. Kimlik No.:</td>
<td><input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()" <?php if($this->data['kullanici_id']){echo 'readonly';} ?> value="<?php echo $this->data['kullanici_id']?>"></td>
</tr>
<?php if(!strlen($this->data['id'])):?>
<tr>
<td>Parola:</td>
<td><input id="password2" class="form-control" type="password" name="parola" value="<?php echo $this->data['parola']?>"></td>
</tr>
<tr>
<td>Parola Tekrar:</td>
<td><input onchange="passwordCheck(this.value)" class="form-control" type="password" name="parola" value="<?php echo $this->data['parola']?>"></td>
</tr>
<?php endif; ?>
</table>
<td><button type="submit" class="btn btn-success btn-sm glyphicon glyphicon-floppy-disk">KAYDET</button> </td>
</form>
</body>
</html>
If I have an id; page looks like an edit member page, if I haven't; page will add a new member. In id="TC" input, if I edit a member, this input shouldn't change, so I add a readonly to solve this. But when I submit, input does not post.
Sorry about my bad English :D
Reason your field is not being submitted it is because its set to readonly.
Reason for this is 'If user cannot change the field there is no point of submitting it as value will always remain the same'.
One way to mitigate this behavior is to add hidden field with same name
<input type="hidden" name="kullanici_id" value="<?php echo $this->data['kullanici_id']?>"> />
<input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()" <?php if($this->data['kullanici_id']){echo 'readonly';} ?> value="<?php echo $this->data['kullanici_id']?>" />
Hi I am coming into an issue in my form when i try to set the value of my field
to a value of a variable it works exactly how i want it for my product field but nothing is showing up in the price field in my form
any help is appreciated i have benn at it for a good while
$query = "SELECT * FROM suplements WHERE product = '$product' OR name = '$prodname' OR price = '$price' OR image = '$image'";
$result = #mysql_query($query) or die ("could not execute SQL query");
while($row = mysql_fetch_array($result))
{ ?>
<table>
<tr>
<th>Product :<?php echo $row["product"]?></th>
</tr>
<td><img src = "<?php echo $row["image"] ?>"height="400" width="400"><?php ?>
<td>
<form>
<input type="text" name="qty" value="1" size="2"><br>
Product <input type="text" name="product" value="<?php echo htmlentities($product); ?>" /></br>
Price <input type="text" name="price" value="<?php echo htmlentities($price); ?>" />
<input type="submit" name="submit" value="ADD" >
</form>
<?php echo $row["information"];?></td>
<tr><td><?php echo $row["product"];?>
<?php echo $row["name"];?>
<?php echo $row["drand"];?>
<?php echo $row["weight"];?>
<td><?php echo $row["price"];?></td></tr>
</tr>
</table>
Is this what you are looking for?
Product <input type="text" name="product" value="<?php echo htmlentities($row['product']); ?>" /></br>
Price <input type="text" name="price" value="<?php echo htmlentities($row['price']); ?>" />
For debug sake, do this after the while: "print_r($row);" - this will show you the exact contents of the $row variable
Plus... it would be nice to add limit 1 to your query
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.
I have a strange issue that I cannot get my head around.
I have the following form and when I click submit I do not GET or POST all fields in the form. Only two fields are being picked up being - isnew=true action=object &submit=Start
<form name="newOffer" action="/auth/dashboard" method="post">
<td><?php echo form_hidden('isnew', 'true');?><?php echo form_hidden('action', 'object');?><input type="text" id="newOfferItem" placeholder="Offer Free Item" class="input-xlarge"></td>
<td><input type="text" id="newOfferText" placeholder="Offer Description" class="input-xlarge" rel="tooltip" title="Description How to get free item"></td>
<td><input type="text" id="newOfferFreeOn" placeholder="Stamps for free item" class="input-xlarge" rel="tooltip" title="Number only. Ex. 5"></td>
<td><span class="label label-danger">Inactive</span></td>
<td><?php $attributes = 'class = "btn btn-success"'; echo form_submit('submit', 'Start', $attributes);?></td>
</form>
You need to add NAME attributes for each INPUT element - either instead of or in addition to the ID attributes.
e.g.
<form name="newOffer" action="/auth/dashboard" method="post">
<td>
<?php echo form_hidden('isnew', 'true');?>
<?php echo form_hidden('action', 'object');?>
<input type="text" NAME="newOfferItem" id="newOfferItem" placeholder="Offer Free Item" class="input-xlarge">
</td>
<td>
<input type="text" NAME="newOfferText" id="newOfferText" placeholder="Offer Description" class="input-xlarge" rel="tooltip" title="Description How to get free item">
</td>
<td>
<input type="text" NAME="newOfferFreeOn" id="newOfferFreeOn" placeholder="Stamps for free item" class="input-xlarge" rel="tooltip" title="Number only. Ex. 5">
</td>
<td>
<span class="label label-danger">Inactive</span>
</td>
<td>
<?php $attributes = 'class = "btn btn-success"'; echo form_submit('submit', 'Start', $attributes);?>
</td>
</form>
Always add a name attribute in input element.
Here is an example for you..
index.html
<form method="POST" action="process.php">
<input type="text" name="username" value="">
<input type="password" name="password" value="">
<input type="submit" name="submit" value="login">
</form>
process.php
<?php
// checking if submit is pressed
if (isset($_POST['submit'])) {
// assigning posted values
$username = $_POST['username'];
$password = $_POST['password'];
// testing
echo $username . "<br>";
echo $password;
}
?>