Update all fields

Update all fields

am 08.02.2006 21:17:46 von UKuser

Hi Guys,

I am playing with a PHP/MySQL script at
http://nana46.coconia.net/test4.php

What I have done is placed every record from the table in an input box,
so that each box can be edited. I've given each field a unique name,
and then assigned the overall name in the update query. However when I
update, it does update everything but not with the information I've
typed in. In short I'm hoping for users to be able to type in any
boxes/fields, click Update and the record update, rather than editing a
record at a time.

Any thoughts would be great.

Thanks

A

I am using the following code:


test 4


function check_mysql()
{
if (mysql_errno() > 0)
{
die("
MySQL error " . mysql_errno() . ": " .
mysql_error());
}
}

$db = mysql_connect("coconia.net", "nana46_nana46", "hello");
if (!$db)
{
die("Failed to open connection to MySQL server.");
}

mysql_select_db("nana46_nana46");
check_mysql();

$requete = "SELECT id,lowerval,upperval,result FROM fig_lookup";
$resulta = mysql_query($requete) or die (mysql_error());

if($mode == "Update")
{
$query = "UPDATE fig_lookup SET lowerval ='$Lid', upperval='Uid',
result='$Rid'";
$req = mysql_query($query);
check_mysql();
}

echo '';

$edit = "Edit record";

echo "
";
echo "";
echo "";
echo "";
echo "";
echo "";

while ($line = mysql_fetch_array($resulta, MYSQL_ASSOC))
{
$id = $line["id"];
{
$num = "0.$id";
$Lid = "1.$id";
$Uid = "2.$id";
$Rid = "3.$id";

$clinec = "\n");

// Affichage des champs sur une line
echo $clinec.$line["id"].">";
echo $clined.$line["lowerval"].">";
echo $clinee.$line["upperval"].">";
echo $clinef.$line["result"].">";

}

