Hello Friends I am new to PHP can any one help me
i am facing one problem
whenever i am working on local host my delete command is working without problem
but whenever i am uploading this file on internet through FTP
the command not deleting any records

Every one help wuld be appreciated
thanks manish mannan

Recommended Answers

All 42 Replies

Do you mean delete in an SQL query, or a unlink to delete files?

[QUOTE=Will Gresham;1035387]Do you mean delete in an SQL query, or a unlink to delete files?[/QUOTE]
sory brother your are not getting me
my question is
i am working on some multiple records like here is my code

<?php
//echo $user;
session_start();
if (!isset($_SESSION['myusername']))
{
echo'<center><b>You need TO login First</b></center>'; 
include 'login.html'; 
exit(); 
}
else{
session_set_cookie_params(1200); 
}

$user = $_SESSION['myusername'];
?>
<style>
body {
    font-family:Arial, Helvetica, sans-serif;
    background:#FFFFF0;
    font-size:12px;
    color:#000000;
}
.logout {
    cursor:pointer;
    background:#FFFF00;
    border:#FF6600 1px solid;
    width:100px;
    height:30px;
    font-size:14px;
    font-weight:bold;
    color:#FF6600;
    float:right;
    text-decoration:none;
    font-family:Arial;
    font-size:14px;
    line-height:30px;
    margin:50px 50px 0px 0px;
    text-align:center;
}
h1 {
    font-family:Arial, Helvetica, sans-serif;
    font-size:20px;
    color: #FF6600;
    text-align:center;
    margin:50px auto 0px auto;
    font-weight:500;
}
.head {
    font-family:Arial, Helvetica, sans-serif;
    font-size:14px;
    color: #000;
    text-align:center;
}
.form {
    font-family:Arial, Helvetica, sans-serif;
    font-size:12px;
    color:#666666;
    line-height:18px;
    background:#FBFBFB;
    width:100%;
    padding:20px;
    border:#FFCC00 2px solid;
    font-weight:bold;
}
.lable {
    margin-left:100px;
}
.btn {
    cursor:pointer;
    background:#E0E0E0;
    border:#000 1px solid;
    width:100px;
    height:30px;
    font-size:14px;
    font-weight:bold;
    color:#000;
    float:left;
    margin-left:20px;
}
</style>
<title>View Record of Online Application</title><a href="logout.php"><span class="logout">LOGOUT</span> </a><br />
<br />
<br />
<br />
<br />
<h1>Login as&nbsp;&nbsp;<?php echo $user;  ?></h1>
<?php
      $host="localhost"; // Host name
      $username="root"; // Mysql username
      $password=""; // Mysql password
      $db_name="hnit";
      $tbl_name="registration";
      $con = mysql_connect($host, $username, $password)or die("cannot connect");
      mysql_select_db($db_name)or die("cannot select DB");
      $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
      $result=mysql_query($sql);
      $count=mysql_num_rows($result);

?>
<form name="form1" method="get"  action= "">
  <table width="100%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bgcolor="#FBFBFB" class="head">
    <tr>
      <td height="38" colspan="8" bgcolor="#FFCC00"><strong>RECORDS DISPLAYING FOR ONLINE APPLICATION </strong></td>
    </tr>
    <tr>
      <td width="67" height="38" align="center" bgcolor="#FFFFCC"><strong>SELECT</strong></td>
      <td width="48" align="center" bgcolor="#FFFFCC"><strong>Id</strong></td>
      <td width="188" align="center" bgcolor="#FFFFCC"><strong>Name</strong></td>
      <td width="135" align="center" bgcolor="#FFFFCC"><strong>Email ID </strong></td>
      <td width="175" align="center" bgcolor="#FFFFCC"><strong>ADDRESS</strong></td>
      <td width="157" align="center" bgcolor="#FFFFCC"><strong>COURSE</strong></td>
      <td width="115" align="center" bgcolor="#FFFFCC"><strong>EDUCATION</strong></td>
      <td width="143" align="center" bgcolor="#FFFFCC"><strong>PHONE NO </strong></td>
    </tr>
    <?php while($rows=mysql_fetch_array($result, MYSQL_ASSOC)){ ?>
    <tr>
      <td height="44" align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value=" <?php echo $rows['id']; ?>"></td>
      <td bgcolor="#FFFFFF"><?php echo $rows['id']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $rows['name']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $rows['emailid']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $rows['address']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $rows['course']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $rows['education']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $rows['phoneno']; ?></td>
    </tr>
    <?php } ?>
    <tr>
      <td height="58" colspan="8" align="center" bgcolor="#FFFFCC"><input name="delete" type="submit" id="delete" value="Delete" class="btn" style="float:none;"></td>
    </tr>
    <?php if($_GET['delete']){
    for($i=0;$i<count($_GET['checkbox']);$i++)
    {
    $del_id = $checkbox[$i];
    $sql = "DELETE FROM $tbl_name WHERE id='$del_id' LIMIT 1";
    $result = mysql_query($sql,$con);
    if (mysql_query($sql,$con)) 
    {
    echo " records is sucessfully Deleted";
    }
    else{
    die('Error: ' . mysql_error());
    } 
    } 
    if($result){
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=del.php\">";
    }
    }
    mysql_close();

