I have this page where it displays some info from a database
here is some code:
while($row = mysql_fetch_array($result))
{ echo "<tr>";
echo "<td><form action='deleteitem.php' method='get'><input type='submit'></form> </td>";
echo "<td><textarea name='description' cols='40' rows='8'>" . $row['some_info']"
}
I'm not sure how to pass the particular row's id to the action script so that an item can be deleted by the user if they want
You can use hidden input:
<input type="hidden" name="id" value="<?php echo $row['id'] ?>" />
Related
I would like some help printing what is in a certain textbox that was created by an echo command.
while($row = $result->fetch_assoc()){
$stringTest = $row['Price'];
$AssetId = $row['AssetId'];
echo "<center><div> <h3>Cost: ".$stringTest."";
echo '<form action="" method="get"><input type="text" name="uid">';
echo "</br><input class='myButton' type='submit' Name='Submit1' VALUE='I have bought'></a></form>";
/** ^ Input value I would like to get *//
echo "<a href='https://www.roblox.com/item-item?id=".$AssetId."' class='myButton'>Buy</a></h3></div></center>";
}
Use the code below to get the value from submit:
if(isset($_GET['Submit1'])) {
echo $_GET['Submit1'];
}
When the user clicks submit, it will echo the value of it.
If you want to print PHP element in a textbox you should put it in the value tag of the input
<?php
echo "<input type='text' value='" . $val . "'>";
?>
In my HTML table I have created a button link for each and every row . I need to edit existing rows and add new rows. The links are working perfectly but I need to pass parameters to url .Like for example I f I need to add new rows I need to get the values of the data cells like
echo "<form action=insert_rows.php?machine_ip&crawler_type&keywords&instances_no method=get>";
Its going to the proper link but I am not able to the row data ,its not getting passed, same with existing rows, through submit button I am able submit to the link but I am not able to pass the row values.For existing rows I need to pass the respective primary keys and then access the rows.
My code so far
<style>
input{
width: 100%
}
</style>
<?php
include('db_connect.php');
$conn = db_connect();
mysql_select_db("crawler_status");
$query="Select * from crawler_info";
$result=mysql_query($query);
echo "<table style=width:1000px border=2>";
echo "<tr>";
echo "<td>"."<b>"."Machine IP"."<b>"."</td>";
echo "<td>"."<b>"."Crawler Type"."</b>"."</td>";
echo "<td>"."<b>"."Keywords"."</b>"."</td>";
echo "<td>"."<b>"."No Of Instances"."</b>"."</td>";
echo "<td>"."<b>"."No Of Keywords"."</b>"."</td>";
echo "<td>"."<b>"."Running Status"."</b>"."</td>";
echo "</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<form action=individual_rows.php method=get>";
echo"<td>". $row['machine_ip']."</td>";
echo "<td>". $row['crawler_type']."</td>";
echo "<td>". $row['keywords']."</td>";
echo "<td>". $row['no_of_instances']."</td>";
echo "<td>". $row['no_of_keywords']."</td>";
echo "<td>". $row['running_status']."</td>";
echo "<td>"."<input type=submit value =EDIT></td>";
echo "</form>";
echo "</tr>";
}
echo "<tr>";
echo "<form action=insert_rows.php?machine_ip&crawler_type&keywords&instances_no method=get>";
echo "<td>"."<input type=text name=machine_ip form=my_form></td>";
echo "<td>"."<input type=text name=crawler_type form=my_form ></td>";
echo "<td>"."<input type=text name=keywords form=my_form></td>";
echo "<td>"."<input type=text name= =instances_no></td>";
echo "<td>"."<input type=text name=keywords_no></td>";
echo "<td>"."<input type=submit value =submit></td>";
echo "</form>";
echo "</tr>";
echo "</table>";
?>
How should I proceed?
action=insert_rows.php?machine_ip&crawler_type&keywords&instances_no
According to above when you are submitting form then action URL get truncated ?machine_ip&crawler_type&keywords&instances_no and only you have working action URL is action=insert_rows.php So according to me you should use hidden field to send data. like
<form action ='action=insert_rows.php' method=get>
<input type=hidden name=machine_ip value= ''>
<input type=hidden name=crawler_type value= ''>
<input type=hidden name=keyword value= ''>
<input type=hidden name=instances_no value= ''>
</form>
where value has your desired value.
You can try hidden field to pass data.
Use
<input type="hidden" name="machine_ip" value="<?php echo $row['machine_ip'] ?>" />
same may be applied for other field.
function LoadProtocols(){
?>
<?php
$result=mysql_query("SELECT id,name,Destination_port, Destination_port_range_start, Destination_port_range_stop FROM protocols;");
echo '<table class="tftable" border="1">';
echo '<tr><th>protocol Name</th><th>Port</th><th></th></tr>';
echo "<form method='POST' action=''>";
if( $row=mysql_fetch_array($result)){
mysql_data_seek($result,0);
while( $row=mysql_fetch_array($result))
{
echo "<tr>
<td>".$row['name']."</td>
<td> "?><input type="hidden" id="id" name="id[]" value=" <?php echo $row['id']?>"> <input id="txt_port" name="txt_port[]" type="text" class="required" title="Port. This is a required field" value=" <?php echo $row['Destination_port'] ?> "></td>
<?php
echo "<td><a onclick='return show_confirm();'><input name='update' class='button' type='submit' value='Update'></a></td></tr>";
if(ISSET($_POST["update"]) and $_SERVER['REQUEST_METHOD'] == "POST"){
$id=$_REQUEST['id'];
$port=$_REQUEST['txt_port'];
$menu=$_GET['Menu'];
$result=mysql_query("UPDATE protocols SET Destination_port=".$port." WHERE id=".$id.";");
header("Location: Overview.php?Menu=".$menu."&Overview=1");
}
echo "</form>";
}
echo '<table>';
}
I made a simple table which as got 3 columns, the first column is a name, second one has a textbox which contains a number (with a hidden id that I need) and last one is a button to update that specific row.
The big problem I have that it only updates the last row, therefore I read that you needed to add [] to ur names and loop through it to update that specific row.
It's still not working and I can't figure out how to just let one specific row update with that [] array.
Thank you for reading and helping.
$_request['id'] is nothing but array ,also header should not be in loop
so Write This
mysql_data_seek($result,0);
$counter=0;
while( $row=mysql_fetch_array($result))
{
echo "<tr>
<td>".$row['name']."</td>
<td> "?><input type="hidden" id="id" name="id[]" value=" <?php echo $row['id']?>"> <input id="txt_port" name="txt_port[]" type="text" class="required" title="Port. This is a required field" value=" <?php echo $row['Destination_port'] ?> "></td>
<?php
echo "<td><a onclick='return show_confirm();'><input name='update' class='button' type='submit' value='Update'></a></td></tr>";
if(ISSET($_POST["update"]) and $_SERVER['REQUEST_METHOD'] == "POST"){
$id=$_REQUEST['id'];
$port=$_REQUEST['txt_port'];
$menu=$_GET['Menu'];
$result=mysql_query("UPDATE protocols SET Destination_port=".$port." WHERE id=".$id[$counter].";");
$counter++;
// header("Location: Overview.php?Menu=".$menu."&Overview=1");
}
Instead of this
mysql_data_seek($result,0);
while( $row=mysql_fetch_array($result))
{
echo "<tr>
<td>".$row['name']."</td>
<td> "?><input type="hidden" id="id" name="id[]" value=" <?php echo $row['id']?>"> <input id="txt_port" name="txt_port[]" type="text" class="required" title="Port. This is a required field" value=" <?php echo $row['Destination_port'] ?> "></td>
<?php
echo "<td><a onclick='return show_confirm();'><input name='update' class='button' type='submit' value='Update'></a></td></tr>";
if(ISSET($_POST["update"]) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$id=$_REQUEST['id'];
$port=$_REQUEST['txt_port'];
$menu=$_GET['Menu'];
$result=mysql_query("UPDATE protocols SET Destination_port=".$port." WHERE id=".$id.";");
header("Location: Overview.php?Menu=".$menu."&Overview=1");
}
I have a php page with this code that passes a variable of a button to next page:
<div><center><table>
while($row = mysqli_fetch_array($result))
{
echo "<td><form action= display.php method= 'post'><input type='hidden'
name='projectid' value=".$row['projectid'].">
<input type= 'submit' name= 'type'
value= 'View/Amend Project Details'></form></td>\n";
}
echo "</table></div>";
I have this on my next page in a table:
$projectid= $_POST['projectid'];
echo "<td>" . $row['projectname'] . "</td>";
I still cannot see the problem, any idea?
The problem is that you're trying to use the $row on your second page, and it isn't set there.
You have to either do the mysqli query again, or transfer the value of $row['projectname'] through the form, using a hidden input field.
<?php
while($row = mysqli_fetch_array($result,,MYSQLI_ASSOC))
{
echo " name='projectid' value=".$row['projectid']."> value= 'View/Amend Project Details'>\n";
}
I have a table with 3 columns like so in index.php:
ID | StName | Inspect
_________________________________
1 Wisconsin INSPECT
2 Alabama INSPECT
3 Nebraska INSPECT
The right most column is a submit button which takes the user to a page called inspect.php. I want to send the corresponding ID column value to inspect.php when a user clicks the INSPECT button so that I can use that value inside inspect.php, how can I do this?
Currently I have:
//index.php
echo "<table border = 1>
<tr>
<td>ID</td>
<td>StName</td>
</tr>";
// go into a loop to create more rows -- omitted
echo "<tr>";
echo "<td>" . $resultArr[0] . "</td>";
echo "<td>" . $resultArr[1] . "</td>";
echo "<td> <form action='inspect.php' method='get'>
<input type='Submit' value='Inspect'>
</form>
</td>";
echo "</tr>";
echo "</table>";
$resultArr[0] contains the ID value I want to send to inspect.php
So add an input field inside the form with a name attribute which will be an index key name on inspect.php page
<form action='inspect.php' method='get'>
<input type='hidden' name="id" value='<?php echo $resultArr[0]; ?>'>
<input type='submit' value='Inspect'>
</form>
A better and simple way to go for this is without a submit, just use a hyperlink like
Inspect
And later process this id on inspect.php page
I think I got what you wanted to work. I am using different data in the array, but you should be able to change to your needs anyway.
On index.php:
$resultArr = array("dave","fff","erere");
echo "<table border = 1>
<tr>
<td>ID</td>
<td>StName</td>
</tr>";
// go into a loop to create more rows -- omitted
echo "<tr>";
echo "<td>" . $resultArr[0] . "</td>";
echo "<td>" . $resultArr[1] . "</td>";
echo "<td> <form action='inspect.php' method='get'>
<input type='hidden' name='id' value=' $resultArr[0] '>
<input type='submit' name='inspect' value='Inspect'> </td>";
echo "</tr>";
echo "</table>";
And on inspect.php:
if( $_GET['inspect']){
$name = $_GET['id'];
echo $name;
}
This outputs the value of $resultArr[0], which I think you wanted.