Like in the title I would like to use a variable inside the hyperlink to use it into the modal window.
I am not using bootstrap, it is a custom code but it works until I try to put some kind of <a href='#openModal?id=".$VARIABLE."'>
Is it possible to do that?
Regards
Update:
<?php
$query = "SELECT * FROM USER";
$result = mysqli_query ($connection,$query)
or die ("You couldn’t execute query");
echo "<div class='admin-table'>
<table cellspacing='15'>
<td><h3>Last Name</h3></td>
<td><h3>Name</h3></td>
<td><h3>Phone</h3></td>
<td><h3>Address</h3></td>
<td><h3>Postcode</h3></td>
<td><h3>Date of Birth</h3></td>
<td><h3>Email</h3></td>
<td><h3>Password</h3></td>
<td><h3>Role</h3></td>
</tr>";
while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC))
{
extract ($row);
echo "<tr>\n
<td>$USER_LASTNAME</td>\n
<td>$USER_FIRTSNAME</td>\n
<td>$USER_PHONE</td>\n
<td>$USER_ADDRESS</td>\n
<td>$USER_POSTCODE</td>\n
<td>$USER_DOB</td>\n
<td>$USER_EMAIL</td>\n
<td>$USER_PASSWORD</td>\n
<td>$USER_ROLE</td>\n
<td><a href='admin_user.php?id=".$USER_ID."'>Delete</a></td>\n
<td><a href='#openModal?id=".$USER_ID."'>Edit</a></td>\n
</tr>\n";
echo "<tr><td colspan ='15'><hr></td></tr>\n";
}
echo "</table></div>\n";
?>
<div id="openModal?id=<?php echo $USER_ID; ?>" class="modalDialog">
<div>X
<h2>$USER_ID</h2>
</div>
</div>
It is working the modal but its just taking the last id, I have to think another solution to pass the variable.
Many thanks for your help
Update 2:
Thank you very much! Now its working,
<?php
$query = "SELECT * FROM USER;";
$result = mysqli_query ($connection,$query) or die ("You couldn’t execute query");
//First echo the table with all your data as you want
echo "
<div class='admin-table'>
<table cellspacing='15'>
<tr>
<td><h3>Last Name</h3></td>
<td><h3>Name</h3></td>
<td><h3>Phone</h3></td>
<td><h3>Address</h3></td>
<td><h3>Postcode</h3></td>
<td><h3>Date of Birth</h3></td>
<td><h3>Email</h3></td>
<td><h3>Password</h3></td>
<td><h3>Role</h3></td>
</tr>";
//Fetch all rows for each user
while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {
extract ($row);
echo "
<tr>
<td>$USER_LASTNAME</td>
<td>$USER_FIRTSNAME</td>
<td>$USER_PHONE</td>
<td>$USER_ADDRESS</td>
<td>$USER_POSTCODE</td>
<td>$USER_DOB</td>
<td>$USER_EMAIL</td>
<td>$USER_PASSWORD</td>
<td>$USER_ROLE</td>
<td><a href='admin_user.php?id=".$USER_ID."'>Delete</a></td>
<td><a href='#openModal?id=".$USER_ID."'>Edit</a></td>
<div id='openModal?id=".$USER_ID."' class='modalDialog'>
<div><a href='#close' title='Close' class='close'>X</a>
<h2>".$USER_ID."</h2>
<p>You can have additional details here.</p>
</div>
</div>
</tr>
<tr>
<td colspan ='15'><hr></td>
</tr>";
}
echo"
</table>
</div>";
?>
Try this:
echo '<a href="#openModal?id='.$VARIABLE.'">';
Update:
echo '<td>Edit</td>\n';
echo '<td>Delete</td>\n';
any reason you can't use onclick ?
<a href="#" onclick="myJsFunc();">
<script>
function myJsFunc() {
//code to open modal
}
</script>
UPDATE
If i have understood you correct you are trying to make a table showing all users and then when the admin clicks at element a modal pop ups providing additional info for the particular user.
<?php
$query = "SELECT * FROM USER;";
$result = mysqli_query ($connection,$query) or die ("You couldn’t execute query");
//First echo the table with all your data as you want
echo "
<div class='admin-table'>
<table cellspacing='15'>
<tr>
<td><h3>Last Name</h3></td>
<td><h3>Name</h3></td>
<td><h3>Phone</h3></td>
<td><h3>Address</h3></td>
<td><h3>Postcode</h3></td>
<td><h3>Date of Birth</h3></td>
<td><h3>Email</h3></td>
<td><h3>Password</h3></td>
<td><h3>Role</h3></td>
</tr>";
//Fetch all rows for each user
while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {
extract ($row);
echo "
<tr>
<td>$USER_LASTNAME</td>
<td>$USER_FIRTSNAME</td>
<td>$USER_PHONE</td>
<td>$USER_ADDRESS</td>
<td>$USER_POSTCODE</td>
<td>$USER_DOB</td>
<td>$USER_EMAIL</td>
<td>$USER_PASSWORD</td>
<td>$USER_ROLE</td>
<td><a href='admin_user.php?id=".$USER_ID."'>Delete</a></td>
<td><a href='#openModal".$USER_ID."'>Edit</a></td>
</tr>
<tr>
<td colspan ='15'><hr></td>
</tr>";
}
echo"
</table>
</div>";
//Fetch again the rows to make the modals with the edit info
while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {
extract ($row);
echo '
<div id="openModal'.$USER_ID.'" class="modalDialog">
<div>X
<h2>'.$USER_ID.'</h2>
<p>You can have additional details here.</p>
</div>
</div>';
}
?>
Old answer before the comments
It seems that single quotes and/or double quotes aren't escaped properly.
Also remember that in PHP string concatenation is made using " . " (dot) and in JavaScript using " + " (plus).
Update 1
I think that if you use the following you will be ok.
echo '<td>Delete</td>';
echo '<td>Edit</td>';
Update 2
Don't forget to add $variable at div too so <a> and div id are the same the same. E.g.
echo '<div id="openModal'.$variable.'" class="modalDialog"></div>';
Related
I have a somefile.php and someotherfile.js with the code as below
javascript file
function deleteSelectedRow() {
return (confirm('Are you sure you want to delete this record))
};
<!DOCTYPE html>
<html lang=" en">
<head>
<title> Title </title>
</head>
<body>
<h1>Select the user to delete from the list below </h1>
<form action="" method="POST">
<?php
if(require_once('../SQL/mySQL_connect.php'))
{
$query = "SELECT id, FirstName, LastName, PhoneNumber FROM participants ORDER BY id ASC";
$userDetails = #mysqli_query($mysqli, $query);
}
else
{
echo "Couldn't connect to database";
echo mysqli_error($mysqli);
}
// mysqli_close($mysqli);
?>
<br><br><br>
<table name="userDetailsTable" id="userDetailsTable" align="left" cellspacing="7" cellpadding="8">
<tr>
<td align="center"><b>S No</b></td>
<td align="center"><b>Id</b></td>
<td align="center"><b>Rank</b></td>
<td align="center"><b>First Name</b></td>
<td align="center"><b>Last Name</b></td>
</tr>
<?php
for($i = 1; $i <= mysqli_num_rows($userDetails); $i++)
// while($row=mysqli_fetch_array($userDetails))
{
$row=mysqli_fetch_array($userDetails);
echo '<tr>
<td align ="center" >'. $i .'</td>
<td align ="center" >' . $row['id'] . '</td>
<td align ="center">' . $row['Rank'] . '</td>
<td align ="center">' . $row['FirstName'] . '</td>
<td align ="center">' . $row['LastName'] . '</td>
<td align ="center"> <input type = submit name="delete" value="delete" onclick="return deleteSelectedRow();" ></input></td>';
echo '</tr>';
}
?>
</table>
</form>
<?php
if(isset($_POST['delete']))
{
require_once('../SQL/mySQL_connect.php');
$query="DELETE FROM `participants` WHERE `participants`.`id` = ".$_POST['IDNumber']."";
$response = #mysqli_query($mysqli, $query);
if($response)
{
echo "Deleted from Database Successfully";
}
else
{
echo "Couldn't Delete from database";
echo'<br>';
echo mysqli_error($mysqli);
}
mysqli_close($mysqli);
}
?>
</body>
What this code does is as follows
Connects to database and retrieves the user details
Creates a table and prints out the user details in it
user clicks on delete button in front of any record and it gets deleted after confirmation
A success message is displayed that the message is deleted
What I want to do is that after displaying the success message the above printed table should get updated automatically so that user is confirmed that the id no longer exists in the table
I tried the following solutions
reload page just before the success message is displayed so that user sees the success message as well as the updated table as well (since reload will re-connect to database and refetch the table)
I tried to use "location.reload(true)" command but i can't figure out where to place this line so that it gets executed just before the success message is displayed.
Any help is much appreciated
A few things:
you'll want the delete operation to be the first thing you do on the page (if it's a form submit) because otherwise you'll print the "pre-deleted" table.
you need to pass the ID through post in the form. It's easier if you just have a unique for for every row, and have a hidden ID input for each.
The confirm is better attached to the form submit event, because otherwise you'll miss other, non-click, input methods.
Your delete operation, as it was written in the question, is susceptible to an SQL Injection attack. You'll want to escape that POST value.
Something like the below should work
function deleteSelectedRow() {
return (confirm('Are you sure you want to delete this record))
};
<?php
$message = '';
$connected = false;
if(require_once('../SQL/mySQL_connect.php'))
{
$connected = true;
}
if($connected && isset($_POST['delete']))
{
$id_to_delete = mysqli_real_escape_string($mysqli, $_POST['IDNumber']);//escape value to prevent sql injection attack
$query="DELETE FROM `participants` WHERE `participants`.`id` = ".$id_to_delete."";
$response = #mysqli_query($mysqli, $query);
if($response)
{
$message = "Deleted from Database Successfully";
}
else
{
$message = "Couldn't Delete from database";
$message .='<br>';
$message .= mysqli_error($mysqli);
}
//mysqli_close($mysqli);
}else{
$message = "unable to connect to database";
}
?><!DOCTYPE html>
<html lang=" en">
<head>
<title> Title </title>
</head>
<body>
<h1>Select the user to delete from the list below </h1>
<?php
if($connected)
{
$query = "SELECT id, FirstName, LastName, PhoneNumber FROM participants ORDER BY id ASC";
$userDetails = #mysqli_query($mysqli, $query);
}
else
{
echo "Couldn't connect to database";
echo mysqli_error($mysqli);
}
?>
<br><br><br>
<?php if($message){ /* do we have a success/error message from the delete operation? */ ?>
<p><?php echo $message; ?></p>
<?php } ?>
<table name="userDetailsTable" id="userDetailsTable" align="left" cellspacing="7" cellpadding="8">
<tr>
<td align="center"><b>S No</b></td>
<td align="center"><b>Id</b></td>
<td align="center"><b>Rank</b></td>
<td align="center"><b>First Name</b></td>
<td align="center"><b>Last Name</b></td>
</tr>
<?php
for($i = 1; $i <= mysqli_num_rows($userDetails); $i++)
// while($row=mysqli_fetch_array($userDetails))
{
$row=mysqli_fetch_array($userDetails);
echo '<tr>
<td align ="center" >'. $i .'</td>
<td align ="center" >' . $row['id'] . '</td>
<td align ="center">' . $row['Rank'] . '</td>
<td align ="center">' . $row['FirstName'] . '</td>
<td align ="center">' . $row['LastName'] . '</td>
<td align ="center"> <form action="" method="POST" onsubmit="return deleteSelectedRow();"><input type="hidden" name="IDNumber" value="'.$row['id'].'" /><input type = submit name="delete" value="delete"></form></td>';
echo '</tr>';
}
?>
</table>
<?php if($connected){
mysqli_close($mysqli);
} ?>
</body>
You need to store the Success/Error message in a $_SESSION["flash"] instead of show by echo and after delete the user you must redirect to the same page.
On the top of the page, if isset the $_SESSION["flash"] you can show the message and remove it from the session. In code:
if(isset($_POST['delete']))
{
require_once('../SQL/mySQL_connect.php');
$query="DELETE FROM `participants` WHERE `participants`.`id` = ".$_POST['IDNumber']."";
$response = #mysqli_query($mysqli, $query);
if($response)
{
$_SESSION["flash"] = "Deleted from Database Successfully";
}
else
{
$_SESSION["flash"] = "Couldn't Delete from database";
//echo'<br>';
//echo mysqli_error($mysqli);
}
mysqli_close($mysqli);
header('Location: '.$_SERVER['PHP_SELF']);
}
and on the top of the page of before isset($_POST['delete']):
if(isset($_SESSION["flash"])){
echo $_SESSION["flash"];
unset($_SESSION["flash"]);
}
don't forget to start_session() on the top of the page.
I'll notice that your code have a SQL Injection Vulnerability. You shouldn't do MySQL queries without validate GET and POST input data.
I have problems with my php that generates a table, requests data from a SQL database, and stores data in the table.
The first cell of each row in the table contains a dropdown button which links to a delete.php script that deletes the row. It also links to a modif.php script used to modify the row's cells.
My problem is that i need to access the dropdown buttons with IDs to know which row to delete.
And i don't really know how to link my dropdown buttons with IDs and access them in my scripts.
Here's the code :
<?php
$con=mysqli_connect("localhost","root","icare","icare1");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM magasin");
echo "<table border='1'>
<tr>
<th>code</th>
<th>ip</th>
<th>ads</th>
<th>region</th>
<th>adress</th>
<th>name</th>
<th>email</th>
<th>number</th>
<th>gtc</th>
<th>date</th>
</tr>";
$indexB = array();
$i = 0;
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>
<div class='dropdown'>
<button id=$indexB[$i] class='dropbtn'>▶</button>
<div class='dropdown-content'>
<a href='modif.php'>Modifier</a>
<a href='delete.php'>Supprimer</a>
</div>
".$row['code']."
</div>
</td>";
echo "<td><div>" . $row['ip'] . "</div></td>";
echo "<td><div>" . $row['ads'] . "</div></td>";
echo "<td><div>" . $row['region'] . "</div></td>";
echo "<td><div>" . $row['adress'] . "</div></td>";
echo "<td><div>" . $row['name'] . "</div></td>";
echo "<td><div>" . $row['email'] . "</div></td>";
echo "<td><div>" . $row['number'] . "</div></td>";
echo "<td><div>" . $row['gtc'] . "</div></td>";
echo "<td><div>" . $row['date'] . "</td>";
echo "</tr>";
$i++;
}
echo "</table>";
mysqli_close($con);
?>
And here is the delete.php :
<?php
$connection = mysqli_connect("localhost", "root", "icare", "icare1");
if($connection === false){
die("Connection failed " . mysqli_connect_error());
};
//$id =
$sql = "DELETE FROM magasin WHERE Code=".$id;
//$result = mysqli_query($connection,$sql);
if(mysqli_query($connection, $sql)){
echo "Done !";
} else{
echo "Failed : $sql. " . mysqli_error($connection);
}
mysqli_close($connection);
?>
I started an indexB[] to store the dropdowns IDs but i'm not sure that i'm doing it right.
In the end I want to link my buttons to the code attribute and then delete the row with my sql query using the code attribute.
I'm new to this so ... sorry if i did or ask something plain stupid.
UPDATE :
To mikrafizik :
I tried your answer but it doesn't work. I only get "1">Supprimer". It seemsi have a problem with the href but i just can't find why.
I don't know what i forgot, so if you see something wrong :
<?php
$con=mysqli_connect("localhost","root","icare","icare1");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM magasin");
echo "<table border='1'>
<tr>
<th>Code</th>
<th>Adresse IP</th>
<th>Adresse ADS</th>
<th>Région</th>
<th>Adresse</th>
<th>Nom du directeur</th>
<th>Mail</th>
<th>Téléphone</th>
<th>GTC</th>
<th>Date d'installation</th>
</tr>";
$data = mysqli_fetch_array($result);
?>
<table>
<?php foreach ($data as $key => $row):?>
<tr>
<td>
<div class='dropdown-content'>
<button class='dropbtn'>▶</button>
<!-- Modifier -->
Supprimer
</div>
</td>
<td><div><?php echo $row['AdresseIP'];?></div></td>
<td><div><?php echo $row['AdresseADS'];?></div></td>
<td><div><?php echo $row['Region'];?></div></td>
<td><div><?php echo $row['Adresse'];?></div></td>
<td><div><?php echo $row['NomDirecteur'];?></div></td>
<td><div><?php echo $row['Mail'];?></div></td>
<td><div><?php echo $row['Tel'];?></div></td>
<td><div><?php echo $row['Gtc'];?></div></td>
<td><div><?php echo $row['DateInstall'];?></td>
</tr>
<?php endforeach; ?>
</table>
<?mysqli_close($con);?>
delete.php :
<?php
$connection = mysqli_connect("localhost", "root", "icare", "icare1");
if($connection === false){
die("Connexion échouée " . mysqli_connect_error());
};
$id = $_GET['id'];
$sql = "DELETE FROM magasin WHERE Code=".$id;
$result = mysqli_query($connection,$sql);
if($result){
echo "Enregistrement réussi !";
} else{
echo "Enregistrement échoué : $sql. " . mysqli_error($connection);
}
mysqli_close($connection);
?>
At first, divide query and form building like that
$data = mysqli_fetch_array($result)
then
<?php foreach ($data as $key => $row): ?>
<tr>
<td>
<div class='dropdown-content'>
<a href='modif.php?id=<?=$row['id']?>'>Modifier</a>
<a href='delete.php?id=<?=$row['id']?>'>Supprimer</a>
</div>
</td>
</tr>
<?php endforeach ?>
And in your modif.php
$id = $_GET['id'];
(Concerns Flumble_'s answer, that I can't comment because of my low rep)
Maybe the <?= ?> are the problem. Try replacing them with <?php ?>
UPDATE :
You should also never use short open tags (<? ?>) : See the answer to this question.
Also, when you write <?php $row['id'] ?>, you are not printing the value. You must write <?php echo $row['id']; ?>.
The same thing applies with short open tags (but not with the <?= syntax).
Hope this helps further. I will continue reviewing your code.
UPDATE 2 :
Alright I think I got it.
mysqli_fetch_array returns a row, not the entire result set. So you have to loop through the rows until mysqli_fetch_array returns NULL :
while($data = mysqli_fetch_array($result)) {
?>
<tr>
<!-- ... -->
</tr>
<?php
}
I built a form where user can enter Country Name and Country's Dialing Code. That form submits to Database and then I pull the record from database in a Table showing Country Name, Country's Dialing Code and two more options of EDIT and DELETE (having GET URL Link e.g. www.abc.com/country.php?country=Pakistan)
I want to add AJAX to it so that when user clicks on EDIT or DELETE link a relevant pop-up open with data from GET URL.
Following is my Dynamic Table in PHP
<div>
<?php
$q = "SELECT * FROM country";
$result = mysqli_query($conn, $q);
echo "<table border=2><tr><th>Country Name</th><th>Country Code</th><th></th><th></th></tr>";
while($a = mysqli_fetch_array($result)) {
$cn = $a['cname'];
$cc = $a['ccode'];
?>
<tr>
<td><?php echo $cn ?></td> <td><?php echo $cc; ?></td>
<script type="text/javascript">
var a = 0;
var cname = new Array("<?php echo $cn;?>");
a++;
</script>
<td>
<a href='#' onclick='javascript:editWin(cname[a]); return(false);'>Edit</a>
</td>
<td id="<?php echo $cn;?>">
<a href='#' onclick='javascript:delWin(); return(false);'>Remove</a>
</td>
</tr>
<?php
}
?>
</div>
My external Javascript Function is as follows
function editWin(e) {
window.open('edit.php?country='+e,'','height=400, width=600, top=100,
left=400, scrollable=no, menubar=no', '');
};
In GET Url it says undefined when popup window opens.
I got the solution
My PHP Code is as follows
<div> <?php
$q = "SELECT * FROM country";
$result = mysqli_query($conn, $q);
echo "<table border=2><tr><th>Country Name</th><th>Country Code</th><th></th><th></th></tr>";
while($a = mysqli_fetch_array($result)) {
$cn = $a['cname'];
$cc = $a['ccode'];
?>
<tr>
<td><?php echo $cn ?></td> <td><?php echo $cc; ?></td>
<td><a href='#' id="<?php echo $cn; ?>" onclick='javascript:editWin(this.id); return(false);'>Edit</a></td>
<td><a href='#' id="<?php echo $cn; ?>" onclick='javascript:delWin(this.id); return(false);'>Remove</a></td></tr>
<?php
}
?>
</div>
and my Javascript is as follows
function editWin(e) {
window.open('edit.php?country='+e,'','height=400, width=600, top=100, left=400, scrollable=no, menubar=no', '');
};
function delWin(e) {
window.open('del.php?country='+e,'','height=400, width=600, top=100, left=400, scrollable=no, menubar=no', '');
};
at the moment i've coded out like
<div class="row">
<div class="col-lg-12">
<table id="usertable" class="table table-bordered table-hover text-center">
<thead>
<th class="col-lg-1 text-center">User ID</th>
<th class="col-lg-4 text-center">Username</th>
<th class="col-lg-4 text-center">Password</th>
<th class="col-lg-2 text-center">Role</th>
</thead>
<tbody>
<?php
require('dbconnectmssql.php');
$sql = "select [User_ID],[user_decoded],[pass_decoded],[permission] from [rfttest].[dbo].[users]";
$query = sqlsrv_query ($conn , $sql);
if($query === false)
{die( print_r( sqlsrv_errors(), true));}
while($row = sqlsrv_fetch_array( $query, SQLSRV_FETCH_NUMERIC))
{
echo "<tr>";
foreach($row as $x => $a)
{
echo "<td>".$a."</td>";
}
echo "<td>";
echo "<a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>";
echo "<a href='usercontrol.php?del=$row[0]'>";
echo "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>";
echo "</a>";
echo "</td>";
echo "</tr>";
}
?>
</tbody>
/table>
</div>
</div>
it's all about query out and show how many user in the table.
I've done the delete-record by link to PHP file and $_GET data (maybe improve later if have another solution that you will suggest )
Another things that i want to do is
Edit specific record without redirected to another page
My idea for right now is hidden form that popup after click edit such as i've click then form pop up with data record that stored and user can edit it and save it by submit to PHP file and then redirect back to this page
something like : Contain form within a bootstrap popover? post
the popover link
<div id="popover-head" class="hide">
some title
</div>
<div id="popover-content" class="hide">
<!-- MyForm -->
</div>
but i still can't figured out
How can i code out to make the link to open the specific popover-head/content maybe popover-head/content must be contain in id or something ?
What about PHP
What about JS/JQ also
Any solution what i just want only something to edit specific record that echo out
Sorry for my bad English
Thanks
You likely want to use AJAX for this.
This looks so painful to me - and if it worked a google spidering would delete all users on the page:
}
echo "<td>";
echo "<a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>";
echo "<a href='usercontrol.php?del=$row[0]'>";
echo "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>";
echo "</a>";
echo "</td>";
echo "</tr>";
}
It could be written
} ?>
<td>
<a href='#' ><span class='glyphicon glyphicon-wrench' aria-hidden='true'></span></a>
<a class="del" href='#' data-userid='<?PHP echo row["User_ID"]; ?>'>
<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>
</a>
</td>
</tr>
<?PHP } ?>
And then
$(function() {
$(".del").on("click",function(e) {
e.preventDefault(); stop the page from reloading
var id=$(this).data("userid");
$.get("usercontrol.php?del="+id,function() {
alert(id + "deleted");
});
});
});
To edit
Popup a form with the data using .show() and .hide()
change the data
AJAX the changes on submit - be sure to use preventDefault to
stop actual submission $("form").on("submit",function(e) { e.preventDefault(); $.post("save.php",$(this).serialize(),function(data) { alert("saved"); $("#formDiv").hide() });});
show the result
close the popup
I am a newbie trying to delete a profile but this message pops up in address bar
http://thexyz.com/the/delete.php?id=1>
Am I making any syntax mistake my code is as below-
<?php
$i=1;
while($row=mysql_fetch_array($rw)) { ?>
<tr>
<td><?php echo $i; ?></td>
<td align="center">
<a href="delete.php?id=<?php echo $row['Customer Id']; ?> "onclick="return chkstatus();">
<img src="resources/images/icons/user_delete.png" width="16" height="16"/></a>delete
</td>
Even delete is not working
My delete.php code is
<?php
session_start();
if($_SESSION['username']=="");
include_once('db.php');
if( isset($_GET['del']) ) {
$id = $_GET['del'];
$sql= "DELETE FROM opd WHERE Sno='$Sno'";
$res= mysql_query($sql) or die("Failed".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
}
?>
You have to remove the > after ?>
Your <a href should look like this:
<a href="delete.php?id=<?php echo
$row['Customer Id']; ?>" onclick="return chkstatus();">
In your delete.php
if($_SESSION['username']==""); // IT will do nothing here
above code will not do anything because your have terminated statement with semicolon ;
You are passing id not del.
so $_GET['del'] should be changed as $_GET['id']
$sql= "DELETE FROM opd WHERE Sno='$Sno'";
changed to
$sql= "DELETE FROM opd WHERE Sno='$id'";