Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z usuwaniem i dodawaniem
ultramega-ok
post
Post #1





Grupa: Zarejestrowani
Postów: 29
Pomógł: 0
Dołączył: 31.01.2005
Skąd: stąd :)

Ostrzeżenie: (0%)
-----


Mam taką małą bazę dla celów ćwiczebnych (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) ale niestety cos mi nie działa przy usuwaniu rekordów. Wyświetla się taki komunikat:
---------------------------------------
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
--------------------------------------------------------------------------------
Apache/1.3.23 Server at localhost Port 80
---------------------------------------

Na dodatek jeśli dodam nową osobę do bazy, to po odświeżeniu strony ten sam rekord dodaje się po raz drugi, po następnym odświeżeniu jeszcze raz i tak w kółko - jak temu zapobiec? (IMG:http://forum.php.pl/style_emoticons/default/blink.gif)

---------------------------------------
Oto kod:

<?php
mysql_connect( "localhost", "root", "")
or die( "nie mozna sie polaczyc z mysql.");
mysql_select_db( "bazaa" )
or die( "nie mozna wybrac bazy.");

if( $co == 'dodaj' )
{
if( $imie && $nazwisko && $telefon )
{
$query = "INSERT INTO book (nr, imie, nazwisko, telefon) " ;
$query .= "VALUES ('', '$imie', '$nazwisko', '$telefon');" ;
$baz = mysql_query( $query );
/* $baz= mysql_query( "INSERT INTO book (nr, imie, nazwisko, telefon) VALUES ('', '$imie', '$nazwisko', '$telefon');" );*/
}
}
elseif( $co == 'skasuj') {
$baz = mysql_query
("DELETE FROM book WHERE nr='$id' LIMIT 1;")
or die("blad w kasowaniu");
}

$baz = mysql_query("SELECT * FROM book;")
or die("blad w zapytaniu.");

print( "<table border=0 cellpadding=5 cellspacing=2 bgcolor=teal>");
print( "<tr><td><b>imie</b></td><td><b>nazwisko</b></td>");
print( "<td><b>telefon</b></td></tr>\n");
while( $rekord = mysql_fetch_array( $baz ))
{
$id = $rekord[0];

print( "<tr><td>$rekord[1]</td><td>$rekord[2]</td><td>$rekord[3]</td>");
print( "<td><a href=\"book.php?co=skasuj&id=$id\">skasuj</a></td></tr>\n" );
}
print "</table>" ;
print '<form method="get">Nowy rekord:' ;
print '<input type="hidden" name="co" value="dodaj"><table>' ;
print '<tr><td>imie:</td><td><input type="text" name="imie"></td></tr>' ;
print '<tr><td>nazwisko:</td><td><input type="text" name="nazwisko"></td></tr>' ;
print '<tr><td>telefon:</td><td><input type="text" name="telefon"></td></tr></table>' ;
print '<input type="submit" value="dodaj"></form>' ;
?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Vertical
post
Post #2





Grupa: Zarejestrowani
Postów: 848
Pomógł: 0
Dołączył: 7.07.2004
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $baz= mysql_query( &#092;"INSERT INTO book (nr, imie, nazwisko, telefon) VALUES ('', '$imie', '$nazwisko', '$telefon');\" )
  3. ?>

Może powinno być:
  1. <?php
  2. $baz= mysql_query( &#092;"INSERT INTO book VALUES (NULL, '$imie', '$nazwisko', '$telefon');\" )
  3. ?>

Co drugiego problemu to zrób tak, żeby nie można było dodać dwóch takich samych użytkowników:
  1. <?php
  2. //łączenie do bazy
  3. $sql = &#092;"SELECT * FROM tabela WHERE imie = '$imie' AND nazwisko = '$nazwisko' AND telefon = '$telefon'\";
  4. $result = mysql_query($sql);
  5. $row_count = mysql_num_rows($result);
  6. if($row_count != 0)
  7. {
  8. echo (&#092;"Nie można dodać! Podane informacje już są w bazie!n\");
  9. } else
  10. {
  11. //dodawanie do bazy
  12. }
  13. ?>

Poza tym jest jeszcze trochę innych błędów:
1.
Cytat
  1. <?php
  2. if( $imie && $nazwisko && $telefon )
  3. ?>

Powinno być:
  1. <?php
  2. if( isset ($imie && $nazwisko && $telefon ) )
  3. ?>

2. Używaj BBcode!

Ten post edytował Vertical 31.01.2005, 14:23:59
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 18:43