
nie wiem dlaczego moja część kodu nie działa. Gdzieś musi byćbłąd i to pewnie trywialny.
to co ja zmieniłem dałem poza kodem.
sktypt miał na celu dopisywać w tabeli chat godzine postu autora i treść. I tą funkcję sprawował doskonale

ze swojej strony chciałem dodać sprawdzanie czy dany użytkownik jest na liście a jeżeli nie to nie pozwolić zamieścić takiego postu.
stworzyłem więc tabelę "lista" i kolumnę użytkownik i tam wpisałem np siebie.. ale nadal mogą pisać wszyscy. Dlaczego? Co jest źle??
Kod
<?
$name = $_POST["n"]; //name from the form in index.html
$text = $_POST["c"]; //comment from the form in index.html
//some weird conversion of the data inputed
$name = str_replace("\'","'",$name);
$name = str_replace("'","\'",$name);
$text = str_replace("\'","'",$text);
$text = str_replace("'","\'",$text);
$text = str_replace("---"," - - ",$text);
$name = str_replace("---"," - - ",$name);
//the message is cut of after 500 letters
if (strlen($text) > 500) {
$text = substr($text,0,500);
}
//to allow for linebreaks a space is inserted every 50 letters
$text = preg_replace("/([^\s]{50})/","$1 ",$text);
//the name is shortened to 30 letters
if (strlen($name) > 30) {
$name = substr($name, 0,30);
}
//only if a name and a message have been provides the information is added to the db
if ($name != '' && $text != '') {
addData($name,$text); //adds new data to the database
getID(50); //some database maintenance
}
//establishes the connection to the database
function getDBConnection () {
include('db.php'); //contains the given DB setup $db, $server, $user, $pass
$conn = mysql_connect($server, $user, $pass);
if (!$conn) {
// echo "Connection to DB was not possible!";
end;
}
if (!mysql_select_db($db, $conn)) {
// echo "No DB with that name seems to exist at the server!";
end;
}
return $conn;
}
$name = $_POST["n"]; //name from the form in index.html
$text = $_POST["c"]; //comment from the form in index.html
//some weird conversion of the data inputed
$name = str_replace("\'","'",$name);
$name = str_replace("'","\'",$name);
$text = str_replace("\'","'",$text);
$text = str_replace("'","\'",$text);
$text = str_replace("---"," - - ",$text);
$name = str_replace("---"," - - ",$name);
//the message is cut of after 500 letters
if (strlen($text) > 500) {
$text = substr($text,0,500);
}
//to allow for linebreaks a space is inserted every 50 letters
$text = preg_replace("/([^\s]{50})/","$1 ",$text);
//the name is shortened to 30 letters
if (strlen($name) > 30) {
$name = substr($name, 0,30);
}
//only if a name and a message have been provides the information is added to the db
if ($name != '' && $text != '') {
addData($name,$text); //adds new data to the database
getID(50); //some database maintenance
}
//establishes the connection to the database
function getDBConnection () {
include('db.php'); //contains the given DB setup $db, $server, $user, $pass
$conn = mysql_connect($server, $user, $pass);
if (!$conn) {
// echo "Connection to DB was not possible!";
end;
}
if (!mysql_select_db($db, $conn)) {
// echo "No DB with that name seems to exist at the server!";
end;
}
return $conn;
}
//w tej samej bazie stworzyłem wcześniej tabele lista
//na początku dałem te 2 linijki poniżej
// Check if the username exists
//$usernameinuse = mysql_query("SELECT * FROM lista WHERE uzytkownik = '$name'");
// $isusernameinuse = mysql_num_rows($usernameinuse);
//ale potem zmieniłem je na taki wpis jak tutaj
$sql = "SELECT * FROM lista WHERE uzytkownik = '$name'";
$conn = getDBConnection();
$results = mysql_query($sql, $conn);
//tego if'a chyba wogule nie wykonuje tylko idzie dalej nieważne pod jakim nickiem wystąpi post
// If username not exists then exit script
$isusernameinuse = mysql_num_rows($results);
if ($isusernameinuse == 0) {
exit;
}
Kod
//adds new data to the database
function addData($name,$text) {
$sql = "INSERT INTO chat (time,name,text) VALUES (NOW(),'".$name."','".$text."')";
$conn = getDBConnection();
$results = mysql_query($sql, $conn);
if (!$results || empty($results)) {
//echo 'There was an error creating the entry';
end;
}
}
//returns the id of a message at a certain position
function getID($position) {
$sql = "SELECT * FROM chat ORDER BY id DESC LIMIT ".$position.",1";
$conn = getDBConnection();
$results = mysql_query($sql, $conn);
if (!$results || empty($results)) {
//echo 'There was an error creating the entry';
end;
}
while ($row = mysql_fetch_array($results)) {
$id = $row[0]; //the result is converted from the db setup (see initDB.php)
}
if ($id) {
deleteEntries($id); //deletes all message prior to a certain id
}
}
//deletes all message prior to a certain id
function deleteEntries($id) {
$sql = "DELETE FROM chat WHERE id < ".$id;
$conn = getDBConnection();
$results = mysql_query($sql, $conn);
if (!$results || empty($results)) {
//echo 'There was an error deletig the entries';
end;
}
}
?>
nie wiem czy to jest czytelne i przejrzyste mam nadzieję że wyjaśniłem pój problem. Przypominam że w kodzie zawarłem orginalny kod php przed zmianą a moja zmiana jest opisana pomiędzy częściami i dokładnie w tamtym miejscu ją wstawiłem. proszę o pomoc.