Help me !!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Help me !!!

Post by lapicki »

$sSQL="Update Table1 Set Nombre=$nom".$size." where Legajo='024'";


With this instruction desire to record the content of the field nom,
but does not work. Somebody can say to me if there is a syntax error?
craigh
Forum Newbie
Posts: 19
Joined: Sun May 19, 2002 2:50 pm

Post by craigh »

$sSQL="Update Table1 Set Nombre=$nom".$size." where Legajo='024'"

is $nom a variable? is $size a variable?

how about:

$sSQL="Update Table1 Set Nombre=".$nom.$size." where Legajo='024'"

??
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you get an error or what happens/doesn't happen that shouldn't/should happen?

Mac
craigh
Forum Newbie
Posts: 19
Joined: Sun May 19, 2002 2:50 pm

Re: Help me !!!

Post by craigh »

lapicki wrote:$size it is a variable that indicates the number of row within the table

$nom it is the entered value to modify the name of that field, from another form
OK - so what are the answers to the previous post?
craigh
Forum Newbie
Posts: 19
Joined: Sun May 19, 2002 2:50 pm

Re: Help me !!!

Post by craigh »

lapicki wrote:

Code: Select all

<?php
MySQL_CONNECT($hostname,$username,$password) or DIE("DATABASE NO RESPONDE"); 
mysql_select_db($dbName)or DIE("Tabla no disponible"); 
$result=mysql_db_query("auth","select * from tabla1"); 
$number = MySQL_NUM_ROWS($result); 
$size = 1; 
while($size <= $number) 
{ 
$sSQL="Update tabla11 Set Nombre=$nom".$size."  where Legajo='024'"; 
echo $sSQL; 
mysql_db_query("auth",$sSQL)or DIE($sSQL .' :'.mysql_error()); 
$size++; 
} 
mysql_close;
?>
You sent this to me via PM. What is the error that is produced?
lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Re: Help me !!!

Post by lapicki »

craigh wrote:
lapicki wrote:

Code: Select all

<?php
MySQL_CONNECT($hostname,$username,$password) or DIE("DATABASE NO RESPONDE"); 
mysql_select_db($dbName)or DIE("Tabla no disponible"); 
$result=mysql_db_query("auth","select * from tabla1"); 
$number = MySQL_NUM_ROWS($result); 
$size = 1; 
while($size <= $number) 
{ 
$sSQL="Update tabla11 Set Nombre=$nom".$size."  where Legajo='024'"; 
echo $sSQL; 
mysql_db_query("auth",$sSQL)or DIE($sSQL .' :'.mysql_error()); 
$size++; 
} 
mysql_close;
?>
You sent this to me via PM. What is the error that is produced?

Two types of errors take place:
1) You have an error in your SQL syntax near '1 where Legajo='024'' at line 1
2) If the instruction is: Set Nombre=$nom".$size."
it records I number of row, is to say $size, instead of recording
the content of the field Nombre
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

When you echo $sSQL what do you get?

Mac
lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Post by lapicki »

twigletmac wrote:When you echo $sSQL what do you get?

Mac
Print the value of $size and the one of the field does not name
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Are $nom and $size both numbers and they are both being printed correctly when you echo $sSQL?

Mac
lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Post by lapicki »

$size prints it correctly

$nom would have to be the name corresponding to the row that
indicates $size
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

So is $nom - a string (text or mixture of text and numbers) or a number?

Could you please post exactly what you get when you echo $sSQL - the whole SQL query as produced by your code.

Mac
lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Post by lapicki »

Update Personal1 Set Nombre=''1 where Legajo='024'Update Personal1 Set Nombre=''1 where Legajo='024' :You have an error in your SQL syntax near '1 where Legajo='024'' at line 1
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Code: Select all

Update Personal1 Set Nombre=''1 where Legajo='024'
Where do the single quotes come from after the Nombre= bit in the statement?

Your statement is failing because of those single quotes them - you need to have either:

Code: Select all

UPDATE Personal1 SET Nombre = '1' WHERE Legajo='024'
or if Nombre will always be a number:

Code: Select all

UPDATE Personal1 SET Nombre = 1 WHERE Legajo='024'
for the query to be syntactically correct.

It also doesn't look as though $nom contains anything.

Mac
lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Post by lapicki »

$sSQL="Update Personal1 Set Nombre=$nom".$size." where Legajo='024'";


echo $sSql:

Update Personal1 Set Nombre=1 where Legajo='024'

I need that instead of printing 1, she prints the name entered a
previous form
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you tried:

Code: Select all

$sSQL = "Update Personal1 Set Nombre='".$_POST['nom'].$size."' where Legajo='024'";
You may need to read:
viewtopic.php?t=511

Mac
Post Reply