?>
  </table>
</form>

whenever i am working on local host it work fine but after uploading file on internet
this script not deleting any records
what do i do????

If you upload the same script as it is to work on the server, it's supposed to throw errors.
Look your few variable settings, you need to change them to the server values.

$host="localhost"; // Host name, should be actual db server name now, and not the localhost
$username="root"; // Mysql username on the above server
$password=""; // Mysql password for the above db server
$db_name="hnit";//is the db name same on the server too

Edit: Please use the code tags

Thanks for your Reply
yes brother after changing this personal information about the database still i am not able to delete the values selected by checkbox
while with the same program i am able to delete the values on my localhost
the script not work on internet why is it so
is there any change needed in php.ini
or any change needed in mysql plz tell me i am in big trouble

in my localhost my PHP Engine Type is MyISAM While on Internet My php Engine Type is InnoDB
is there any difference in both the type of PHP engine

you did the same common mistake..not doing isset on $_POST.
your improved code here -

<?php
//echo $user;
session_start();
if (!isset($_SESSION['myusername']))
{
	echo'<center><b>You need TO login First</b></center>';
	include 'login.html';
	exit();
}
else{
	session_set_cookie_params(1200);
}

$user = $_SESSION['myusername'];
?>
<style>
body {
font-family:Arial, Helvetica, sans-serif;
background:#FFFFF0;
font-size:12px;
color:#000000;
}
.logout {
cursor:pointer;
background:#FFFF00;
border:#FF6600 1px solid;
width:100px;
height:30px;
font-size:14px;
font-weight:bold;
color:#FF6600;
float:right;
text-decoration:none;
font-family:Arial;
font-size:14px;
line-height:30px;
margin:50px 50px 0px 0px;
text-align:center;
}
h1 {
font-family:Arial, Helvetica, sans-serif;
font-size:20px;
color: #FF6600;
text-align:center;
margin:50px auto 0px auto;
font-weight:500;
}
.head {
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color: #000;
text-align:center;
}
.form {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
color:#666666;
line-height:18px;
background:#FBFBFB;
width:100%;
padding:20px;
border:#FFCC00 2px solid;
font-weight:bold;
}
.lable {
margin-left:100px;
}
.btn {
cursor:pointer;
background:#E0E0E0;
border:#000 1px solid;
width:100px;
height:30px;
font-size:14px;
font-weight:bold;
color:#000;
float:left;
margin-left:20px;
}
</style>
<title>View Record of Online Application</title><a href="logout.php"><span class="logout">LOGOUT</span> </a><br />
<br />
<br />
<br />
<br />
<h1>Login as&nbsp;&nbsp;<?php echo $user; ?></h1>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="hnit";
$tbl_name="registration";
$con = mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if(isset($_GET['delete']) && $_GET['delete'] =='Delete')
{
	for($i=0;$i<count($_GET['checkbox']);$i++)
	{
		$del_id = $checkbox[$i];
		$sql = "DELETE FROM $tbl_name WHERE id='$del_id' LIMIT 1";
		$result = mysql_query($sql,$con);
		if (mysql_query($sql,$con))
		{
			echo " records is sucessfully Deleted";
		}
		else{
			die('Error: ' . mysql_error());
		}
	}
	if($result){
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=del.php\">";
	}
}

