Jump to content

edit button on php table created from sql DB


Recommended Posts

Hi!

Im making a php script which goes over an MySQL DB and present the Db as Table (its actually a db of customers where there's info of their ship address, phone, etc).

so the php script fetch array and take 1 row at a time, and ofcours go thru all the elements in the DB and present it in a table.

I wish i can make an EDIT button at the end of each row where the user can press it and it will move it to another (already made) edit user php script with the row Customer number. 

of cours i can end each line with a button but how can i make it so that after all the table has been printed out (maybe 250 rows) each button at the end of the row will lead to the edituser.php with the specific row customer number?

any idea? thanks in advance

Link to post
Share on other sites

echo '<td><form action="findorder.php?'. $order_num.'"><input type="submit"  value="edit" /></form></td>';

doesnt seep to work... above is the line that create the edit button, (order_num is uniqe in the database), but when pressed, it send the user to the findorder.php? with no order_num.. what am i doing wrong here?

Edited by Weiss
Link to post
Share on other sites
1 hour ago, Weiss said:

echo '<td><form action="findorder.php?'. $order_num.'"><input type="submit"  value="edit" /></form></td>';

doesnt seep to work... above is the line that create the edit button, (order_num is uniqe in the database), but when pressed, it send the user to the findorder.php? with no order_num.. what am i doing wrong here?

dsonesuk is referring to using <a> tag. Like:

<a href="edituser.php?cust_id=n">Edit User</a>

 

  • Like 1
Link to post
Share on other sites

when i try doing this:

echo '<td><form method="get" action="findorder.php"><input type="submit"  name="testing" value="Edit" /></form></td>';

i get redirected to: http://localhost/logitech/findorder.php?testing=Edit

..

i can use $_GET['testing'] but it will give me whaever in the value which is "Edit".. i cannot change the value because it will change the writing on the button

Link to post
Share on other sites
17 minutes ago, dsonesuk said:

Actually No, there are several ways to do this, and I did not which had been chosen, but the how the querystring and value are used is the important part to get it to work.

Last time i checked GET is for query strings (using <a> tag, although can be applied to form via method get) which is what you mentioned in your post. But okay man. 

Edited by Don E
  • Like 1
Link to post
Share on other sites
37 minutes ago, Don E said:

Last time i checked GET is for query strings which is what you mentioned in your post. But okay man.  

When a get form is submitted it would produce an querystring also

 

38 minutes ago, Weiss said:

echo '<td><form method="get" action="findorder.php"><input type="submit"  name="testing" value="Edit" /></form></td>';

You are not adding querystring to form action, example

echo '<td><form method="get" action="findorder.php?order_num='.$order_num.'"><input type="submit"  name="testing" value="Edit" /></form></td>';

In findorder.php

$this_order = $_GET['order_num'];  //would retrieve value of $order_num

same as

$this_test = $_GET['testing'] // would retrieve value of 'Edit'.

OR add to hidden input, like I said there are several ways to do this

echo '<td><form method="get" action="findorder.php"><input type="hidden"  name="order_num" value="'$order_num.'" ><input type="submit"  name="testing" value="Edit" /></form></td>'; 

 

Edited by dsonesuk
  • Like 1
Link to post
Share on other sites
8 minutes ago, dsonesuk said:

When a get form is submitted it would produce an querystring also

 

You are not adding querystring to form action, example

echo '<td><form method="get" action="findorder.php?order_num='.$order_num.'"><input type="submit"  name="testing" value="Edit" /></form></td>';

In findorder.php

$this_order = $_GET['order_num'];  //would retrieve value of $order_num

same as

$this_test = $_GET['testing'] // would retrieve value of 'Edit'.

 

Well if i do this i get directed to the findorder.php. my url shows: http://localhost/logitech/findorder.php?testing=Edit

when i echo $this_order i get nothing

when i echo $this_this i get: Edit

Link to post
Share on other sites

Try last suggestion I added in my post before this one, the previous will work if changed to post method but you would use

$this_order = $_GET['order_num'];  //would retrieve value of $order_num

$this_test = $_POST['testing'] // would retrieve value of 'Edit'

because you are using get the input value will overwrite the one set in action (unless you add a '&' at end to include both)

  • Like 1
Link to post
Share on other sites
	while ($row = mysqli_fetch_array($data)) {
		echo '<tr>';
		echo '<td>'.$row['order_num'].'</td>';
		echo '<td>'.$row['cust_name'].'</td>';
		echo '<td>'.$row['store_name'].'</td>';
        echo '<td><form method="get" action="findorder.php?order_num='.$order_num.'"><input type="submit"  name="testing" value="Edit" /></form></td>';
          
          }

doesnt work thanx very much though dsonesuk, posted the code maybe someone will be able to fix this :P

Link to post
Share on other sites
echo '<form method="post" action="findorder.php?order_num=' . $order_num . '"><input type="submit"  name="testing" value="Edit" /></form>';

Will work with

        $this_order = $_GET['order_num'];  //would retrieve value of $order_num

        $this_test = $_POST['testing']; // would retrieve value of 'Edit'.

        echo $this_order . '<br>' . $this_test;

IF get method the input will overwrite the querystring set in action, if you wish to use GET method you would have to do it this way

echo '<td><form method="get" action="findorder.php"><input type="hidden"  name="order_num" value="'$order_num.'" ><input type="submit"  name="testing" value="Edit" /></form></td>'; 

with

        $this_order = $_GET['order_num'];  //would retrieve value of $order_num

        $this_test = $_GET['testing']; // would retrieve value of 'Edit'.

        echo $this_order . '<br>' . $this_test;

IF going this way it would be better to set form AS POST method, so the naming and values do not appear in address bar of browser

  • Like 1
Link to post
Share on other sites

:| still not working.. i dont understand how can i use post method and comine it with $_GET on the second script. ANYWAY, maybe A HREF is a better option but is there a way to let the user click on <a href> and send it with $order_num data?

 

thanks very much again for your your time 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...