Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Need some :help:

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Need some :help:

Postby supaflyer » Wed Apr 24, 2013 7:09 am

Hello everyone, just found your forum in desperate need for help, im not into php but i have some website that the delete entry is not working anymore, i will try to simplify so it can be fast code read.

the problem is on backoffice that add/delete reservations:


i think it has this for deleting the file on the begining of the backoffice page

Code: Select all
<?php include("inc.apagar.php"); ?>


inc.apagar.php file contents:

Code: Select all
<?php
if ((isset($_GET['del'])) && ($_GET['del'] != "")) {
   $deleteSQL = sprintf("DELETE FROM ".$tabela." WHERE id=%s",
                  GetSQLValueString($_GET['del'], "int"));
   
   mysql_select_db($database_conexao_bd, $conexao_bd);
   $Result1 = mysql_query($deleteSQL, $conexao_bd) or die(mysql_error());
   
   $deleteGoTo = $main_pag;
   header(sprintf("Location: %s", $deleteGoTo));
}
?>


now the button that should delete the entry has this

Code: Select all
<a href="#"><img onClick="<?php echo "'".$actual_pag."','".$tipo_pag."',".$row_agenda['id'].",'".$row_titulo_imovel['nome']; ?>" src="imagens/delete.png" alt="Apagar" width="16" height="16" border="0" title="Apagar"></a>


i would like to truly thanks any help in advance
supaflyer
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Apr 24, 2013 6:56 am

Re: Need some :help:

Postby johnj » Wed Apr 24, 2013 8:06 pm

What is the error that you are getting?
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Need some :help:

Postby supaflyer » Thu Apr 25, 2013 3:28 am

It doesn't delete the reservation, just refresh the webpage and nothing happens... tyvm john
supaflyer
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Apr 24, 2013 6:56 am

Re: Need some :help:

Postby seandisanti » Thu Apr 25, 2013 7:46 am

So you know, that is a bad implementation anyway. if someone adds ?del=%27%25%27 ('%') to the end of their url, they could potentially wipe out that table.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Need some :help:

Postby supaflyer » Thu Apr 25, 2013 7:49 am

i didnt know that, the site itself is really bad developed but now i have to hold to it :(

can u help me out with the command to delete the entry please?

Tyvm
supaflyer
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Apr 24, 2013 6:56 am

Re: Need some :help:

Postby seandisanti » Thu Apr 25, 2013 8:02 am

Actually, I apologize, I didn't see the explicit casting and string escaping prior to my last post, so it's not as bad as I'd originally thought. just for laughs, add this line after the $Result1 line...
Code: Select all
die('the result is : ' mysql_affected_rows($conexao_bd) . '<br />And the delete query is: <br />' $deleteSQL);
 

That should return two lines of input, the first being the number of rows affected by the query, and teh second being the query its trying to execute. could you copy and paste the output here?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Need some :help:

Postby supaflyer » Thu Apr 25, 2013 8:32 am

Do not get any output, added the line to the file inc.apagar.php~, file looks like this now:

Code: Select all
<?php
if ((isset($_GET['del'])) && ($_GET['del'] != "")) {
   $deleteSQL = sprintf("DELETE FROM ".$tabela." WHERE id=%s",
                  GetSQLValueString($_GET['del'], "int"));
   
   mysql_select_db($database_conexao_bd, $conexao_bd);
   $Result1 = mysql_query($deleteSQL, $conexao_bd) or die(mysql_error());
   die('the result is : ' . mysql_affected_rows($conexao_bd) . '<br />And the delete query is: <br />' . $deleteSQL);
   
   $deleteGoTo = $main_pag;
   header(sprintf("Location: %s", $deleteGoTo));
}
?>


when i press the delete link, same thing happens, reload the webpage and nothing happens, am i doin something wrong?

Tyvm
supaflyer
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Apr 24, 2013 6:56 am

Re: Need some :help:

Postby seandisanti » Thu Apr 25, 2013 9:25 am

ok, it doesn't look like the delete code is being executed. Was this code working previously, or has it never worked?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Need some :help:

Postby johnj » Thu Apr 25, 2013 7:32 pm

$_GET['del']..... Looks like you are expecting a submit from a delete button and what you have right now is an image(link) to click.

So, either use a delete button with a form OR write the code to trap the click from a image/link.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Need some :help:

Postby supaflyer » Fri Apr 26, 2013 5:29 am

That used to work , it opened a dialog asking confirmation for delete.

The website was on a windows hosting, i had to move to a linux hosting, everything was smooth, except for the the showing of the calendar with the reservations, was creating a big error log, i opened the log saw the lines of the error, and searched for solution it was a problem with string variables i think.

the error was this:
[11-Apr-2013 13:54:40 Europe/Paris] PHP Warning: mktime() expects parameter 6 to be long, string given in /home/fadoflat/public_html/disponibilidade.php on line 284

the line had this:
Code: Select all
for($d=1;$d<=date("t",mktime(0,0,0,($month+1),0,$year));$d++)


i had to change all '$year' to '(int) $year' and the problem was fixed, the $year is defined as this on top of the file:
Code: Select all
{
  $year=date("Y",mktime());
  $year = intval($year);
  $year = isset($_GET["ano"]) ? $_GET['ano'] : $year;
}


when i noticed the delete wasnt working i changed everything as it was and still didnt work so i think is not from this change, but im not sure, im a really a noob at this, i try to read but some stuff is really out of my compreension.

based on the link code to delete the entry, what should i change to make a simple instruction delete it?

tyvm all for the time and help
supaflyer
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Apr 24, 2013 6:56 am

Re: Need some :help:

Postby seandisanti » Fri Apr 26, 2013 7:36 am

As John pointed out, your delete is being initiated based on a GET variable of del. so if your delete button is a link, you'd want to point it at the name of the page, and tack on '?del=N' without the quotes, and with 'N' replaced by the article number to delete.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.