?>
<form name="form1" method="get" action= "">
<table width="100%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bgcolor="#FBFBFB" class="head">
<tr>
<td height="38" colspan="8" bgcolor="#FFCC00"><strong>RECORDS DISPLAYING FOR ONLINE APPLICATION </strong></td>
</tr>
<tr>
<td width="67" height="38" align="center" bgcolor="#FFFFCC"><strong>SELECT</strong></td>
<td width="48" align="center" bgcolor="#FFFFCC"><strong>Id</strong></td>
<td width="188" align="center" bgcolor="#FFFFCC"><strong>Name</strong></td>
<td width="135" align="center" bgcolor="#FFFFCC"><strong>Email ID </strong></td>
<td width="175" align="center" bgcolor="#FFFFCC"><strong>ADDRESS</strong></td>
<td width="157" align="center" bgcolor="#FFFFCC"><strong>COURSE</strong></td>
<td width="115" align="center" bgcolor="#FFFFCC"><strong>EDUCATION</strong></td>
<td width="143" align="center" bgcolor="#FFFFCC"><strong>PHONE NO </strong></td>
</tr>
<?php while($rows=mysql_fetch_array($result, MYSQL_ASSOC)){ ?>
<tr>
<td height="44" align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value=" <?php echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['emailid']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['address']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['course']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['education']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['phoneno']; ?></td>
</tr>
<?php } ?>
<tr>
<td height="58" colspan="8" align="center" bgcolor="#FFFFCC"><input name="delete" type="submit" id="delete" value="Delete" class="btn" style="float:none;"></td>
</tr>
<?php 
mysql_close();
?>
</table>
</form>

you can experiment with the form method=post

thanks for your reply sir but my coding is currently working on localhost but not working on internet why is it so

if your changes work then i will back to you thanks once again

you tried this code, change method in the form to 'POST' and the successive changes from $_GET to $_POST like -
if(isset($_POST) && $_POST =='Delete')

but boss my script is not working even on local host after changing with get to post
i am remain with my $_GET Script

whenever i am working on local host it work fine but after uploading file on internet
this script not deleting any records
what do i do????

so what error you getting on the server?
Again you including the login.html and using <?php echo $user; ?> in the script, $user gets set in the html file??
check with this or post your login.html too here