echo "";
echo "
idLowervalUppervalResult ";
echo ("
HREF=\"test5.php?id=$id\">$edit
";
?>


Re: Update all fields

am 09.02.2006 02:52:48 von Tyrone Slothrop

On 8 Feb 2006 12:17:46 -0800, "UKuser" wrote:

>Hi Guys,
>
>I am playing with a PHP/MySQL script at
>http://nana46.coconia.net/test4.php
>
>What I have done is placed every record from the table in an input box,
>so that each box can be edited. I've given each field a unique name,
>and then assigned the overall name in the update query. However when I
>update, it does update everything but not with the information I've
>typed in. In short I'm hoping for users to be able to type in any
>boxes/fields, click Update and the record update, rather than editing a
>record at a time.
>
>Any thoughts would be great.
>
>Thanks
>
>A
>
>I am using the following code:
>
>
>test 4
>


> >function check_mysql()
>{
> if (mysql_errno() > 0)
> {
> die("
MySQL error " . mysql_errno() . ": " .
>mysql_error());
> }
>}
>
>$db = mysql_connect("coconia.net", "nana46_nana46", "hello");
>if (!$db)
>{
> die("Failed to open connection to MySQL server.");
>}
>
>mysql_select_db("nana46_nana46");
>check_mysql();
>
>$requete = "SELECT id,lowerval,upperval,result FROM fig_lookup";
>$resulta = mysql_query($requete) or die (mysql_error());
>
>if($mode == "Update")
>{
> $query = "UPDATE fig_lookup SET lowerval ='$Lid', upperval='Uid',
>result='$Rid'";
> $req = mysql_query($query);
> check_mysql();
>}
>
>echo '';
>
>$edit = "Edit record";
>
>echo "
";
>echo "";
>echo "";
>echo "";
>echo "";
>echo "";
>
>while ($line = mysql_fetch_array($resulta, MYSQL_ASSOC))
>{
> $id = $line["id"];
> {
> $num = "0.$id";
> $Lid = "1.$id";
> $Uid = "2.$id";
> $Rid = "3.$id";
>
> $clinec = "\n");
>
> // Affichage des champs sur une line
> echo $clinec.$line["id"].">";
> echo $clined.$line["lowerval"].">";
> echo $clinee.$line["upperval"].">";
> echo $clinef.$line["result"].">";
>
>}
>
>echo "";
>echo "
idLowervalUppervalResult";
> echo ("
>HREF=\"test5.php?id=$id\">$edit
";
>?>
>
>

>

Don't worry about assigning unique names to the form fields. This
complicaters your code and, by the time you get it working, will make
you crazy. Instead, use arrays.

Rather than trying to figure out what fields are which, I am just
going to assign field name arbitrarily:

while ($l = mysql_fetch_array($resulta, MYSQL_ASSOC))
{ ?>



} //end display
?>

for ($i=0; $i {
mysql_query ("UPDATE table SET f2='{'$_POST['f2'][$i]}',
f3='{'$_POST['f3'][$i]}' WHERE f1='{'$_POST['f1'][$i]}'");
}
?>

Re: Update all fields

am 09.02.2006 20:29:40 von UKuser

My code now reads:


test 4


function check_mysql()
{
if (mysql_errno() > 0)
{
die("
MySQL error " . mysql_errno() . ": " .
mysql_error());
}
}

$db = mysql_connect("coconia.net", "nana46_nana46", "hello");
if (!$db)
{
die("Failed to open connection to MySQL server.");
}

mysql_select_db("nana46_nana46");
check_mysql();

$requete = "SELECT id,lowerval,upperval,result FROM fig_lookup";
$resulta = mysql_query($requete) or die (mysql_error());

echo '';

$edit = "Edit record";

echo "
";
echo "";
echo "";
echo "";
echo "";

if($mode == "Update")
{
for ($i=0; $i {
$query = "UPDATE table SET lowerval='{'$_POST['lowerval'][$i]}',
upperval='{'$_POST['upperval'][$i]}', result='{'$_POST['result'][$i]}'
WHERE id='{'$_POST['id'][$i]}'";
$test = mysql_query($query);
}
}

while ($l = mysql_fetch_array($resulta, MYSQL_ASSOC))
{ ?>





} //end display

echo "";
echo "
idLowervalUppervalResult
";
?>




And I'm afraid it doesnt appear to work.

Re: Update all fields

am 09.02.2006 20:44:35 von UKuser

Using this code will show the results (the above won't I'm afraid), but
this displays an error:

for ($i=0; $i {
////LINE 39////// next one
mysql_query ("UPDATE fig_lookup SET
lowerval='{'$_POST['f2'][$i]}',upperval='{'$_POST['f3'][$i]} ',result='{'$_POST['f4'][$i]}'
WHERE id='{'$_POST['f1'][$i]}'");
}
}

while ($l = mysql_fetch_array($resulta, MYSQL_ASSOC))
{ ?>

">
">
">
">
}

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in /home/www/nana46.coconia.net/test4.php on line 39
(line 39 is mysql_query line - marked in code)

Re: Update all fields

am 24.02.2006 00:50:35 von Jim Michaels

"UKuser" wrote in message
news:1139514275.133348.95370@g43g2000cwa.googlegroups.com...
> Using this code will show the results (the above won't I'm afraid), but
> this displays an error:
>
> for ($i=0; $i > {
> ////LINE 39////// next one

try this:

mysql_query ("UPDATE fig_lookup
SET lowerval='$_POST[f2][$i]',
upperval='$_POST[f3][$i]',
result='$_POST[f4][$i]'
WHERE id=$_POST[f1][$i]");


id shouldn't really have quotes on it if it's an integer.

BTW, when you do an UPDATE ... SET with no WHERE, is sets *all* the entire
table.

> }
> }
>
> while ($l = mysql_fetch_array($resulta, MYSQL_ASSOC))
> { ?>
>
> ">
> ">
> ">
> ">
> > }
>
> Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
> `T_NUM_STRING' in /home/www/nana46.coconia.net/test4.php on line 39
> (line 39 is mysql_query line - marked in code)
>