I want to make a registration form page which also contains a table where we retrieve the data entered through the form into the database. The table also have edit and delete options so that we can later make any change. I saw an example, how to make such 'edit and delete' table. But I could not understand the code given below:
<?php
if(isset($_REQUEST['s']))
{
if($_REQUEST['s']=="m")
{
echo "Successfully deleted.";
}
}
if(isset($_REQUEST['s']))
{
if($_REQUEST['s']=="e")
{
echo "Successfully update.";
}
}
?>
Can you explain it's meaning, line by line?
the code below doesn't make much sense. If anything it should be re-written
if(isset($_REQUEST['s']))
{
switch($_REQUEST['s'])
{
case "m":
echo "Success fully deleted.";
break;
case "e":
echo "Success fully update.";
break;
}
}
This code checks if "s" has been passed either as $_POST or $_GET variable, if it was s=m then display message, that entity was successfully deleted, if e, it was successfully updated.
In general, try using more verbose names of variables, and avoid $_REQUEST due to security implications
$_REQUEST['s']
----> This will get the submit button name <input type="submit" name="s" value="m" />
m and e is the value of submit button
<?php
if(isset($_REQUEST['s'])) // to check if button is pressed or not
{ if($_REQUEST['s']=="m") //if m button is clicked
{
//code for delete
echo "Success fully deleted.";
}}
if(isset($_REQUEST['s']))
{ if($_REQUEST['s']=="e") // if e button is clicked
{
//code for update into db
echo "Success fully update.";
}}
?>
if(isset($_REQUEST['s'])) { // If a Requst "s" exists eq index.php?s=hello if($_REQUEST['s']=="m") { // Now lets see what value the Request "s" has IF s=="m" echo "Success fully deleted."; // Output because s has the Value "m" } }
Fort better understanding just try this
if(isset($_REQUEST['s'])) { if($_REQUEST['s']=="m") { // Now lets see what value the Request "s" has IF s=="m" echo "Success fully deleted."; // Output because s has the Value "m" } else { echo "s is not equal 'm': s has the value ".$_REQUEST['s']; } } else { echo "i need the Request s to do something"; echo "<pre>Requests i got: ".print_r($_REQUEST,1)."</pre>"; }
Now try it by:
yourscript.php?s=m
yourscript.php?s=hello
yourscript.php