I'm trying to delete a record in mysql using php. What do I have to add in my code so that there will be a delete confirmation first. Because in my current code, it automatically deletes the record corresponding to the pnum inputted.
<html>
<style>
input { font-size: 16px;}
</style>
<?php include('header.php'); ?>
<div id="main_content">
</div>
<?php include('footer.php'); ?>
<head>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="DeletebyPnumIn.php" method="post">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="9" style="background:#9ACD32; color:white; border:white 1px solid; text-align: center"><strong><font size="3">Delete In-patient</strong></td>
</tr>
<td><font size="3">Patient #:</td>
<td></td>
<td><input type="text" name="pnum" value="" maxlength="15" /><br/></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Delete" /></td>
</form>
</tr>
</table>
<body>
</body>
</html>
Here is the form action:
<html>
<style>
input { font-size: 16px;}
</style>
<?php include('header.php'); ?>
<div id="main_content">
</div>
<?php include('footer.php'); ?>
<head>
<?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hospital", $con);
mysql_query("DELETE FROM t2 WHERE PNUM='{$_POST["pnum"]}'") ;
mysql_close($con);
echo "<script>alert('Record successfully deleted!')</script>";
?>
Please help.
There are numerous ways to provide delete confirmation, ranging from simple and haphazard to complex and robust. The simplest approach is probably a Javascript confirmation dialog. To implement this, you'll want to add the functionality on the page where they click "Delete", not on the PHP side.
For instance:
Delete
By the way, watch out for SQL injection. You need to sanitize your inputs before dropping POST or GET data into an SQL string.
The simplest way, given your current code would be just to add an onsubmit action to your form.
<form action="DeletebyPnumIn.php" method="post" onsubmit="return confirm('Really Delete?');">
or something similar.
A JavaScript Confirm box should do the trick!
http://www.tizag.com/javascriptT/javascriptconfirm.php
You could also do it in pure PHP using another page... but that's likely to annoy your users...
You could simply use onsubmit="return confirmationMessage()" for the <form>. Of course this only works if JavaScript is enabled. The confirmationMessage should ask the user whether to delete or not, and return true if so, false if not.
Related
I am having an issue on designing a web page. I want to display a POST variable inside of an HTML table.
Here is the form code from the first page:
<form action="buy.php" method="post">
<input type="text" name="uid" />
<input type="submit" value="Buy Now" />
</form>
This code works fine if I am displaying the POST variable on a normal blank PHP file.
But when I go to use it in an html table it just won't display.
Here is the table code:
<td id="bal"><?php echo $_POST['uid']; ?></td>
<td id="amt">test1</td>
<td id="type">test2</td>
The first tabledata just appears blank.
Can anyone help me fix this?
Here is the entire code in the buy.php file: http://pastebin.com/ffWAP92C
(was having trouble posting it in here )
This is what the problem looks like:
Change this <td id="bal"> <?php echo "$_POST['uid'];" ?> </td> to <td id="bal"> <?php echo $_POST['uid']; ?> </td>
Try this one,
<html>
<head>
<title></title>
<style type="text/css">
</style>
</head>
<body>
<center><h1>Purchase Account ID</h1></center>
<table border="1" style="width:100%;">
<tr>
<td><b>Account ID</b></td>
<td><b>Account Type</b></td>
<td><b>Account Price</b></td>
</tr>
<tr>
<td id="bal">
<?php
if(isset($_POST['uid']))
echo $_POST['uid'];
else
echo "Nothing";
?>
</td>
<td id="amt">test1</td>
<td id="type">test2</td>
</tr>
</table>
</body>
</html>
Hope this works.
Remove " signs inside php tag. i.e. replace
<td id="bal"> <?php echo "$_POST['uid'];" ?> </td>
with
<td id="bal"> <?php echo $_POST['uid']; ?> </td>
OR insert semicolon after " sign. i.e.
<td id="bal"> <?php echo "$_POST['uid']"; ?> </td>
you can copy past below code in a test.php file. i have updated code. It is working in my localhost.
<html>
<head>
<title></title>
<style type="text/css">
</style>
</head>
<center><h1>Purchase Account ID</h1></center>
<body>
<table border="1" style="width:100%;">
<tr>
<td><b>Account ID</b></td>
<td><b>Account Type</b></td>
<td><b>Account Price</b></td>
</tr>
<tr>
<td id="bal"> <?php if(isset($_POST['uid'])) echo $_POST['uid']; ?> </td>
<td id="amt">test1</td>
<td id="type">test2</td>
</tr>
</table>
</body>
<form action="test.php" method="post">
<input type="text" name="uid" />
<input type="submit" value="Buy Now" />
</form>
</html>
I have the following piece of code and wish to display it as text in a webpage. How can I do it? I wat the code mentioned below to be displayed as text in a webpage. The page might be either a .html page or a .php page. Kindly help.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Log in!</title>
<style type="text/css">
div {
width:300px;
height:120px;
margin: 0px auto;
margin-top: 100px;
padding: 30px 20px;
border:2px solid #00F;
background-color:#0CF;
border-radius:10px;
}
span{
margin:0px auto;
color:#F00;
font-family:Verdana, Geneva, sans-serif;
font-size:12px;
}
</style>
</head>
<body>
</body>
<?php
require_once('conn.php');
$sql="select * from contacts where contacts_id=14";
$result=$mysqli->query($sql);
$row=$result->fetch_array();
if( isset($_POST['id']) && $row['email']==$_POST['id'] && $_POST['password']==$row['password'])
{
header("location:view.php") ;
$_SESSION['sid']= $row['email'];
$flag=1;
}
?>
<div>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table align="center" border="0">
<tr>
<td>Id</td>
<td>:</td>
<td><input type="text" name="id" placeholder="Email" /></td>
</tr>
<tr>
<td>Password</td>
<td>&:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td></td>
<td colspan="2"><input type="submit" value="Log In!" /></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['id']) && isset($_POST['password']) && $flag==0)
{
echo "<center><span>Invalid Id/Password</span></center>";
}
?>
</div>
</body>
</html>
You can also use highlight_string()
function
<?php
highlight_string("YOUR STRING/CODE GOES HERE");
?>
$gen_query_data= htmlspecialchars(' $'.$db_val_clean.'_ser = $_POST["'.$sel_name_clean.'_ser"];')."<br>";
echo $gen_query_data;
please change your variables
if your server isn't set up to process .html for the php tag, you're fine to do exactly what you've done.
You can also use this: <?php which would render as <?php but not be seen by PHP.
One option you can use is PHP's highlight_file() function:
<?php
highlight_file("your_file.php");
?>
You can also use .html file extensions highlight_file("your_file.html").
Even a .txt file extension highlight_file("your_file.txt").
Consult:
http://php.net/manual/en/function.highlight-file.php
this question is pretty old , but as long as no one used this solution so this would be helpful .
using htmlspecialchars :
htmlspecialchars — Convert special characters to HTML entities
echo htmlspecialchars("your special character goes here");
I found a strange behaviour in my css style. I created a login page that can be accessed from a link wihtin home page. If I access login page from a link within home page or login page itself, everything looks fine. But, whenever I refresh login page, the header looks weird. And all of this happen only if <form> element is exists, without <form> element, there's no problem.
So, what causes this to happen? And how do I fix this?
Note: Everything after this is only attachment for my question details.
The login file page written like this:
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/config/core.php'); ?>
<html>
<?php include_once($root.'/includes/head.php');?>
<body>
<div id="wrapper">
<?php include_once($root.'/includes/header.php');?>
<?php include_once($root.'/includes/navigation.php');?>
<section>
<article>
<h2>Login</h2>
<form action="<?php echo $current_file;?>" method="post">
<table align="center" border="0" cellpadding="0" cellspacing="15">
<tr>
<td width="100">Username</td>
<td>:</td>
<td><input type="text" name="username" maxlength="50" size="35"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="password" maxlength="50" size="35"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" value=" Login "><input type="submit" value=" Reset "></td>
</tr>
</table>
</form>
</article>
</section>
<?php include_once($root.'/includes/news.php');?>
<?php include_once($root.'/includes/footer.php');?>
</div>
</body>
</html>
The header.php file that I included written like this:
<header>
<div id="logo">
<img src="/images/arh.png" />
<h1>The Header</h1>
</div>
</header>
And, the css file for header element is written like this:
header {
background-color: #000; height: 120px;
}
#logo {
float: left;
}
#logo img {
height: 100px; padding: 10px;
}
#logo h1 {
color: #ccc; float: right; font-size: 36px; padding: 30px;
}
The result if i access login.php page from link:
And, if i refresh the page:
i had pretty much that same problem. Matewka is right.
there was a small error in my html on my header. i had my div in the middle of my table.
What i had
<div>
<table>
<tr>
<td>
</td>
</tr>
</div>
</table>
what i changed it to
<div>
<table>
<tr>
<td>
</td>
</tr>
</table>
</div>
I just moved my div to the end of my table. I don't know how i did this, but being up for a few days or staring at the same thing over and over you start missing things. I would double check the html, it might be that simple. (are you using height % ?) do you have borders?
I understand that the question is little bit vague. Still I am tempted to ask this. I will give one working example and would like to know, how I can use this in my project. There is a site called http://erail.in .In this, if I want to get the details of a train or PNR, just enter in the form and submit. This (I assume) opens the train or PNR search page of Indian Railways (probably in the background) and get details pertaining to the value given by me and display the result in the page in which I am.
Similar way I have a form in my page which has one input box for entering TLD No.
<html>
<head>
<title>Untitled Document</title>
<link href="/DatePicker.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.5.1.js"></script>
</head>
<body>
<form>
TLD No.<input type="text" id="tip"/>
<input type="submit" id="submit" value="Get" />
</form>
</body>
</html>
Upon submitting this form , I need a jQuery script which opens another search page in another server and submit the form in that page get the result from that page to my script. The search page in that server is like this:
<html>
<head>
<title>INDIVIDUAL ALL REPORT</title>
<base target="_self">
</head>
<body >
<form method="POST" name="form1" action="../dbms/allindvres.asp" target="I1">
<table border="0" cellpadding="0" cellspacing="0" style="BORDER-COLLAPSE: collapse" bordercolor="#669999" width="100%" id="AutoNumber1" >
<tr>
<th width="100%" colspan="4" style="BACKGROUND-COLOR: #cc6600; COLOR: #ffffff; FONT-WEIGHT: bold; TEXT-TRANSFORM: uppercase">individual data in one click</th>
</tr>
<tr>
<td width="33%" height="22" align="middle" ><font size=4>TLD No <input name="TLDNO" size="10"></td>
<td width="33%" height="22" align="middle" ><font size=4>CC No <input name="CCNO" size="10"></td>
<td width="33%" height="22" align="middle"><font size=4>or Name <input name="name" size="30"></td>
<td width="33%" height="22" align="middle">
<p align="center"><input type="submit" value="Get Life Dose" name="B1"></p>
</td>
</tr>
</table>
</form>
<iframe name="I1" width="100%" height="500" src="../DBMS/allindvres.asp" marginwidth="10" marginheight="5">
Your browser does not support inline frames or is currently configured not to display inline frames.</iframe></p></p>
</body>
</html>
Once the form is submitted, the result is displayed in the iframe above. The resulting html will look like this
<html>
<head>
<body>
<h3 align = 'center'><font color="red">
OTHER STATION
</h3>
<table border="2" align = 'center' cellpadding="0" style="border-collapse: collapse" width="80%" id="AutoNumber2">
<tr>
<TD WIDTH = 85% align = 'left' colspan='3'>
<table border="0" align = 'center' cellpadding="0" width =100%>
<tr>
<td>CC NO:</td>
<td>xxx</td>
<Td>SECTION: </td>
<td>xxx</td>
</tr>
<tr>
<td>NAME: </td>
<td>XXXX </td>
<Td>CATEGORY: </td>
<td>XX</td>
</tr>
<tr>
<td>FATHER'S NAME:</td>
<td>XXXX</td>
<Td>EMP NO: </td>
<td>XXXXX</td>
</tr>
<tr>
<td>BIRTH PLACE </td>
<td>XXXXX</td>
<td>CC NO:</td>
<td>XXXX</td>
</tr>
<tr>
<td>STATE</td>
<td>XXXXX</td>
<td>DATE OF BIRTH</td>
<td>3thMay1968</td>
</tr>
<tr>
<td>QUALIFICATION: </td>
<td>XXXX</td>
<td>DESIGNATION: </td>
<td>XXXX</td>
</tr>
</table>
</body>
</html>
I want to get values in second of second from the above table and display it in my page. How can I accomplish this?
If I am using the action="http://anotherserver/dbms/allindvres.asp" in the form above, After submitting I can get the result in an I frame in my page. But I do not want to use the default form submit method which refreshes the page. That is why I use jQuery. Any work around?
This is my code, I'm trying to get data inside #download div and submit it to other file test2.php
Don't worry it is just table inside #download
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<form action="test2.php" method="post">
<textarea style="" id="file" name="file"></textarea>
<input type="submit">
</form>
<script>
$(document).ready(function(e) {
var html=$('#download').html();
$('#file').val(html);
});
</script>
<div id="download">
<div id="content">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="7" id="info"></td>
</tr>
<tr>
<td colspan="7" id="info_space"></td>
</tr>
<tr>
<td valign="top" class="sirinaStupca"><!-- 1. STUPAC -->
</tr>
</table>
</div>
</div>
Other file just needs to echo it, for testing purpose, but it throws me an error: Error 404
Unable to resolve the request "test2.php". When I put normal text or css() instead of table it is working. I can't figure it out why.
if(isset($_POST["file"]))
{
echo $_POST["file"];
}