Welcome! Log In Create A New Profile

Advanced

Edit and Delete links in table

Posted by OngeskikteVeldmuis 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Edit and Delete links in table
October 04, 2013 08:21PM
As per the screenshot of the list_players.php page.... the fields containing links for editing and deleting a player is repeated and it looks rather stupid (in my humble opinion) tongue sticking out smiley

I hope it's ok if I instead, set the player's first name as an anchor which links directly to edit/delete options...

like you said, as long as the functions work.... thumbs up

I guess I'm more design oriented smile
avatar
Mac
Re: Edit and Delete links in table
October 10, 2013 08:43AM
This format is generally accepted when data is presented in an Excel-like layout.... As it stands, when you click delete you will be asked if you are sure you want to delete - so two clicks. Edit is one click. Because you do not differentiate between the edit/delete by using the name as the link, it means this choice is at least another click away, and then a confirmation of delete - so that is 3 clicks. Also, the user most now read elsewhere to click the name - not user friendly? But do it whichever way you want.
Re: Edit and Delete links in table
October 10, 2013 09:31AM
Please help me to understand this, i created a link with yes or no option. In my script,how will i check if the user clicked yes?
avatar Re: Edit and Delete links in table
October 10, 2013 09:44AM
Depends on how you have coded your link - or is it 2 links ?

Most likely using $_GET, and then if ..else.
Re: Edit and Delete links in table
October 10, 2013 01:50PM
Sorry about that.

I'll do that
avatar
Mac
Re: Edit and Delete links in table
October 10, 2013 01:59PM
First use the formatted code button to post code and do not post all your code - only the offending lines.
Re: Edit and Delete links in table
October 10, 2013 02:22PM
Hi there
pls help, My edit page doesn't get data from the list when displaying a form and if i try to update nothing happens as well.

Here is my code, you help will be appreciated I try to figure it out.

Language: PHP
//Get the Player Id $Player_ID =$_GET[';Player_ID';]; if(isset($_POST[';submit';])) { // assign variables $Name = $_POST[';Name';]; $Surname = $_POST[';Surname';]; //etc

And then

