Updating mysql using php in html form - php

I've created a form that is supposed to update table contents in input boxes, when the content of the input boxes are changed and submitted the database is supposed to update.
This is my first page:
<body>
<form action="qa1.php" method="post">
<ul>
<li><a class="active" href="df1.php">Disease</a></li>
<li><a href="drug.php" >Drug</a></li>
<li>Interaction</li>
Alternate Drug
</ul>
<?php
$query = "SELECT * FROM disease;";
$result = mysqli_query($dp, $query);
echo "<table border=5>
<tr>
<th>Select</th>
<th>Edit</th>
<th>Disease ID</th>
<th>Disease</th>
<th>Sub Disease</th>
<th>Associated Disease</th>
<th>Ethinicity</th>
<th>Source</th>
</tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td><input type='radio' name='select' value=".$row['Disease_id']."/> </td>";
echo "<td>".$row{'Disease_id'}."</td>";
echo "<td><a href='edit.php?Disease_id=".$row['Disease_id']."'>edit</a></td>";
echo "<td>".$row{'Disease'}."</td>";
echo "<td>".$row{'SubDisease'}."</td>";
echo "<td>".$row{'Associated_Disease'}."</td>";
echo "<td>".$row{'Ethinicity'}."</td>";
echo "<td>".$row{'Source'}."</td>";
echo "</tr>";}
echo "</table>";
$selectedRow=$_POST['select'];
?>
<div>
<table border="0" align="center" style="border-spacing: 40px 30px;">
<caption><strong>QualityAnalysis:</br></br></strong></caption></br></br>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="40%">
</br><div><center>
<button style="color: red">Add</button>
<input type = 'submit' value = 'Delete' name = 'submitdelete' button style="color: red"></button>
<input type = 'submit' value = 'Update' name = 'submitupdate'>
</center></div> </TABLE>
</body>
</html>
This is my editing page: edit.php
<body>
<form action="edit.php" method="post">
<ul>
<li><a class="active" href="df1.php">Disease</a></li>
<li><a href="drug.php" >Drug</a></li>
<li>Interaction</li>
Alternate Drug
</ul>
<div>
<?php
$conn = mysqli_connect('localhost','root','','tool');
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_error());
}
if(isset($_GET['Disease_id']))
{
if(isset($_POST['Update']))
{
$id=$_GET['Disease_id'];
$name=$_POST['Ethinicity'];
$query3=mysqli_query("update disease set Ethinicity='$name', where Disease_id='$id'");
if($query3)
{
header('location:qa1.php');
}
}
$query1=mysqli_query("select * from disease where Disease_id='$id'");
$query2=mysqli_fetch_array($query1);
?>
<table border="2" align="center" style="border-spacing: 40px 30px;">
<caption><strong>Edit</br></br></strong></caption></br></br>
<tr>
<td>Ethinicity<input type="text" list="Ethinicity" name="Ethinicity" value="<?php echo $row['Ethinicity'];?>"/>
<input type="hidden" name="Disease_id" value="<?php echo $row['Disease_id']; ?>"/>
<input type="submit" name="Update" value ="Update">
<?php
}
?>
</center></div></div>
</form>
But Data is not getting updated in the database. Can anyone help me with this?

Firstly, mysqli_query requires the connection parameter.
Secondly, there's a syntax error with your UPDATE query, there isn't a need for a comma.
So, it should be:
$query3=mysqli_query($conn, "update disease set Ethinicity='$name' where Disease_id='$id'");
$query1=mysqli_query($conn, "select * from disease where Disease_id='$id'");
Also, if($query3) won't check if the row is successfully inserted, use mysqli_affected_rows instead.

Related

Cannot Input image to database. Image File Upload Error: Undefined index: file_img

