Problems deleting and updating the mysql help!

Troubleshooting with your custom scripts/programs installed on Polarhome.

Moderator: Moderators

Problems deleting and updating the mysql help!

Postby netsheik » Thu Jul 07, 2005 5:28 pm

Hi,

I'm making my homepage and I have problems with the interaction with the mysql. I can't update and delete a register. I use the next code:

Code: Select all
<?
$id = $HTTP_GET_VARS["noticia"];

$usuario="******";
$password="*****";
$database="******";


mysql_connect('localhost',$usuario,$password);
@mysql_select_db($database) or die( "Unable to select database");

mysql_query("DELETE FROM noticias WHERE id = $id");


mysql_close();

include ("page2.php");

?>


For uptadte I use:

Code: Select all

<?

$e_titulo = $titulo;
$e_cuerpo = $cuerpo;
$id = $HTTP_GET_VARS["noticia"];
$usuario="******";
$password="*****";
$database="****";

mysql_connect(localhost,$usuario,$password);
@mysql_select_db($database) or die( "Unable to select database");

mysql_query("UPDATE noticias SET titulo = '$e_titulo', texto = '$e_cuerpo' WHERE id =$id");

mysql_close();

include ("page4.php");


?>




I think that the problem comes when I use WHERE because the updating runs perfect if I don´t use the WHERE sentence but it updates all the table and I want to update only one register which has $id like id value.

I am in redhat server and I am so desperate! Thx and help please![/code]
netsheik
Newbie
 
Posts: 1
Joined: Thu Jul 07, 2005 5:17 pm

Postby dillona_aix » Thu Oct 06, 2005 3:30 am

Your $id is set incorrectly. The proper code is:
Code: Select all
$id = $HTTP_GET_VARS['noticia'];

Notice the single quotes. :D
There are 10 types of people in this world, those who understand binary and those who don't.
User avatar
dillona_aix
Moderator
Moderator
 
Posts: 185
Joined: Sun Sep 11, 2005 9:05 pm
Location: USA

Postby DenisF » Thu Oct 06, 2005 6:24 pm

Why are you defining user, pass and db with variables?

waste of code if your script is THAT short, and you use only one connection...
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell

Postby zoli » Thu Oct 06, 2005 10:18 pm

hi,

I would try my sql statement in phpmysqladmin and all other variables would write out - even the whole update and insert string.

This really helps.
Regards,
Z
---
Zoltan Arpadffy
zoli
Forum Admin
Forum Admin
 
Posts: 785
Joined: Mon Sep 30, 2002 1:27 am
Location: Stockholm, Sweden


Return to Troubleshooting

Who is online

Users browsing this forum: Google [Bot] and 11 guests

cron