Weiss Posted September 3, 2017 Share Posted September 3, 2017 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 comment Share on other sites More sharing options...
dsonesuk Posted September 3, 2017 Share Posted September 3, 2017 Send it as GET querystring with customer number edituser.php?cust_id=n where 'n' will be the customer number. 1 Link to comment Share on other sites More sharing options...
Weiss Posted September 4, 2017 Author Share Posted September 4, 2017 (edited) 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 September 4, 2017 by Weiss Link to comment Share on other sites More sharing options...
Don E Posted September 4, 2017 Share Posted September 4, 2017 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> 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted September 4, 2017 Share Posted September 4, 2017 You haven't added a index reference name, just the value edituser.php?cust_id=n filename with querystring initialiser : index name : value ($order_mum) So when you need to read value of specific name index $this_order = $_GET['cust_id']; 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted September 4, 2017 Share Posted September 4, 2017 3 minutes ago, Don E said: dsonesuk is referring to using <a> tag. Like 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. 1 Link to comment Share on other sites More sharing options...
Weiss Posted September 4, 2017 Author Share Posted September 4, 2017 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 comment Share on other sites More sharing options...
Don E Posted September 4, 2017 Share Posted September 4, 2017 (edited) 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 September 4, 2017 by Don E 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted September 4, 2017 Share Posted September 4, 2017 (edited) 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 September 4, 2017 by dsonesuk 1 Link to comment Share on other sites More sharing options...
Weiss Posted September 4, 2017 Author Share Posted September 4, 2017 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 comment Share on other sites More sharing options...
dsonesuk Posted September 4, 2017 Share Posted September 4, 2017 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) 1 Link to comment Share on other sites More sharing options...
Weiss Posted September 4, 2017 Author Share Posted September 4, 2017 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted September 4, 2017 Share Posted September 4, 2017 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 1 Link to comment Share on other sites More sharing options...
Weiss Posted September 4, 2017 Author Share Posted September 4, 2017 :| 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 comment Share on other sites More sharing options...
Weiss Posted September 4, 2017 Author Share Posted September 4, 2017 solved it with a href thanx for your time Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now