Jump to content
soimuletzu1

Problema la insert in tabel

Recommended Posts

Posted

<form method="post" action="adauga.php">
<table cellpadding="4" cellspacing="0">
<tr>
<td>Server-Name:</td>
<td><input type="text" name="name" size="30" /></td>
</tr>
<tr>
<td>Game:</td>
<td><input type="text" name="game" size="2" maxlength="2" value="cs"></td>
</tr>
<tr>
<td>Server IP:</td>
<td><input type="text" name="ip" size="30" /></td>
</tr>
<tr>
<td>Server Port:</td>
<td><input type="text" name="port" size="30" /></td>
</tr>
<tr>
<td>Server Query:</td>
<td><input type="text" name="query" size="30" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="ADAUGA" /></td>
</tr>
</table>
</form>

<?php

if (isset($_POST['name']) && isset($_POST['game']) && isset($_POST['ip']) && isset($_POST['port']) && isset($_POST['query'])) {
// Se filtreaza datele pt. eliminare posibile spatii exterioare si tag-uri
$_POST = array_map("trim", $_POST);
$_POST = array_map("strip_tags", $_POST);

// Se verifica daca "magic_quotes_gpc()" este setat ON
// Daca e ON, se aplica stripslashes() pentru a nu se adauga de 2 ori '\' cand va fi aplicat "mysql_real_escape_string()"
if(get_magic_quotes_gpc()) { $_POST = array_map("stripslashes", $_POST); }

// Se verifica daca au fost completate corect toate campurile
// Daca au fost completate le preia in variabile, in caz contrar seteaza o variabila tip Array cu mesaj de eroare

// Verifica daca Numele are cel putin 5 caractere si maxim 50
if(strlen($_POST['name'])>5 && strlen($_POST['name'])<50) $name = $_POST['name'];
else $eroare[] = 'Error Name : 5 and 50 characters';

// Verifica daca GAME are cel putin 2 si cel mult 3
if(strlen($_POST['game'])>1 && strlen($_POST['game'])<3) $game = $_POST['game'];
else $eroare[] = 'Error Game : 2 and 3 characters';

// Ip intre 5 si 25 de caractere
if(strlen($_POST['ip'])>5 && strlen($_POST['ip'])<25) $ip = $_POST['ip'];
else $eroare[] = 'Error IP : 5 and 25 characters';

// Verifica daca Portul are cel putin 5 caractere si maxim 6
if(strlen($_POST['port'])>4 && strlen($_POST['port'])<6) $port = $_POST['port'];
else $eroare[] = 'Error Port : 5 and 6 characters';

// Verifica daca Query are cel putin 5 caractere si maxim 6
if(strlen($_POST['query'])>4 && strlen($_POST['query'])<6) $query = $_POST['query'];
else $eroare[] = 'Error Query : 5 and 6 characters';

if (!isset($eroare)) {

$username="user";
$password="user";
$database="test";
$localhost = "localhost";
$con = mysql_connect("$localhost","$username","$password");
if (!$con)
{
die('Nu sa putut conecta la baza de date: ' . mysql_error());
}
mysql_select_db($database, $con);

// Se aplica functia de filtrare mysql_real_escape_string()
$name = mysql_real_escape_string($name);
$game = mysql_real_escape_string($game);
$ip = mysql_real_escape_string($ip);
$port = mysql_real_escape_string($port);
$query = mysql_real_escape_string($query);


// Acum se adauga mai in siguranta aceste date in MySQL
$sql = "INSERT INTO `ws_a96_phgstats` (`name`, `game`, `ip`, `port`, `query`) VALUES ('$name', '$game', '$ip', '$port', '$query')";
if (mysql_query($sql, $conn)) {
$mesaj = '<font color="blue">Serverul a fost adaugat</font>';
$name = ''; $ip = '';
}
else $mesaj = '<font color="red">Serverul nu a putut fi adaugat '. mysql_error(). '</font>';

mysql_close($conn);
}
else $mesaj = '<font color="red">'. implode('<br />', $eroare). '</font>';
}

echo $mesaj;
?>

am urmatorul cod care imi insereaza intr-un tabel campurile de mai sus ... da primesc o eroare cand il, rulez :


Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\adauga.php on line 87

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\adauga.php on line 93
Serverul nu a putut fi adaugat

Stiti careva unde am gresit???

Posted (edited)

posteaza exact linia 87 si 93 te rugam

daca linia 87 este mysql_query($sql, $conn) atunci incearca mysql_query($sql)

daca linia 93 este mysql_close($conn) atunci incearca mysql_close($con)

Edited by tiodr
Posted

Ca sa nu mai fac un nou topic voi intreba tot aici !

img=http://img140.imageshack.us/img140/5290/photo1twc.jpg

Cum as putea sa separ partea <form> de partea cu imagini dar totusi sa le am in acelasi fisier? Adica partea de jos de la imagine + codurile bb/html sa apara dupa ce dau Check server , ms

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...