I am able to get data from my form to backend php but how to insert it to MySQL?
Here is my form
<div class="container">
<form class="form-control" method="post" action="save.php">
<div id="input_fields">
<div class="container">
<input type="text" name="name[]" placeholder="name"> <input type="text" name="project[]" placeholder="project"> <button class="btn btn-primary" id="add_field">+</button>
</div>
</div>
<input class="btn btn-primary" type="submit" value="submit">
</form>
</div>
<script>
$(document).ready(function() {
$("#add_field").click(function(e){
e.preventDefault();
$("#input_fields").append('<div class="container"><input type="text" name="name[]" placeholder="name"/> <input type="text" name="project[]" placeholder="project"> <button id="remove" class="btn btn-danger">-</button></div>');
});
$("#input_fields").on("click","#remove", function(e){
e.preventDefault(); $(this).parent('div').remove();
x--;
})
});
</script>
Backend php code Here on foreach I used echo to check data and it show me correct data but it is not inserting to MySQL.
if(isset($_POST["name"]) && isset($_POST["project"])) {
foreach($_POST['name'] as $key => $val) {
$proj = $_POST['project'][$key];
echo "Name ".$val." Project ".$proj;
$insert = "INSERT INTO table_name (column1,colunm2) values ('$val','$proj')";
$result = $conn->query($insert);
}
if($result) {
echo "Data inserted Successfully";
}
}
You can check that there is any error in query. If have then try to fix the following error.
if(!$result) die($conn->error);
Remove this line for now
if($result) {
echo "Data inserted Successfully";
}
and define this code inside loop, just below where foreach loop starts -
$insert = '';
$result = '';
I hope this will help you!
Related
I want to update my data in SQL database but i am facing issues like as you can see i already defined the request method as POST but when i gonna check it, it doesn't work like:
if (
isset($_POST["form"])
) {
...
}
else{ echo "form's method is not set as POST"}
this condition get false and print "form's method is not set as POST".
This is my form HTML
<form name="form" method="post" action="courses.php">
<div class=" mb-3">
<label for="c_name_u" class="form-label">Course Name</label>
<input type="text" class="form-control" name="c_name_u" id="c_name_u" require>
</div>
<div class=" mb-3">
<label for="credit_hours_u" class="form-label">Credite Hours</label>
<input type="text" class="form-control" name="credit_hours_u" id="credit_hours_u" require>
</div>
<a style="text-decoration: none; color: white;" href="courses.php?edit_task=<?php echo $course_id ?>">
<button type="submit" class="btn btn-primary btn-md">
Update Course
</button>
</a>
</form>
and my PHP code is:
<?php
if (isset($_GET['edit_task'])) {
if (
isset($_POST["form"])
) {
$c_name_u = $_POST["c_name_u"];
$credit_hours_u = $_POST["credit_hours_u"];
$course_id = $_GET['edit_task'];
$query = "UPDATE `courses` SET `Course_name` = '$c_name_u', `Credit_hours` = '$credit_hours_u' WHERE `courses`.`Course_id` =" . $course_id;
$update_db = $conn->query($query);
if (!$update_db) {
echo " data is not saved";
}
}
}
?>
Whenever I hit submit button my first name, last name and email are empty even when they are filled up properly so they return red color fonts.
Here is the PHP code:
<?php
if (isset($_POST['submit'])) {
include_once 'dbh.inc.php';
$first = mysqli_real_escape_string($conn, $_POST['first']);
$last = mysqli_real_escape_string($conn, $_POST['last']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$college = mysqli_real_escape_string($conn, $_POST['college']);
$pwd = mysqli_real_escape_string($conn, $_POST['password']);
// Error handlers
$errorfirst=false;
$erroremail=false;
$errorlast=false;
$errorpwd=false;
// Check for empty fields
if (empty($first) || empty($email) || empty($pwd)) {
echo "
<span class='form-error'>*Please check one of the fields before submitting<br></span>
<span class='form-error'>*Please check first name <br></span>
<span class='form-error'>*Please check last name <br></span>
<span class='form-error'>*Please check email <br></span>
";
$errorfirst=true;
$erroremail=true;
} else {
// Check if input characters are valid
if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
echo "<span class='form-error'>*write properly</span>";
$errorfirst=true;
$errorlast=true;
} else {
//Check if email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "<span class='form-error'>*write a proper email</span>";
} else {
$sql = "SELECT * FROM name WHERE user_email='$email'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
echo "<span class='form-error'>This E-mail ID is already existed</span>";
} else {
//Hashing the password
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
// Insert the user into the database
$sql = "INSERT INTO name (id,user_first, user_last, user_email, user_uid, user_pwd) VALUES (NULL,'$first', '$last', '$email', '$uid', '$hashedPwd');";
mysqli_query($conn, $sql);
}
}
}
}
} else {
header("Location: ../signupform.php");
exit();
}
?>
<script type="text/javascript">
$('.first-input,.last-input,.email-input').removeClass('input-error');
var errorfirst="<?php echo '$errorfirst'; ?>";
var errorlast="<?php echo '$errorlast'; ?>";
var erroremail="<?php echo '$erroremail'; ?>";
if (errorfirst==true) {
$('.first-input').addClass('input-error');
}
if (errorlast==true) {
$('.last-input').addClass('input-error');
}
if (erroremail==true) {
$('.email-input').addClass('input-error');
}
if (erroremail==false && errorfirst==false && errorlast==false) {
$('.first-input,last-input,.email-input').val('');
}
</script>
It is not sending any value to the database. I used jQuery to validate form without refreshing but I think because of jQuery my form is not working
Here is my jQuery code
<script>
$(document).ready(function () {
$('.signup-Form').submit(function(event){
event.preventDefault();
var first=$(".first-input").val();
var last=$(".last-input").val();
var email=$(".email-input").val();
var college=$(".college-input").val();
var password=$(".password-input").val();
var submit=$(".signup-btn").val();
$(".form-message").load("includes/signup.inc.php", {
first:first,
last:last,
email:email,
college:college,
password:password,
submit:submit
})
});
});
</script>
And here is my HTML form
<form class="signup-Form" action="includes/signup.inc.php" method="post">
<div class="first-input">
<input type="text" name="first" placeholder="First Name">
</div>
<div class="last-input">
<input type="text" name="last" value="" placeholder="Last Name">
</div>
<div class="email-input">
<input type="text" name="email" value="" placeholder="E-mail">
</div>
<div class="college-input">
<input type="text" name="college" value="" placeholder="College Name">
</div>
<div class="password-input">
<input type="password" name="password" value="" placeholder="Password">
</div>
<p class="form-message"></p>
<div class="signup-btn">
<button type="submit" name="button">sign-up</button>
</div>
</form>
Help me over this issue and I also don't know about security in PHP forms so you can aslo suggest me some tips over that, I will really appreciate because I am want to be a professional back-end developer and now I am a newbie
Your jQuery uses $(".first-input").val(), but you have class="first-input" on the DIV, not the input.
Either move the class attribute to the inputs, or change the selector to $(".first-input input").val() (and similarly for all the other inputs).
You need to grab the input, not the container
<form class="signup-Form" action="includes/signup.inc.php" method="post">
<div class="first-input">
<input id="first-input" type="text" name="first" placeholder="First Name">
</div>
<div class="last-input">
<input id="last-input" type="text" name="last" value="" placeholder="Last Name">
</div>
<div class="email-input">
<input id="email-input" type="text" name="email" value="" placeholder="E-mail">
</div>
<div class="college-input">
<input id="college-input" type="text" name="college" value="" placeholder="College Name">
</div>
<div class="password-input">
<input id="password-input" type="password" name="password" value="" placeholder="Password">
</div>
<p class="form-message"></p>
<div class="signup-btn">
<button id="signup-btn" type="submit" name="button">sign-up</button>
</div>
</form>
<script>
$(document).ready(function () {
$('.signup-Form').submit(function(event){
event.preventDefault();
var first=$("#first-input").val();
var last=$("#last-input").val();
var email=$("#email-input").val();
var college=$("#college-input").val();
var password=$("#password-input").val();
var submit=$("#signup-btn").val();
$(".form-message").load("includes/signup.inc.php", {
first:first,
last:last,
email:email,
college:college,
password:password,
submit:submit
})
});
});
</script>
First of all before i show you the code i will explain how my webpage works.
User selects date -> AJAX Calls On Date Change
Resulting PHP data displays in two sections on page.
First Section is Orders Table Contents
Second Section is Items Table Contents (not including the items inside Orders)
What i am trying to add is functionality to 3 buttons that will change the tables dynamically using AJAX.
I currently have working non ajax requests.
Here is the Code:
$(document).ready(function(){
$('.date-picker').change(function(){
$.ajax({
type: 'POST',
url: 'php/getproduct.php',
data: {dateorderpicker: $('.date-picker').val()},
dataType: 'JSON',
success: function(data)
{
$("#cartrow").html(data.result_1);
$("#otheritems").html(data.result_2);
}
});
});
});
PHP file for Current AJAX:
session_start();
include('db_config.php');
$datepicker = $_POST['dateorderpicker'];
$sql = "SELECT * FROM orders WHERE deliveryDate = ? AND customerId = ? ";
$stmt = $conn->prepare($sql);
$stmt->bindParam(1, $datepicker, PDO::PARAM_STR);
$stmt->bindParam(2, $_SESSION['customer_id'], PDO::PARAM_INT);
$stmt->execute();
$container = array();
$data['result_1'] = $data['result_2'] = '';
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$container[] = "'{$row['itemName']}'"; // put them inside a temporary container
$data['result_1'] .= '
<div class="col-sm-4 col-md-4">
<div class="content-boxes style-two top-column clearfix animated flipInY" style="opacity: 1;">
<div class="content-boxes-text">
<form action="php/edit.php" method="post" class="form-inline pull-right">
<h3>' . $row['itemName'] . '</h3>
<h4>Total Price: $'.$row['price'].'</h4>
<img src="../wholesale/img/sourdough.jpg" class="img-reponsive">
<p>Our best seller. Full of flavour.</p>
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Qty</label>
<div class="input-group">
<input type="number" name="qty" class="form-control" id="exampleInputAmount" value="' . $row['qty'] . '">
</div>
</div>
<input type="hidden" name="id" value="'.$row['id'].'">
<button type="submit" name="update" class="btn btn-primary">Update</button>
<button type="submit" name="delete" class="btn btn-primary">Remove</button>
</form>
</div>
<!-- //.content-boxes-text -->
</div>
<!-- //.content-boxes -->
</div>
';
}
if(!empty($container)){
$excluded_names = implode(',', $container);
$sql = "SELECT * FROM item WHERE itemName NOT IN($excluded_names)";
$stmt = $conn->prepare($sql);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$price ="";
if ($_SESSION['customer_band'] == 'A') {
$price = $row['bandA'];
}
else if ($_SESSION['customer_band'] == 'B') {
$price = $row['bandB'];
}
else if ($_SESSION['customer_band'] == 'C') {
$price = $row['bandC'];
}
else if ($_SESSION['customer_band'] == 'D') {
$price = $row['bandD'];
}
else if ($_SESSION['customer_band'] == 'E') {
$price = $row['bandE'];
}
$data['result_2'] .= '
<div class="col-sm-4 col-md-4">
<div class="content-boxes style-two top-column clearfix animated flipInY" style="opacity: 1;">
<div class="content-boxes-text">
<form action="php/additem.php" method="post" class="form-inline pull-right">
<h4>'.$row['itemName'].'</h4><input id="itemname" type="hidden" name="itemName" value="'.$row['itemName'].'">
<h3>$'.$price.'</h3><input id="price" type="hidden" name="pricetotal" value="'.$price.'">
<img src="../wholesale/img/sourdough.jpg" class="img-reponsive">
<p>'.$row['description'].'</p><input id="description" type="hidden" name="description" value="'.$row['description'].'">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Qty</label>
<div class="input-group">
<input id="qty" type="number" name="qty" class="form-control" id="exampleInputAmount" placeholder="How Many?">
</div>
</div>
<button type="submit" id="additem" class="btn btn-primary">Add</button>
</form>
</div>
<!-- //.content-boxes-text -->
</div>
<!-- //.content-boxes -->
</div>
';
}
}
else
{
$sql = "SELECT * FROM item";
$stmt = $conn->prepare($sql);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$price ="";
if ($_SESSION['customer_band'] == 'A') {
$price = $row['bandA'];
}
else if ($_SESSION['customer_band'] == 'B') {
$price = $row['bandB'];
}
else if ($_SESSION['customer_band'] == 'C') {
$price = $row['bandC'];
}
else if ($_SESSION['customer_band'] == 'D') {
$price = $row['bandD'];
}
else if ($_SESSION['customer_band'] == 'E') {
$price = $row['bandE'];
}
$data['result_2'] .= '
<div class="col-sm-4 col-md-4">
<div class="content-boxes style-two top-column clearfix animated flipInY" style="opacity: 1;">
<div class="content-boxes-text">
<form action="php/additem.php" method="post" class="form-inline pull-right">
<h4>'.$row['itemName'].'</h4><input type="hidden" name="itemName" value="'.$row['itemName'].'">
<h3>$'.$price.'</h3><input type="hidden" name="pricetotal" value="'.$price.'">
<img src="../wholesale/img/sourdough.jpg" class="img-reponsive">
<p>'.$row['description'].'</p><input type="hidden" name="description" value="'.$row['description'].'">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Qty</label>
<div class="input-group">
<input type="number" name="qty" class="form-control" id="exampleInputAmount" placeholder="How Many?">
</div>
</div>
<button type="submit" id="additem" class="btn btn-primary">Add</button>
</form>
</div>
<!-- //.content-boxes-text -->
</div>
<!-- //.content-boxes -->
</div>
';
}
}
echo json_encode($data);
exit;
Both Update and Delete PHP file:
include('db_config.php');
if (isset($_POST['update']))
{
$qty = $_POST['qty'];
$id = $_POST['id'];
echo $id;
$sql = "UPDATE orders SET qty=? WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->execute(array($qty,$id));
header('Location: ../order.php');
}
if (isset($_POST['delete']))
{
$id = $_POST['id'];
$sql = "DELETE FROM orders WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->execute(array($id));
header('Location: ../order.php');
}
The code above needs to be converted to AJAX, and both sections on the page using ajax should update the table automatically. It might be that you will call the first ajax query to reload the tables correctly?
Thanks for having a look at this.
I am having trouble wrapping my head around how i should get this work.
Alex
It is easy you can give a class (NOTE : yes class ) to your update button and similarly to delete button
Suppose your update button has class "update_task"
but your content was added to DOM after DOM already loaded, so you will need to create two ajax request with DELEGATE Methods for delete and update.
For delegate reference -
http://api.jquery.com/delegate/
// for update
$("body").delegate(".update_task","click",function(){
current_id = $(this).previous("input:hidden").val() // for current update button id,
$.ajax({
type: 'POST',
url: 'php/update_product.php',
data: {id: current_id, othervalues: other_value_of_choice},
dataType: 'JSON',
success: function(data)
{
if(data==1)
{
// what ever you want to do if data has been updated
}
}
});
});
Send AJAX request to PHP for update/delete. Return result of operation (true/false).
If result is true, update/remove from html with javascript(jquery).
By the way, don't use redirect, when you call php via ajax.
My code given below. Please help me correct the code. Iam confused with syntax. Also I do not know where exactly to put error message alert if there is any database issue and how to close the database. Please help
<form id="ContactForm" name="form1" method="post" onsubmit="submitdata()">
<div>
<div class="formwrap"><span>Your Name:</span><input name="fname" type="text" class="input" ></div>
<div class="formwrap"><span>Your E-mail:</span><input type="text" name="femail" class="input" ></div>
<div class="formwrap"><span>Your Mobile:</span><input type="text" name="fmobile" class="input" ></div>
<div class="formwrap"><span>Your City:</span><input type="text" name="fcity" class="input" ></div>
<div class="textarea_box"><span>Your Message:</span><textarea name="fmessage" cols="1" rows="1"></textarea></div>
<a class="button" onClick="document.getElementById('ContactForm').submit()"><span class="shadow"></span>Send</a>
<a class="button" onClick="document.getElementById('ContactForm').reset()"><span class="shadow"></span>Clear</a>
</div>
</form>
<?php
function submitdata(){
include "config/connection.php";
$fdname = $_POST['fname']);
$fdemail = $_POST['femail']);
$fdmobile = $_POST['fmobile']);
$fdcity = $_POST['fcity']);
$fdmessage = $_POST['fmessage']);
$sql="INSERT INTO users (name, email, mobile, city, message)
VALUES ('$fdname', '$fdemail', '$fdmobile', '$fdcity', '$fdmessage')";
}
?>
Thank you
I changed the action on your html form and created the php script that will handle and store your data into the database,take a look and do some further reading on prepared statements.
<form id="ContactForm" name="form1" action="insert.php" method="post">
<div>
<div class="formwrap"><span>Your Name:</span><input name="fname" type="text" class="input" ></div>
<div class="formwrap"><span>Your E-mail:</span><input type="text" name="femail" class="input" ></div>
<div class="formwrap"><span>Your Mobile:</span><input type="text" name="fmobile" class="input" ></div>
<div class="formwrap"><span>Your City:</span><input type="text" name="fcity" class="input" ></div>
<div class="textarea_box"><span>Your Message:</span><textarea name="fmessage" cols="1" rows="1"></textarea></div>
<a class="button" onClick="document.getElementById('ContactForm').submit()"><span class="shadow"></span>Send</a>
<a class="button" onClick="document.getElementById('ContactForm').reset()"><span class="shadow"></span>Clear</a>
</div>
</form>
insert.php
<?php
if($_POST){
$db = new mysqli("address","id","password","DBname");
if (mysqli_connect_errno())
{
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
$stmt = $db->prepare("INSERT INTO users (name, email, mobile, city, message) VALUES (?, ?, ?, ?, ?)");
$stmt -> bind_param('sssss', $fname, $femail, $fmobile, $fcity, $fmessage);
$fname = $_POST['fname'];
$femail = $_POST['femail'];
$fmobile = $_POST['fmobile'];
$fcity = $_POST['fcity'];
$fmessage = $_POST['fmessage'];
$stmt -> execute();
$stmt -> close();
$db -> close();
}
?>
You can use something like this (if you have jQuery included):
<script>
$(document).ready(function () {
$('form[name=form1]').submit(function () {
var fname = $('input[name=fname]').val();
var femail = $('input[name=femail]').val();
var fmobile = $('input[name=fmobile]').val();
var fcity = $('input[name=fcity]').val();
var fmessage = $('textarea[name=fmessage]').val();
$.post("/ajax/insert.php", {
'fname': fname,
'femail': femail,
'fmobile': fmobile,
'fcity': fcity,
'fmessage': fmessage
}, function (data) {
if (data == 1) {
alert("Success");
} else {
alert("Error");
}
});
});
});
</script>
Then make folder "ajax" in the root of website and make there a script called insert.php (if you want different name, edit line 9 in the js code). Content of the insert.php will be something like this:
<?php
include "config/connection.php";
$fdname = $_POST['fname'];
$fdemail = $_POST['femail'];
$fdmobile = $_POST['fmobile'];
$fdcity = $_POST['fcity'];
$fdmessage = $_POST['fmessage'];
$sql="INSERT INTO users (name, email, mobile, city, message)
VALUES ('$fdname', '$fdemail', '$fdmobile', '$fdcity', '$fdmessage')";
mysql_query($sql);
if(mysql_error()) {
echo 0;
} else {
echo 1;
}
?>
For onsubmit attribute JS function or codes is required not PHP function. But you provided a PHP function in onsubmit. I suggest you to use AJAX or action in form.
An Example for you
<form id="ContactForm" name="form1" >
<div>
<div class="formwrap"><span>Your Name:</span><input name="fname" type="text" class="input" ></div>
<div class="formwrap"><span>Your E-mail:</span><input type="text" name="femail" class="input" ></div>
<div class="formwrap"><span>Your Mobile:</span><input type="text" name="fmobile" class="input" ></div>
<div class="formwrap"><span>Your City:</span><input type="text" name="fcity" class="input" ></div>
<div class="textarea_box"><span>Your Message:</span><textarea name="fmessage" cols="1" rows="1"></textarea></div>
<a class="button" id="submit"><span class="shadow"></span>Send</a>
<a class="button" onClick="document.getElementById('ContactForm').reset()"><span class="shadow"></span>Clear</a>
</div>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>
$('#submit').click(function(){
$.ajax({
url: 'test.php',
data: $('#ContactForm').serialize(),
type: 'post',
success: function(data){
if(data == 'inserted'){
alert('Inserted');
}else{
console.log(data);
}
}
});
});
</script>
In test.php
include "config/connection.php";
$fdname = $_POST['fname'];
$fdemail = $_POST['femail'];
$fdmobile = $_POST['fmobile'];
$fdcity = $_POST['fcity'];
$fdmessage = $_POST['fmessage'];
$sql="INSERT INTO users (name, email, mobile, city, message)
VALUES ('$fdname', '$fdemail', '$fdmobile', '$fdcity', '$fdmessage')";
// if you use mysql connection
$result = mysql_query($sql);
if($result) {
echo 'inserted';
} else {
die(mysql_error());
}
You also fix some syntax error. Remove ) after each $_POST.
My script does not seem to be working. Every time i try to use the form i've get the error with readystate=0, and status=0. Any help will be appreciated.
I've got the following form:
<form action="" method="post" >
<input type="text" name="name" id="tekst"/><br/>
<input type="text" name="name" id="autor"/><br/>
<input type="submit" name="<?php echo $id; ?>" value="Send" id="submit"/>
</form>
<div class="response"></div>
the values from input fields are then processed by the following code:
$("input#submit").click(function(){
var id = $("input#submit").attr("name");
var autor = $('input#autor').val();
var tresc = $('input#tekst').val();
$.ajax({
type: "POST",
url: "add_comment.php",
data:
{id: id,
autor: autor,
tresc: tresc},
success: function(data){
$(".response").text(data);
},
error:function(xhr,err){
alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
alert("responseText: "+xhr.responseText);
}
});
});
Here is my add_comment.php:
<?php
$id = $_POST['id'];
$autor= $_POST['autor'];
$tresc = $_POST['tresc'];
if(isset($id) && isset($autor) && isset($tresc)){
include("db/connection.php");
$zapytanie= "INSERT INTO komentarze(id_ref, autor, tresc) values ('$id', '$autor', '$tresc')";
$wynik = $db->query($zapytanie);
echo "Added";
}else{
echo "Problem";
}
?>
EDIT:
id_ref is not auto_increment field. The script is running on the localhost
First of all, your form isn't correct...name="name", class=".response"??
<form action="" method="post" >
<input type="text" name="tekst" id="tekst"/><br/>
<input type="text" name="autor" id="autor"/><br/>
<input type="submit" name="id" value="Send" id="submit"/>
</form>
<div class="response"></div>
Your PHP File should be"
<?php
$id = $_POST['id'];
$autor= $_POST['autor'];
$tresc = $_POST['tekst'];
if(isset($id) && isset($autor) && isset($tresc)){
include("db/connection.php");
$zapytanie= "INSERT INTO komentarze(id_ref, autor, tresc) values ('$id', '$autor', '$tresc')";
$wynik = $db->query($zapytanie);
echo "Added";
}else{
echo "Problem";
}
?>
<form action="add_comment.php" method="post" >
<input type="text" name="tekst" id="tekst"/><br/>
<input type="text" name="autor" id="autor"/><br/>
<input type="submit" name="button" value="Send" id="submit"/>
</form>
And in php it should be like this
$id = $_POST['button'];
$autor= $_POST['autor'];
$tresc = $_POST['tekst'];
It should work properly now. Previously you were making a mistake that in the submit button field you were passing a php variable which could contain anything and you dont know if it is dynamic. So you weren't be able to get it by using $_REQUEST['id'] because it could have been some thing like this
$id = 1; or $id = 'dynamic string' ;