Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql and update has no effect

Status
Not open for further replies.
Sep 5, 2004
55
CH
Hi together

I use the following script to update records a in mysql DB, but if made some changes within the webform and press "Aenderungen uebernehmen" nothing happens and the changes won't be taken

any ideas?

----------------------------------------------------------

<html>
<head>
<title> Swiss Protection Guard GmbH </title>
</head>
<link href=" rel="stylesheet" type="text/css"/>
<body bgcolor=#BEE7AD>

<?php
$benutzer= "ea";
$passwort= "dbuser";
$db = "protection";
$link = mysql_connect ( "localhost", $benutzer, $passwort ) ;
if ( ! $link )
die ( " Keine Verbindung zum MY SQL Server!" );
mysql_select_db ( $db, $link )
or die ( " Konnte Datenbank \"$db\" nicht öffnen !:
".mysql_error() );

if ( isset ($id) && isset ( $Datum ) && isset ( $Ort ) && isset ( $Einsatzzeit ) && isset ( $Tenue ) && isset ( $Auftrag ) && isset ( $Einsatzleiter ) && isset( $Sicherheitsangestellte) )
{
$anfrage = "UPDATE mos_mosform_formdata_1 SET Datum='$Datum', Ort='$Ort', Einsatzzeit='$Einsatzzeit', Tenue='$Tenue' , Auftrag='$Auftrag', Einsatzleiter='$Einsatzleiter', Sicherheitsangestellte='$Sicherheitsangestellte' where id=$id";
$ergebnis = mysql_query ( $anfrage ) ;
if ( ! $ergebnis )
die ("Aenderungen fehlgeschlagen: ".mysql_error());
print "<font color=#0000000><h1>Einsatz geändert!: ".mysql_affected_rows()."Datensatz geandert</h1></font>";
}
?>
<form action="<? print $PHP_SELF ?>" method="POST">
<select name="id">
<?
$ergebnis = mysql_query ( "SELECT id, Datum, Ort, Einsatzzeit, Tenue, Auftrag, Einsatzleiter, Sicherheitsangestellte from mos_mosform_formdata_1" );
while( $datensatz = mysql_fetch_object ( $ergebnis ) )
{
print "<OPTION VALUE=\"$datensatz->id\"";
if ( isset($id) && $id == $datensatz->id )
print "Datensatz ausgewaehlt";
print "> $datensatz->Datum\n";
print "> $datensatz->Ort\n";
print "> $datensatz->Einsatzzeit\n";
print "> $datensatz->Einsatzzeit\n";
print "> $datensatz->Tenue\n";
print "> $datensatz->Auftrag\n";
print "> $datensazt->Einsatzleiter\n";
print "> $datensatz->Sicherheitsangestellte\n";
}
mysql_close ( $link );
?>
</select>
<input type="textarea" name="Datum">
<input type="textarea" name="Ort">
<input type="textarea" name="Einsatzzeit">
<input type="textarea" name="Tenue">
<input type="textarea" name="Auftrag">
<input type="textarea" name="Einsatzleiter">
<input type="textarea" name="Sicherheitsangestellte">
<input type="submit" value="Aenderungen uebernehmen">
</form>


print "<font color=#EE82EE><strong><center><a href=javascript:top.close()>Fenster schliessen</font></strong></center>";

</body>
</html>
----------------------------------------------------------

î use this script on a redhat 7.2 Linux Server with Apache 2.52 and mysql 3.23.41 and PHP 4.3.9

all mysql necessary libs are installed and compiled, is there maybe a little setting which i can modified (perhaps in the php.ini) to make this script working fine

thanks for your help

best regards

E.Altherr
 
Print the query string your script produces.

Examine it. Does it look well-formed?

Copy that query, paste it into your preferred MySQL admin tool, then run it. Does it work from there?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
ok how can i print out the query?

print $ergebnis....

or so?

if tried but nothing happens, neither a error...



 
These two lines:

$anfrage = "UPDATE mos_mosform_formdata_1 SET Datum='$Datum', Ort='$Ort', Einsatzzeit='$Einsatzzeit', Tenue='$Tenue' , Auftrag='$Auftrag', Einsatzleiter='$Einsatzleiter', Sicherheitsangestellte='$Sicherheitsangestellte' where id=$id";
$ergebnis = mysql_query ( $anfrage ) ;

Tells me that the script is putting the query into the variable $anfrage. Perform

print $anfrage;
exit;

in your script.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
ok
i tried the Update Statement within the MYSQL Control Center, and it works, so i think it is a problem between php and mysql (it seems the can't communicate together)

--> the print command produced no effect, except i place
the print at the following line:

$ergebnis = mysql_query ( $anfrage ) ;

something happens, but no changes to the recordset, the Browser Page is then empty?!

very strange
 
I don't think you understand the exact process I'm trying to describe.

You want to test the exact query string produced by your code, not the query string you think your code is producing. It is necessary to output then copy-and-paste the query string from your browser to your MySQL admin tool.

If changing the lines:

Code:
$anfrage = "UPDATE mos_mosform_formdata_1 SET Datum='$Datum', Ort='$Ort', Einsatzzeit='$Einsatzzeit', Tenue='$Tenue' , Auftrag='$Auftrag', Einsatzleiter='$Einsatzleiter', Sicherheitsangestellte='$Sicherheitsangestellte' where id=$id";
$ergebnis = mysql_query ( $anfrage ) ;
  if ( ! $ergebnis )
  die ("Aenderungen fehlgeschlagen: ".mysql_error());
  print "<font color=#0000000><h1>Einsatz geändert!: ".mysql_affected_rows()."Datensatz geandert</h1></font>";

to read:

Code:
$anfrage = "UPDATE mos_mosform_formdata_1 SET Datum='$Datum', Ort='$Ort', Einsatzzeit='$Einsatzzeit', Tenue='$Tenue' , Auftrag='$Auftrag', Einsatzleiter='$Einsatzleiter', Sicherheitsangestellte='$Sicherheitsangestellte' where id=$id";
print $anfrage;
exit;
$ergebnis = mysql_query ( $anfrage ) ;
  if ( ! $ergebnis )
  die ("Aenderungen fehlgeschlagen: ".mysql_error());
  print "<font color=#0000000><h1>Einsatz geändert!: ".mysql_affected_rows()."Datensatz geandert</h1></font>";

does not output your query string, then there is something wrong in your code. It will not actually update the database, as the exit statement occurs before your invocation of mysql_query().

Also, do a "View source" on the page. It may be that due to mismatched HTML tags, the query string is not visible.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
hm.. maybe i think it coud also be, that the bundled mysql library which came with php4.3.9 (if i do a ./configure --with-mysql and give no path to the header files the compiler will take the bundled lib) had not the same functionalty as the original lib's from mysql

--> I hate this dammed "RedHat" RPMS's you never know where the files are, after installing them.... :-(


anyway, i will try also Perl to see, if it works not

 
It's not difficult at all to know what modules are available to a PHP installation. Just create a script which consists of:

Code:
<?php
phpinfo();
?>

And you will learn a great deal about your PHP installation.

However, unless this section of your script:

Code:
$link    = mysql_connect ( "localhost", $benutzer, $passwort ) ;
if ( ! $link )
   die ( " Keine Verbindung zum MY SQL Server!" );

outputs an error, MySQL functionality is available to your PHP installation. Don't blame the installation until you have exhausted all other possibilities, like simple typographic errors in your own code.

For example, this section of your script:

Code:
if ( isset ($id) &&  isset ( $Datum ) && isset ( $Ort ) && isset ( $Einsatzzeit ) && isset ( $Tenue ) && isset ( $Auftrag ) && isset ( $Einsatzleiter ) && isset( $Sicherheitsangestellte) )
   {
$anfrage = "UPDATE mos_mosform_formdata_1 SET Datum='$Datum', Ort='$Ort', Einsatzzeit='$Einsatzzeit', Tenue='$Tenue' , Auftrag='$Auftrag', Einsatzleiter='$Einsatzleiter', Sicherheitsangestellte='$Sicherheitsangestellte' where id=$id";
$ergebnis = mysql_query ( $anfrage ) ;
  if ( ! $ergebnis )
  die ("Aenderungen fehlgeschlagen: ".mysql_error());
  print "<font color=#0000000><h1>Einsatz geändert!: ".mysql_affected_rows()."Datensatz geandert</h1></font>";
  }

is a conditional statement. Keeping in mind that variable names in PHP are case-sensitive, could your condition be failing?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
thanks to all, it works now

the problem was the following

cause i turned off (for security reasons)"REGISTER GLOBALS" i need to call all variables like this (found this at mysql.com)

...$POST["varname"] and so on...

 
However: Implement securing of variables!
Make a simple function, as the one on php.net (as I provided above), which you then can call:

$var = securevar($var);

it's easier to do it while developing, than having to update x number of scripts.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top