Hi everyone i need some help regarding this error. Im trying to create a module that will allow users to upload their image and display it to the other page. I am using 3 forms (index.php for displaying, create.php for sql query and addform.php for adding records). But everytime I run the program it always shows an error: Undefined index: file_img
index.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="assets/jquery-1.11.3-jquery.min.js"> </script>
</head>
<body>
<div class="container">
<h2 class="form-signin-heading">Employee Records.</h2><hr />
<button class="btn btn-info" type="button" id="btn-add"> <span class="glyphicon glyphicon-pencil"></span> Add Employee</button>
<button class="btn btn-info" type="button" id="btn-view"> <span class="glyphicon glyphicon-eye-open"></span> View Employee</button>
<hr />
<div class="content-loader">
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Photos</th>
</tr>
</thead>
<?php
require_once 'dbconfig.php';
$sql = $db_con->prepare("select id, name, content, imgname from tblkeanu");
$sql->execute();
while($result=$sql->fetch(PDO::FETCH_ASSOC))
{
echo '<tr>';
echo '<td>' . $result["name"] . '</td>';
echo '<td>' . $result["content"] . '</td>';
echo "<td><img src = 'images/" . $result['imgname'] . "' height='350px;' width='300px;' class='img'></td>";
echo "<td><a id = $result[id] class = 'edit_link' href='#' title = 'EDIT'> EDIT </a></td>";
echo "<td><a id = $result[id] class = 'delete_link' href='#' title = 'DELETE'> DELETE </a></td>";
echo ' </td>';
echo '</tr>';
}
?>
</table>
</div>
</div>
<br />
<div class="container">
<div class="alert alert-info">
Tutorial Link
</div>
</div>
</body>
</html>
create.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$name = $_POST['txtname'];
$content = $_POST['txtcontent'];
$filetmp = $_FILES['file_img']['tmp_name'];
$filename1 = $_FILES['file_img']['name'];
$filetype = $_FILES['file_img']['type'];
$filepath = 'images/'.$filename1;
try{
move_uploaded_file($filetmp,$filepath);
$sql = $db_con->prepare("INSERT INTO `tblkeanu`(`name`, `content`, `imgname`, `imgpath`, `imgtype`) Values (:name,:content,:filename1,:filepath,:filetype)");
$sql->bindParam(":name",$name);
$sql->bindParam(":content",$content);
$sql->bindParam(":filename1",$filename1);
$sql->bindParam(":filetype",$filetype);
$sql->bindParam(":filepath",$filepath);
if($sql->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
addform.php
<form method='post' id='emp-SaveForm' action="#" enctype="multipart/form-data">
<table class='table table-bordered'>
<tr>
<td>Title</td>
<td><input type='text' name='txtname' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td>Content</td>
<td><input type='text' name='txtcontent' class='form-control' placeholder='EX : Web Design, App Design' required></td>
</tr>
<tr>
<td>Photo</td>
<td><input type='file' name='file_img'/></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
The tricky part here is if i combined the addform.php to create.php and address bar is "..../..../create.php" the program runs smoothly and the input type was identified. but i need these 2 to be separated and not combined on one page so the webpage will not be refreshed everytime because im also using a javascript and jquery and the address should only be "..../..../index.php".
It will be much appreciated if you could help me out.
In your addform.php file the form dosen't have an action yet, The form action should be create.php.
In the create.php file the condition:
if($sql->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
Should be modified as :
if($sql->execute())
{
header("Location: index.php");
}
else{
echo "Query Problem";
}
This way after saving the records to the database you will be redirected to index.php .
**IN This Section **
<tr>
<td>Photo</td>
<td><input type='file' name='file_img'/></td>
</tr>
Please try this edit, It may help..
<tr>
<td>Photo</td>
<td><input type='file' name='file_img' accept='image/*'/></td>
</tr>

Update query is not working correctly

I am making a code for editing a text area. The query runs correctly without any errors but the textarea is not updated. Can anyone help me with it please?
<html>
<body bgcolor="skyblue">
<form method= "post" enctype="multipart/form-data" action="upd.php">
<table align="center" width="795" border="2" bgcolor="#CCC">
<?php
$i=0;
$sel="select * from video";
$sel_query=mysqli_query($con, $sel);
while($row=mysqli_fetch_array($sel_query)){
$i++;
$var_id=$row['v_id'];
$var=$row['video'];
?>
<tr align="center">
<td align="right">
<br>
<h2>Upadte Video <?php echo $i; ?> Link: </h2>
<button type="submit" name="btn">
<a name="upd" href="upd.php?insert_brand=<?php echo $var_id; ?>&fram=<?php echo $var; ?>">Update</a>
</button>
<td align="left"><br><textarea name="vids" rows="4" cols="50"><?php echo $var; ?>"</textarea></td>
</td>
</tr>
<?php
}
?>
</table>
</form>
upd.php
<?php
include ("includes/db.php");
$check=#$_GET['insert_brand'];
if(isset($_POST['btn'])){
$vids=$_POST['vids'];
$upds="UPDATE `video` SET `video`='$vids' WHERE `v_id`='$check'";
$query=mysqli_query($con, $upds);
if($query){
echo 'The query is executed';
}
else{
echo 'There was an error'. mysqli_error($con);
}
}
?>
Have you tried mysql_real_escape_string() to retrieve textarea data.

multiple arrays value fetching with session

Insert Is Fine But if I select this value from database All Values are fine but single values fetch array problem I don't know how to solve this task. Please Update this code asap.
This Is Insert Code .....
<?php
if(isset($_POST['sendmessage'])){
$entermessage = $_POST['teachermessage'];
$checkbox_user = $_POST['usernameallcheckbx'];
$arr = implode(',',$checkbox_user);
//$arr2 = explode(',',$arr);
$insert = mysql_query("INSERT into usermessages(fromteacher,toparent,messages) VALUES('".$_SESSION['username']."','$arr','$entermessage')");
if($insert == 1){
echo "<h1>successful</h1>";
}
else{
echo mysql_error();
}
}
?>
<form method="post">
<div style="float:left; width:450px;"><br/><br/>Message: <br/>
<textarea style="width:400px; height:300px;" name="teachermessage"></textarea><br/>
<input type="submit" value="Send" name="sendmessage" /></div>
<div style="float:left; with:200px; padding-top:55px;">
<table>
<tr>
<?php
$select_query1 = mysql_query("SELECT * FROM register_user WHERE teacher='$teachername'");
while($chckbx=mysql_fetch_array($select_query1))
{
?>
<td><?php echo "<input type='checkbox' name='usernameallcheckbx[]' value=". $chckbx['userid']." />"; ?></td>
</tr>
<tr>
<td><?php echo $chckbx['parent_fname']." ".$chckbx['parent_lname']; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</form>
And This Is Select Code....
<h2>Messages</h2>
<?php
$select_query3 = mysql_query("SELECT * FROM usermessages");
$fetch= mysql_fetch_array($select_query3);
$data=$fetch['toparent'];
$arr=explode(',',$data);
//$userids=explode(',',$data);
$sessionshow=$_SESSION['userid'];
$userids=in_array("$sessionshow",$arr);
$select_query2 = mysql_query("SELECT * FROM usermessages WHERE toparent in ('$userids')='".$_SESSION['userid']."'");
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Teacher Name</th>
<th>Message</th>
</tr>
<?php
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo "<tr>";
echo "<td>".$fetch_data=$fetch_name2['fromteacher']."</td>";
echo "<td>".$fetch_data=$fetch_name2['messages']."</td>";
echo "</tr>";
}
?>
</table>
I have only put this as an answer to show some incorrect code - remove fetch data from your loop as it doesn't do anything
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo "<tr>";
echo "<td>".$fetch_name2['fromteacher']."</td>";
echo "<td>".$fetch_name2['messages']."</td>";
echo "</tr>";
}
even better is use of a HEREDOC:
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo <<<EOF
<tr>
<td>{$fetch_name2['fromteacher']}</td>
<td>{$fetch_name2['messages']}</td>
</tr>
EOF;
}
I really can't figure out what you're trying to do, but maybe this is the query you want:
SELECT * FROM usermessages WHERE FIND_IN_SET('$sessionshow', toparent)
FIND_IN_SET(str, strlist) searches the comma-separated list in strlist for an element that equals str, and returns the position in the list; if it's not found it returns 0, which counts as false.
I can't see any purpose to any of the code that uses $select_query3.

Multi checkbox post proplem

I wanna check same exist database, but doesn't work the $check. What's wrong ı cannot find.
ı taking this error when post;
error 1-Members not added :(
Mysql error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''459' at line 1
error 2- 459 memb_id already in databese, try again!
This is my code:
<?php
$row_data = array();
foreach($_POST['checkbox'] as $row=>$Name) {
$name=mysql_real_escape_string($Name);
$memb_id=mysql_real_escape_string($_POST['memb_id'][$row]);
$memb_srnm=mysql_real_escape_string($_POST['memb_srnm'][$row]);
$kur_id=mysql_real_escape_string($_POST['kur_id'][$row]);
$row_data = array("'$memb_id'", "'$memb_srnm'", "'$kur_id'");
}
if (!empty($row_data)) {
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id");
if (mysql_affected_rows() ){
echo '<h4 class="alert_error"><strong>'.ss($memb_id).'</strong> already in databese, try again! </h4>';
header('Location: index.php');
} else {
$query = 'INSERT INTO basvurular (memb_id, memb_srnm, basvur_kurid) VALUES (' .implode(',', $row_data) . ')';
}
if (mysql_query($query)){
echo '<h4 class="alert_success"> <label style="color: blue; font-size: 26px; font-weight: bold;"><img style="width: 4%" src="images/pers2.png" alt=""/>-'.mysql_affected_rows().'- </label> Succesfull :) </h4>';
header('Location: index.php');
}else{
echo '<h4 class="alert_error">Members not added :( <br> Mysql Error:'.mysql_error().'</h4>';
return false;}
}
?>
<article class="module width_3_quarter" style="padding-bottom: 10px; width: 95%">
<header>
<div style="float:right;font-size:14px;font-weight: bold; padding:10px"></div>
<h3 class="tabs_involved">POST SELECTED</h3>
</header>
<div class="tab_container">
<?php
$query = query("SELECT * FROM members INNER JOIN kurumlar ON kurumlar.kur_id = members.kur_id WHERE kurumlar.kur_id=' ".$_SESSION["kur_id"]." ' && ceza=0 ORDER BY memb_id DESC");
if (mysql_affected_rows()){
?>
<div id="tab1" class="tab_content">
<?php echo '<form action="" method="post" name="frm" onsubmit="return check">
<table class="tablesorter" cellspacing="0"> '; ?>
<thead>
<tr>
<th><a style="text-decoration: none;font-size:14px;font-weight: bold; color: blue" href="javascript:void(0);" id="link" onclick="slct()">All Select</a></th>
<th align= "left" >ID Number</th> <th></th>
<th align= "left" >USER NAME</th><label style="padding-right: 10px;padding-bottom: 10px;float:right " ><input style="color: red" type="submit" name="post" value="Selected Post"></label>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($row = row($query)){
?>
<tr>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" ></td>
<td><?php echo ss($row["membName"]);?></td><td><input name="memb_id[]" type="hidden" value="<?php echo ss($row["memb_id"]);?>"></td>
<td><?php echo ss($row["memb_srnm"]);?></td><td><input name="memb_srnm[]" type="hidden" value="<?php echo ss($row["memb_srnm"]);?>"></td>
<td><input name="kur_id[]" type="hidden" value="<?php echo ss($_SESSION["kur_id"]);?>"></td>
</tr>
<?php }?>
</tbody>
<?php echo '</table></form>'; ?>
</div>
<?php }else{ ?>
<h4 class="alert_warning">Nobody Here :(( </h4>
<?php }?>
</div>
</article>
You're missing a quote on this line:
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id'");
Also, to check whether a SELECT query returned any rows, you should use mysql_num_rows(), not mysql_affected_rows() -- the latter is only for queries that modify tables.
You should also check that the query is successful:
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id")
or die(mysql_error());

Trying to pass a variable to another php page based on the data from checkbox

I'm trying to use php with mysql. basically i've an index page where user fills a form and another page where all rows are displayed. i've checkboxes for each row for deleting the selected row/rows. i'm trying to create a new page (namely details) where it shows only the selected row.
I'm trying to use $_GET but i could not do it. maybe the syntax is wrong. any help is welcome.
here are the relative code parts:
display.php:
<?
require_once('auth.php');?>
<html>
<head>
<title>Goruntule</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="checkboxForm">
<?
require "config.php"; // All database details will be included here
$page_name="display.php";
$start=$_GET['start']; // To take care global variable if OFF
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start -0);
$limit = 10; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// WE have to find out the number of records in our table. We will use this to break the pages
$query2=" SELECT * FROM table1 ";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////
/////////// Now let us print the table headers ////////////////
$bgcolor="#f1f1f1";
echo "<TABLE width=80% align=center cellpadding=5 cellspacing=0> <tr>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>#</font></td>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>ID</font></td>";
echo "<td bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='2'>Time</font></td>";
echo "</tr>";
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query=" SELECT * FROM table1 ORDER BY id DESC limit $eu, $limit ";
$result=mysql_query($query);
echo mysql_error();
//////////////// Now we will display the returned records in side the rows of the table/////////
while($rows = mysql_fetch_array($result))
{
if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}
echo "<tr>";
echo "<td><input name='checkbox[]' type='checkbox' value='" . $rows[id] . "'></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='1'>$rows[id]</font></td>";
echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='1'>$rows[DateTime]</font></td>";
echo "<td>Details</td>";
//here is the problematic line i guess
echo "</tr>";
}
echo "</table>";
////////////////////////////// End of displaying the table with records ////////////////////////
///// Variables set for advance paging///////////
$p_limit=100; // This should be more than $limit and set to a value for whick links to be breaked
$p_f=$_GET['p_f']; // To take care global variable if OFF
if(!($p_f > 0)) { // This variable is set to zero for the first page
$p_f = 0;
}
$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;
//////////// End of variables for advance paging ///////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='50%'><tr><td align='left' width='20%'>";
if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; }
echo "</td><td align='left' width='10%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0 and ($back >=$p_f)) {
print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "</td><td align=center width='30%'>";
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){
if($i <> $eu){
$i2=$i+$p_f;
echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='2'>$i</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$i</font>";} /// Current page is not displayed as link and given font color red
}
echo "</td><td align='right' width='10%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume and $this1 <($p_f+$p_limit)) {
print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";}
echo "</td><td align='right' width='20%'>";
if($p_fwd < $nume){
print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT $p_limit</font></a>";
}
echo "</td></tr></table>";
?>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete">
<form>
<INPUT TYPE="BUTTON" VALUE="Previous" ONCLICK="window.location.href='http://......../util'">
</FORM></td>
</tr>
<?php
$checkbox=$_POST['checkbox'];
if($_REQUEST['delete']=='Delete'){
foreach($checkbox as $id => $value)
{$sql="DELETE FROM table1 WHERE id='$value'";
$result = mysql_query($sql);
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=display.php\">";
}
}
?>
details
<?
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
detail.php
<?php
require_once('auth.php');
$host="localhost";
$username="";
$password="";
$db_name="";
$tbl_name="table1";
mysql_connect("$host", "$username", "$password")or die("Cannot connect ". mysql_error());
mysql_select_db("$db_name")or die("Cannot select DB ". mysql_error());
$num=$_GET['var1'];
$query = "SELECT * FROM table1 where id='$num'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result) or die(mysql_error());
?>
<table border="0" align="center" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="13" align="center" bgcolor="#FFFFFF"><strong>Bölge</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Time</strong></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF" align="center"><? echo $row['13']; ?></td>
<td bgcolor="#FFFFFF" align="center"><? echo $row['0']; ?></td>
</tr>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete">
<form>
<input type=button value="Close" onClick="javascript:window.close();">
</form>
</tr>
<?php
$checkbox=$_POST['checkbox'];
if($_REQUEST['delete']=='Delete'){
foreach($checkbox as $key=>$value)
{$sql="DELETE FROM $tbl_name WHERE id='$value'";
$result = mysql_query($sql);
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=display.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
<html><head><link href="loginmodule.css" rel="stylesheet" type="text/css" /></head></html>
As I've said, the only problem i'm guessing is with the syntax, or something small as i can echo the row when i gave the var1 a specific id.
I'm sorry if i'm reposting but i couldn't find an answer. Thanks!
Edit: I'm thinking of deleting checkbox parts and adding gif links in the while loop where users can delete, edit or detailed view of the corresponding row. seems easier i guess.
Make sure that the details link is within the while block.
<?php
while($rows = mysql_fetch_array($result)) {
echo 'Details';
}
?>
Looks like you should not be using double quotes.
<? echo "$rows[id]" ?>
Should be
<?php echo $rows[id]; ?>
I also suggest you use 'id' as the name of the get rather than 'var1'. 'var1' does not mean anything whereas 'id' makes more sense.
Details
It's because you are using $rows outside your while-loop. You have to put the
Details
inside the while loop.
//EDIT:
Alright, I've stripped your code to the very neccessary according to your problem. So don't just copy/paste the code, it probably won't work. But read it carefully, and I hope you get the idea and see what may be wrong with your code ;)
display.php
<?php
require_once('auth.php');
require "config.php";
$page_name="display.php";
$start = (isset($_GET['start']) && $_GET['start'] < 1) ? 0 : $_GET['start'];
$eu = ($start-0);
$limit = 10;
$query="SELECT * FROM table1 ORDER BY id DESC limit $eu, $limit";
$result=mysql_query($query);
echo mysql_error();
$i = 0; //counter for the bg-color
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="checkboxForm">
<table width="80%" align="center" cellpadding="5" cellspacing="0">
<?php while($rows = mysql_fetch_array($result)) :
$bgcolor = $i%2 == 0 ? '#ffffff' : '#f1f1f1';
?>
<tr>
<td>
<input name="checkbox[]" type="checkbox" value="<?php echo $rows['id']; ?>">
</td>
<td style="align: left; font-family: Verdana; font-size: 10px; background-color: <?php echo $bgcolor; ?>;" id="title">
<?php echo $rows['id']; ?>
</td>
<td style="align: left; font-family: Verdana; font-size: 10px; background-color: <?php echo $bgcolor; ?>;" id="date">
<?php echo $rows['DateTime']; ?>
</td>";
<td>
Details
</td>
</tr>
<?php endwhile; ?>
</table>
</form>
detail.php
<?php
require_once('auth.php');
$num= isset($_GET['var1']) ? $_GET['var1'] : '';
$query = "SELECT * FROM table1 where id='$num'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
?>
<form name="form1" method="post" action="">
<table border="0" align="center" cellspacing="1" cellpadding="0">
<input name="checkbox[]" type="checkbox" value="<? echo $rows['id']; ?>">
<? echo $row['13']; ?>
<? echo $row['0']; ?>
<input name="delete" type="submit" id="delete" value="Delete">
<button onClick="javascript:window.close();">Close</button>
</table>
</form>
And not only for security's sake, you should get more familiar with PHP and some design patterns before publishing your website.

Categories