commented: Use code and icode tags :( +0

thanks but my problem is not solve

is there any change needed in php.ini file to delete records from the database if it happen thn plz tell me

Login.HTML

<html>
<head>
<script language="JavaScript" type="text/javascript"> 
function validate()
{
if (document.frm1.txtuser.value == '')
{
alert('Please fill a UserName!');
return false;
}
if (document.frm1.txtpass.value == '')
{
alert('Please fill in Password!');
return false;
}
return true;    
}

</script>
<style>
body {
    font-family:Arial, Helvetica, sans-serif;
    background:#FFFFF0;
    font-size:12px;
    color:#000000;
}
.logout {
    cursor:pointer;
    background:#FFFF00;
    border:#FF6600 1px solid;
    width:100px;
    height:30px;
    font-size:14px;
    font-weight:bold;
    color:#FF6600;
    float:right;
    text-decoration:none;
    font-family:Arial;
    font-size:14px;
    line-height:30px;
    margin:50px 50px 0px 0px;
    text-align:center;
}
h1 {
    font-family:Arial, Helvetica, sans-serif;
    font-size:20px;
    color: #FF6600;
    text-align:center;
    margin:50px auto 0px auto;
    font-weight:500;
}
.head {
    font-family:Arial, Helvetica, sans-serif;
    font-size:14px;
    color: #000;
    text-align:center;
    font-weight:bold;
}
.form {
    font-family:Arial, Helvetica, sans-serif;
    font-size:12px;
    color:#666666;
    line-height:18px;
    background:#FBFBFB;
    width:100%;
    padding:20px;
    border:#FFCC00 2px solid;
    font-weight:bold;
}
.lable {
    margin-left:100px;
}
.btn {
    cursor:pointer;
    background:#E0E0E0;
    border:#000 1px solid;
    width:100px;
    height:30px;
    font-size:14px;
    font-weight:bold;
    color:#000;
    float:left;
    margin-left:20px;
}
</style>
<title>Admin Login</title><body>
<form name= "frm1" method= "post" action="login.php"  >
  <h1 align="center" class="style1">ADMIN PANEL </h1>
  <br>
  <br>
  <table width="354" height="166" border="1" align="center" cellspacing="0" bordercolor="#FF9900" bgcolor="#FBFBFB" class="head">
    <tr>
      <th height="23" colspan="2" bgcolor="#FFCC00">LOG IN </th>
    </tr>
    <tr>
      <td width="83" height="40"> User</td>
      <td width="261" height="40"><input type="text" name="txtuser" /></td>
    </tr>
    <tr>
      <td height="40">Password</td>
      <td height="40"><input type="password" name="txtpass" /></td>
    </tr>
    <tr>
      <td height="40">&nbsp;</td>
      <td height="40"><input type="submit" name="submit" value="login" class="btn"/></td>
    </tr>
  </table>
</form>
    <center><a href="forget.php" target="_self">Foget Username or Password </a><br>
<a href="change.php" target="_self">Change Password</a>
    </center>
</body>
</html>

NOW Login.php

<?php

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="hnit"; // Database name

$tbl_name="login"; // Table name



// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from signup form

$myusername= $_POST['txtuser'];

$mypassword= $_POST['txtpass'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

$result=mysql_query($sql);


// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

//echo"$count";

// If result matched $myusername and $mypassword, table row must be 1 row



if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

session_start ();



    $_SESSION['myusername'] = $_POST['txtuser'];

    $_SESSION['myusername'];

    $_SESSION['mypassword'] = $_POST['txtpass'];

    //$_SESSION['id'] = $ror[id];



    session_write_close ();



    header ( 'location: task.php' );



    exit ();

}

else {
echo'<center><b>Wrong Username or Password</b></center>';

}

?>
<style>
body {
    font-family:Arial, Helvetica, sans-serif;
    color:#ff0000;
    font-size:16px;
    font-weight:bold;
    background:#FFFFF0;
    padding:50px;
}
#holder {
    width:502px;
    height:164px;
    margin:50px auto 0px auto;
    background:#FFFFCC;
    border:#FFCC00 1px solid;
}
#link {
    width:500px;
    position:relative;
    float:left;
    background: #FFFFCC;
    text-align:center;
    border:#FFCC00 1px solid;
}
#link a {
    color:#000;
    padding:10px;
    text-decoration:none;
    display:block
}
#link a:hover {
    color:#ff0000;
    text-decoration:none;
    background:#FFCC00;
}
#link a:visited {
    color:#000;
    text-decoration:none;
}
#link a:active {
    color:#000;
    text-decoration:none;
}
h1 {
    font:bold Arial, Helvetica, sans-serif 14px;
    color: #FF6600;
    text-align:center;
    margin:50px auto 0px auto;
}
#logout {
    cursor:pointer;
    background:#FFFF00;
    border:#FF6600 1px solid;
    width:100px;
    height:30px;
    font-size:14px;
    font-weight:bold;
    color:#FF6600;
    float:right;
    margin-right:100px;
    margin-top:20px;
    position:relative;
}
</style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Wrong Username or Password</title>
</head>
<body>
<?php echo $error_message; ?>
</body>
</html>

plz help me dude

there is no any kind of error occuring in the server even it print the message that records have deleted but still reords is not deleted
My all the commands work properly but still the records are not deleted do somthing take it seriously plzzzzzz

No,deleting the rows got nothing to do with php.ini settings. Now I will write how to start debugging step by step.
-first check if you can connect to the mysql on the server; echo the connection object like

$con = mysql_connect(.....,....,..);
echo "Connection=>".$con;

-check you getting the delete query as echo after the delete
-try to execute it in the db,got any error in the mysql with the query syntax.