Language: PHP
$query1 = "UPDATE player_reg SET Surname = ';$Surname';, Name = ';$Name';, Contact_Number=';$Contact_Number';, Email = ';$Email';, Position =';$Position';, Username = ';$Username';, Password = ';$Password'; WHERE Player_ID = ';$Player_ID';"; $result = mysql_query($query1) or die ("Query Failed: " . mysql_error()); if(query1) {



Here is the form
Language: PHP
<form action ="list_players.php" method ="POST" align = "center"> <input type = "hidden" name = "Player_ID" value = "<?php echo $row[';Player_ID';]; ?>"/> </br> Name: <input type ="text" name ="Name" value ="<?php echo $row[';Name';]; ?>"/><br/> Surname : <input type ="text" name ="Surname" value ="<?php echo $row[';Surname';]; ?>"/><br/> // and so on   <input type ="submit" name ="submit" value ="Submit"/> </form>
avatar Re: Edit and Delete links in table
October 10, 2013 02:46PM
There is nothing in the $_GET array. There is nothing in your form which involves the $_GET array, why are you trying to extract a value from it ?

You extract all values from the $_POST array, including hidden inputs, when your form method is "POST".

Put this in your //assign variables -

Language: PHP
$Player_ID = $_POST[';Player_ID';];
Re: Edit and Delete links in table
October 10, 2013 02:57PM
Nothing happens even if i try that - bigron11.
avatar Re: Edit and Delete links in table
October 10, 2013 03:03PM
This -

Language: PHP
if(query1) // query1 does not exist in any event, the variable name is $query1 {

should be -

Language: PHP
if ($result) // leave a space between the if and the (. {

Although it is not necessary, as it will never be false - the "or die" part will exit the script if it is false.
Re: Edit and Delete links in table
October 10, 2013 03:16PM
Oh that I wasn't aware.
Thanks anyway but it didn't change a thing.
avatar Re: Edit and Delete links in table
October 10, 2013 03:20PM
Do you get any error messages ?

Does your SQL query execute OK ?

Try putting a temporary echo statement after the line where you extract the Player_ID value, just to make sure you are getting a proper value for it.
avatar Re: Edit and Delete links in table
October 10, 2013 03:26PM
What do you mean by "nothing happens".

You need to execute another SQL query in order to be able to access any updated information in the table.
avatar
Mac
Re: Edit and Delete links in table
October 10, 2013 03:27PM
Methinks you need to go back to the tut sad smiley. The fact that you used $_GET to catch a $_POST suggest that?

Do this - when you catch a variable, echo it immediately as a "test" - if it works, then delete the echo and continue to the next line (me and bigron are on the same page - he posted just before me smiling smiley)

There are just too many things that could be wrong here - e.g. column names are case-sensitive?
Re: Edit and Delete links in table
October 10, 2013 03:44PM
No errors just display an empty form .

And I did put an echo statement now I see that it doesn't read from the table query.

Thanks Bigron and does it matter where I put my query for the table?
avatar Re: Edit and Delete links in table
October 10, 2013 04:36PM
Your form wont display any new information unless you query the database and insert the values into the input value attributes.

If you want to list the info (ie not a form) - you need to do the query just before you display the information.
Re: Edit and Delete links in table
October 13, 2013 06:51PM
I thank you much for your support. When do i really have to check when the SUBMIT button was clicked. Everything is working well except data for my edit page, the database is not updated.
Language: PHP
echo "Please update " . $fname . " " . $sname . ';\';s'; . '; '; . "information"; //Inform the user to edit the data in the form if needed if (isset($_POST[';Submit';])) //check if submit button was clicked { $player_id = $_GET[';player_id';]; //Update the table $query = "UPDATE playerregistration SET player_name = ';$fname';, player_surname = ';$sname';, player_contact_num = ';$cnumber';, player_email = ';$email';, player_position = ';$pos';, player_username = ';$uname';, player_password = ';$pword'; WHERE player_id = ';$player_id';"; $result = mysql_query($query); if ($result) { echo "Player';s information updated successfully"; //Was the data updated? } else { echo "Failed to update player';s information."; } mysql_close($connection);

My script does process the if ($result) potion.....




It looks like i also encounter the same problem with my delete page,especially the potion with checking if YES was clicked from the link to confirm the delete...My form simply display information,so i don't have the famous "SUBMIT" button. All i should do is to check if YES was clicked
Language: PHP
if (player_id==$player_id&action==yes) // Check if yes was chosen to definetely delete {   $query = "DELETE * FROM playerregistration WHERE player_id = ';$player_id';"; //use player_id to retrieve the player';s information $result = mysql_query($query); $result = mysql_query($query) or die("Query failed: " . mysql_error()); if ($result) { echo "Player deleted successfully."; } else { echo "Failed to delete a player <br>"; } mysql_close($connection); }

The link i created looks like
Language: PHP
//Option[yes or no] to make sure that the user really wants to delete the player echo "Are you sure you want to delete $fname $sname?&nbsp&nbsp;<a href=delete.php?player_id=$player_id&action=yes>Yes |</a>&nbsp;&nbsp;<a href=list_players.php>No</a>";

I am sorry for posting so much work at once,i only have 10 minutes to "steal" the internet. I am a prisoner and internet is forbidden.
Re: Edit and Delete links in table
October 13, 2013 06:53PM
I meant to type that my script does not process the if ($result) potion of my code....sad smiley
avatar Re: Edit and Delete links in table
October 13, 2013 07:19PM
Delete page -

This is incorrect -

Language: PHP
if (player_id==$player_id&action==yes) // Check if yes was chosen to definitely delete

The data is in the $_GET array.

Language: PHP
if (isset($_GET[';player_id';])) { $player_id = $_GET[';player_id';]; $action = $_GET[';action';]; // You don';t actually need this.


Your query did not work because $player_id was undefined.
avatar Re: Edit and Delete links in table
October 13, 2013 07:42PM
Language: PHP
echo "Please update " . $fname . " " . $sname . ';\';s'; . '; '; . "information"; //Inform the user to edit the data in the form if needed if (isset($_POST[';Submit';])) //check if submit button was clicked { $player_id = $_GET[';player_id';]; //Update the table

If player_id is in a hidden field in your form, you must extract it from the $_POST array.
Also note the capitalization in the name in the form - Player_ID - it MUST be exactly the same.

Language: PHP
{ $player_id = $_POST[';Player_ID';];


Quote

When do i really have to check when the SUBMIT button was clicked.

isset($_POST) will never be evaluated immediately below a form.
Remember, when the user clicks Submit the form is reloaded (Depending on the action), and execution starts again at the very top.
Nothing after a form is executed when a user clicks Submit.

Basically you need to do something like this -

if (not logged in)
redirect

if (user clicked the link) // if (isset()$_GET))

Query database and display data for editing;

else

if (user clicked Submit) // if (isset($_POST))

Write edited data to database;

else

default situation - initialize variables with "" so that form will display OK.



Then display the form.
Sorry, only registered users may post in this forum.

Click here to login