• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Check it ($_POST-$_GET)

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Reaction score
72
Location
Poland
Im trying to do something like a config editor or content editor..

Atm i just found

WORKING:

PHP:
<h2>Input Only</h2>
<form method="post">
id:<br>
<input type="text" name = "id" size="30"> <br>
value:<br>
<input type="text" name = "value" size="30"> <br>
name:<br>
<input type="text" name = "name" size="30"> <br>
<input type="submit" value="dodaj dane"> <br>
</form>
</body>
</html>

<?php
$baza = "mod";
$tabela = "k_injection";
$connection = mysql_connect ("localhost","root","");
$wybierz = mysql_select_db ($baza,$connection);

@$id=mysql_real_escape_string($_POST['id']);
@$value=mysql_real_escape_string($_POST['value']);
@$name=mysql_real_escape_string($_POST['name']);

$wstaw = "INSERT INTO $tabela (id, value, name) VALUES ('$id','$value','$name')";
$rezultat = mysql_query($wstaw,$connection);
if ($rezultat) {
echo "Do tabeli dodano dane:
<b>ID:</b> <i>$id</i><br>
<b>NAME:</b> <i>$name</i><br>
<b>VALUE:</b> <i>$value</i><br>";
}
else {
echo "Error";
}
?>

I want it also that it could read the values from the database as a input then i could edit it and change.


Could any one create a simply example?
 
Last edited:
I have 2 problems

1. Display value in a field

$val = $SQL->QUERY ("SELECT * FROM $tabela; WHERE `id` = 1' ") ;

<input type="text" name = "name" size="30" value="<?PHP ECHO $val['name'] ?>"> <br>

Fatal error: Cannot use object of type PDOStatement as array in D:\xampp\xampp\htdocs\trunk.r123\system\pages\config.php on line 18

2. Error

Each time i refresh the page it addes VALUES (0,0,0) in $table rofl :D
 
You used object as an array. You should use method which will fetch the data from that. I don't know which one you use in PDO, but in other ones are: fetch_array(); result_array() etc
 
Do it works from PDO ?
Fatal error: Call to undefined method PDOStatement::result_array() in D:\xampp\xampp\htdocs\trunk.r123\system\pages\config.php on line 7


Full code

PHP:
<?PHP
$ots = POT::getInstance();
$ots->connect(POT::DB_MYSQL, connection());
$SQL = POT::getInstance()->getDBHandle(); 
require ('config.php');
$tabela = "k_injection";
$val = $SQL->QUERY ("SELECT * FROM $tabela; WHERE `id` = 1' ")->result_array();
?>


<h2>Input Only</h2>
<form method="post">
id:<br>
<input type="text" name = "id" size="30" value="Cos"> <br>
value:<br>
<input type="text" name = "value" size="30" value="Cos"> <br>
name:<br>
<input type="text" name = "name" size="30" value="<?PHP ECHO $val['name'] ?>"> <br>
<input type="submit" value="Edit"> <br>
</form>
</body>
</html>

<?php
$baza = "mod";

$connection = mysql_connect ("localhost","root","");
$wybierz = mysql_select_db ($baza,$connection);

@$id=mysql_real_escape_string($_POST['id']);
@$value=mysql_real_escape_string($_POST['value']);
@$name=mysql_real_escape_string($_POST['name']);

$wstaw = "INSERT INTO $tabela (id, value, name) VALUES ('$id','$value','$name')";
$rezultat = mysql_query($wstaw,$connection);
if ($rezultat) {
echo "Do tabeli dodano dane:
<b>ID:</b> <i>$id</i><br>
<b>NAME:</b> <i>$name</i><br>
<b>VALUE:</b> <i>$value</i><br>";
}
else {
echo "Error";
}
?>
 
Back
Top