Please use code tags, it makes it easier to read your code.

Also, the code on the first page has a Delete statement, the code above does not. Which code are you using at the moment?

hello friends
1stly i am replying to network
my query works fine like there is a statements in my script like this

<?php if($_GET['delete'] && $_GET['delete'] =='Delete' ){
    for($i=0;$i<count($_GET['checkbox']);$i++)
    {
    $del_id = $checkbox[$i];
    $sql = "DELETE FROM $tbl_name WHERE id='$del_id' ";
    $result = mysql_query($sql,$con);
    if (mysql_query($sql,$con)) 
    {
    echo " records is sucessfully Deleted";
    }
    else{
    die('Error: ' . mysql_error());
    } 
    } 
    if($result){
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=del.php\">";
    }
    }
    mysql_close();

?>

here i got proper execution of my script even no any kind of error occured
and message prints sucessfully
like
records is sucessfully Deleted
but results is no rows are deleting from the database

and this is the same script that work fine on my local host but not on uploading files on internet
what to do??????????
plz help me out
and i need to tell you that my localhost sql version is
MySQL
Server: localhost via TCP/IP
Server version: 5.1.37
Protocol version: 10
User: root@localhost
MySQL charset: UTF-8 Unicode (utf8)

and on internet i am having

localhost
Server version: 5.0.18-nt
Protocol version: 10
Server: localhost via TCP/IP
User: DATABASE@127.0.0.1
MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation:

is there any difference in any both the version of my sql??????

NOW hii Will Gresham
thanks for the reply

sir on previous page i have pasted the script of my delete command you can try it and i am remain with that script
thanks
if you can do somthing plz reply

is there any difference in any both the version of my sql??????

Firstly, thanks for the neat and clean information.
But its not the MySQL version issue. Can you put here the MySQL connection settings you making.Like i said previously, when you executing the script on the server, you need to do the proper changes in the server address like "localhost" won't work there.
Put the IP of your database server there.It might be possible that, the connection your script making on the server is to some other database and its executing fine there, but you checking with some other database as par your expectation.

hii thanks once again
see my script carefully 1st of all i am getting some date from the database in my tables with my php script the data has been appered on the web page without any problem but wenever i am selecting a records to delete from the data base query executes fine even the echo message has been apperead that records have been deleted.
but still no records have been deleted from the database
if records are coming well by select query on the table then its mean the selected database is correct
what to do???????

hii thanks once again
see my script carefully 1st of all i am getting some date from the database in my tables with my php script the data has been appered on the web page without any problem but wenever i am selecting a records to delete from the data base query executes fine even the echo message has been apperead that records have been deleted.
but still no records have been deleted from the database
if records are coming well by select query on the table then its mean the selected database is correct
what to do???????

yes, I strongly agree with you and understood your problem too.
But what I am concerned about is that, are you using the same database for both,localhost and online too.That's what I was checking in the previous post.Please make it clear too.

no no no
i am using my diffterent database with locahost & with internet like
here in localhost i am using----- localhost,root,'no password'
on internet i am using some ----someIP address,hnitindia,"with password"

no no no
i am using my diffterent database with locahost & with internet like
here in localhost i am using----- localhost,root,'no password'
on internet i am using some ----someIP address,hnitindia,"with password"

ok, fine.please use this -

echo mysql_error($connection);

and post it here.
I suspect your "this MySQL user" don't have a grant on the database.
You getting the echo that, "Successfully deleted " doesnt mean necessarily the query got executed. This echo will depend upon what you comparing against.
give it a try-

$sql = "DELETE FROM $tbl_name WHERE id='$del_id' ";
$result = mysql_query($sql,$con);
echo "result=>".$result."Error=>".mysql_error($con);

hiiii
this change in your script work fine on my localhost now i am going to check on the internet
please wait for a while

hiiii
this change in your script work fine on my localhost now i am going to check on the internet
please wait for a while

yes, do that and post here the echoes i gave in the code

yes hello now before refresh
it shows like this
result=>1Error=> records is sucessfully Deleted
now how to remove error

is it the error or the result getting by my checkbox what is it??????? plz do it fast

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.