Instead of email the user id going into database - php

Been trying for hours anyways this form suppose to take my email that is being displayed and on submit inserts the details include email into database.
Instead of taking my 'email' it is taking my user id(auto increment) from user table and update that into feedback table.
feedback.php
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$name='';$feedback=''; $topic=''; $details='';
$action =(isset($_POST['submit']) ? $_POST['submit'] : null);
if($action!=null) {
$name =(isset($_POST['name']) ? $_POST['name'] : null);
$feedback =(isset($_POST['feedback']) ? $_POST['feedback'] : null);
$topic =(isset($_POST['topic']) ? $_POST['topic'] : null);
$details =(isset($_POST['details']) ? $_POST['details'] : null)
if($details==null) {
echo "<br><p style='text-align:center;color:red'>Please fill up all text fields!</p>";
}
else {
$query="insert into feedback values('','$email','$name','$feedback','$topic','$details','',null)";
$result=mysql_query($query);
echo "<br><p style='text-align:center;color:blue'>Successfully submit the feedback to system </p>";
$feedback=''; $topic=''; $details='';
}
if( mysql_error()!="") {
echo "<font style='text-align:center;color:red'>" . mysql_error() . "</font><br>";
}
}
?>
<form method="post" action="user_feedback.php">
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$query="select * from user where id=$email";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
?>
<br>
<table cellpadding="5">
<tr><td style="width:150px">User Email</td><td><input type="text" name="email" value="<?php echo $row['email'] ?>" disabled style="width:200px;" ></td></tr>
<tr><td>User Name</td><td><input type="text" name="name" value="<?php echo $name ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback</td>
<td>
<select name="feedback" style="height:32px">
<option <?php if($feedback=="Inquiry") { echo 'selected'; } ?> >Inquiry</option>
</select>
</td>
</tr>
<tr><td>Feedback Topic</td><td><input type="text" name="topic" value="<?php echo $topic ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback Details</td><td><textarea type="comment" name="details" value="<?php echo $details ?>" style="width:500px;" ></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Submit" class="tall"></td></tr>
</table>
</form>

Fixed it by using suggestion because there is was mixed up of login session between id and email on login page it self.
<?php
//echo("{$_SESSION['id']}"."<br />");
$email =(isset($_SESSION['id']) ? $_SESSION['id'] : null);
$name='';$feedback=''; $topic=''; $details='';
$action =(isset($_POST['submit']) ? $_POST['submit'] : null);
if($action!=null) {
$name =(isset($_POST['name']) ? $_POST['name'] : null);
$feedback =(isset($_POST['feedback']) ? $_POST['feedback'] : null);
$topic =(isset($_POST['topic']) ? $_POST['topic'] : null);
$details =(isset($_POST['details']) ? $_POST['details'] : null);
if($topic==null || $details==null) {
echo "<br><p style='text-align:center;color:red'>Please fill up all text fields!</p>";
}
else {
$query="insert into feedback values('','$email','$name','$feedback','$topic','$details','',null)";
$result=mysql_query($query);
echo "<br><p style='text-align:center;color:blue'>Successfully submit the feedback to system </p>";
$feedback=''; $topic=''; $details='';
}
if( mysql_error()!="") {
echo "<font style='text-align:center;color:red'>" . mysql_error() . "</font><br>";
}
}
?>
<form method="post" action="user_feedback.php">
<?php
$email =(isset($_SESSION['email']) ? $_SESSION['email'] : null);
$query="select * from user where id=$email";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
?>
<br>
<table cellpadding="5">
<tr><td style="width:150px">User Email</td><td><input type="text" name="email" value="<?php echo $row['email'] ?>" disabled style="width:200px;" ></td></tr>
<tr><td>User Name</td><td><input type="text" name="name" value="<?php echo $name ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback</td>
<td>
<select name="feedback" style="height:32px">
<option <?php if($feedback=="Inquiry") { echo 'selected'; } ?> >Inquiry</option>
</select>
</td>
</tr>
<tr><td>Feedback Topic</td><td><input type="text" name="topic" value="<?php echo $topic ?>" style="width:300px;" ></td></tr>
<tr><td>Feedback Details</td><td><textarea type="comment" name="details" value="<?php echo $details ?>" style="width:500px;" ></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Submit" class="tall"></td></tr>
</table>
</form>

Related

match multiple words in any order from sql via form submit

Hi I hope someone can help. This is my first attempt at using SQL and I'm finding a challenge, to say the least. What I am trying to do is to write multiple searches for a motorcycle website the customer would enter
make in box 1 model in box 2 product in box 3 year in bod 4
But I stuck trying to match multiple words in any order, customers have to type the exact phrase for it to find the product.
this is the code so far
Thanks for your help in advance
<?php
include 'motorcyclefitmentdb.php';
?>
<center>
<table id="search_box">
<form method="post">
<td><input name="Make" type="text" placeholder="Make....." value="<?php echo isset($_POST['Model']) ? htmlspecialchars($_POST['Make'], ENT_QUOTES) : ''; ?>">
</td>
<td><input name="Model" type="text" placeholder="Model....." value="<?php echo isset($_POST['Model']) ? htmlspecialchars($_POST['Model'], ENT_QUOTES) : ''; ?>">
</td>
<td><input name="Item" type="text" placeholder="Item....." value="<?php echo isset($_POST['Item']) ? htmlspecialchars($_POST['Item'], ENT_QUOTES) : ''; ?>">
</td>
</td>
<td><input name="Year" type="text" placeholder="Year....." value="<?php echo isset($_POST['Year']) ? htmlspecialchars($_POST['Year'], ENT_QUOTES) : ''; ?>"></td>
<td><button type="submit" name="submit search">Submit</button></td>
</form>
</table>
</center>
<br><br>
</div>
<center>
<table class = "customer">
<?php
if(isset($_POST['submit-search'])){
$Make = $_POST['Make'];
$Model = $_POST['Model'];
$Item = $_POST['Item'];
$Year = $_POST['Year'];
$sql = "SELECT * FROM `fitment` WHERE `Make` LIKE '%$Make%'
AND `Model` LIKE '%$Model%'
AND `Item` LIKE '%$Item%'
AND `Year Search` LIKE '%$Year%'
";
$stmt = $conn->prepare($sql=presql);
$newsql = presql;
$stmt->bindPram("presql", $newsql, PDO::PARAM_CHAR);
$stmt->execute();
}
if ($stmt->num_rows > 0) {
// output data of each row
while($row = $stmt->fetch_assoc()) {
echo
"
<tr>
</tr><td>
".$row["Image"]."
<br><br>
".$row["Item"]."
<br><br>
SKU: ".$row["SKU"]."
<br>
£ ".$row["Price"]."
<br><br>
".$row["Buy"]."
</td>
<td>
".$row["Make"]." ".$row["Model"]." ".$row["Year"]."
<br><br>
".$row["Engine"]."
</td>
</tr>
";
}
} else {
echo "0 results";
}
$conn->close();
?>
</table>
</center>
</div>

How to disable button when returned books is equal with original books volume?

I am making a book management system.I have a return button ,with that button user can return books.
Here is my release-books.php:
<?php
$sql_select = "SELECT * FROM carti ORDER BY titlu";
$rezultat = mysqli_query($conn, $sql_select);
if (mysqli_num_rows($rezultat) > 0) {
while ($row = mysqli_fetch_assoc($rezultat)) {
$disabled = $row['stoc'] > 0 ? "" : "disabled"; ?>
<tr><td><input type="submit" name="id" value="<?php echo $row['idCarte']; ?>" <?php echo $disabled; ?> formaction="imprumutare.php"></input></td>
<td><input type="submit" name="returnare" value="<?php echo $row['idCarte']; ?>" formaction="returnare_carte.php"></input>
</td>
<td><input type="text" name="nume" value="<?php echo $row['titlu']; ?>" ></input></td>
<td><input type="text" name="" value="<?php echo $row['autor']; ?>"></input></td>
<td><input type="text" name="" value="<?php echo $row['editura']; ?>"></input></td>
<td><input type="text" name="" value="<?php echo $row['categorie']; ?>"></input></td>
<td><input type="text" name="" value="<?php echo $row['data_adaugarii']; ?>"></input></td>
<td><input type="text" name="" value="<?php echo $row['stoc']; ?>"></input></td>
</tr>
<?php
}
}
?>
And here is my borrowing.php
include('conexiune.php');
//sfarsit if
//Imprumutare
if (isset($_POST['id'])) {
$identificator = $_POST['id'];
$carte_nume = $_POST['nume'];
$current_date = date('y:m:d');
$current_date_plus_14days = date('y:m:d', strtotime("+14 days"));
$nume_carte = $_POST['nume'];
$insert_in_imprumuturi = "INSERT INTO imprumuturi(idc,nume_carte,data,termen_returnare,carti_imprumutate) VALUES('$identificator','$carte_nume','$current_date','$current_date_plus_14days','1')";
mysqli_query($conn, $insert_in_imprumuturi) or die(mysqli_error($conn));
$sql_rezervare = "UPDATE carti SET stoc=stoc-1 WHERE iDCarte='$identificator' ";
if (mysqli_query($conn, $sql_rezervare)) {
header('Refresh:0,url=emitere_carti.php');
} else {
die(mysqli_error($conn));
}
}
But I do not know how to disable the return button when the returned books volume is equal or greater that the originial volume
Can somone help me?
Check If your books volume is equal or greater than original volume, if it is. Use PHP echo to disable the Return Button.
<button type="submit" name="return"
<?php
if($returned_books_volume >= $original_books_volume){
echo 'disabled';
}
?>
>Return</button>

i am trying to update my data with an image updation too but the image isset would not work in php

Hey guys i have created a register form with an image upload too but when i try to update this form i try to get the id but the isset of my image is not working so it just wont run my update query do check it out
this is the updation form where all the values will be displayed for edit now can i run the update function in the isset condition of my submit button and then update the data
<title>Register Update</title>
<?php
//error_reporting(0);
$id=$_GET['id'];
function __autoload($classname)
{
include "$classname.php";
}
$obj = new connect();
$st=$obj->con();
if (isset($_POST['sub']))
{
$upd= new update();
$upd->updatedata($_POST);
}
$qry = "select * from register ";
$run = mysqli_query($st,$qry);
$row = mysqli_fetch_assoc($run);
{
$g = $row['gen'];
$l = $row['lang'];
}
$query=mysqli_query($st,"select * from register where id='$id'");
//echo "<ul>";
while($query2=mysqli_fetch_assoc($query))
{
//print_r($query2);
echo "<form method='POST' action='RegisterRetrieve.php'>";
echo "<table>";
?>
<p><input type="hidden" name="sid" value="<?php echo $query2['id']; ?>"></p>
<tr>
<td>
First Name:
</td>
<td><input type="text" name="uname" value="<?php echo $query2['uname']; ?>"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" value="<?php echo $query2['pwd']; ?>"></td>
</tr>
<tr>
<td>Email Id:</td>
<td><input type="text" name="emailid" value="<?php echo $query2['emailid']; ?>"
</td>
</tr>
<tr>
<td>Radio Button: Are you male or female?</td>
<?php
if ($g == "male"){
echo "<td><input type='radio' name='gen' value='Male' id='gen' checked> Male <input type='radio' name='gen' value='Female' id='gen'> Female </td>";
}
else
{
echo "<td><input type='radio' name='gen' value='Male' id='gen'> Male <input type='radio' name='gen' value='Female' id='gen' checked> Female </td>";
}
?>
</tr>
<tr>
<td>Check Box: Check the languages you know?</td>
<td><?php
$lang=explode(',',$l);
//print_r($lang);
if(in_array('Cricket', $lang))
echo '<input type="checkbox" name="lang[0]" value="Cricket" checked>Cricket';
else
echo '<input type="checkbox" name="lang[0]" value="Cricket">Cricket';
if(in_array('Basketball', $lang))
echo '<input type="checkbox" name="lang[1]" value="Basketball" checked>Basketball';
else
echo '<input type="checkbox" name="lang[1]" value="Basketball">Basketball';
if(in_array('Hockey', $lang))
echo '<input type="checkbox" name="lang[2]" value="Hockey" checked>Hockey';
else
echo '<input type="checkbox" name="lang[2]" value="Hockey">Hockey'."<br>";
?>
</td>
</tr>
<tr>
<td>Mobile No:</td>
<td><input type="text" name="mobile" value="<?php echo $query2['mobile']; ?>"
</td>
</tr>
<tr>
<td>10th Marks:</td>
<td><input type="text" name="marks_10" value="<?php echo $query2['10marks'];?>"
</td>
</tr>
<tr>
<td>
12th Marks:</td>
<td><input type="text" name="marks_12" value="<?php echo $query2['12marks'];?>"</td>
</tr>
<tr>
<td>
Browse Image:</td>
<td><input type="file" name="file1"></td>
<td><img src='img/<?php echo $query2['name'];?>' width='150px' height='150px'></td>
</tr>
<tr>
<td>
<select name="priority">
<option value="admin">
admin
</option>
<option value="<?php echo $query2['priority']; ?>"><?php echo $query2['priority']; ?>
</option>
<option value="superadmin">
superadmin
</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="submit" name="sub"><br>
</td>
</tr>
<?php
echo "<table>";
echo "</form>";
}
//echo "</ul>";
?>
now my update query which i m using but when i try to isset my image it just wont go in that condition
<?php
class update extends connect
{
function updatedata($rel)
{
$obj= new connect();
$obj->con();
extract($_POST);
$id=$_GET['id'];
$line = implode("," ,$lang);
print_r($_POST);
if(isset($_FILES["file1"]))
{
extract($_POST);
echo "hello";
$name = $_FILES['file1']['name'];
$type = $_FILES['file1']['type'];
$size = $_FILES['file1']['size'];
$tmp_name = $_FILES['file1']['tmp_name'];
$loc = 'img/';
$ext = substr($name,strpos($name,'.')+1);
if($_FILES['file1']['size']>= '10000' || $_FILES['file1']['size']<="23000000")
{
//echo $size;
}
else{
// echo "size is not supported";
}
$val = $_FILES['file1']['size'];
if($ext == 'jpg' || $ext == 'png')
{
//echo $lang;
//print_r($_POST);
//exit;
$val =("update register set uname='$uname',pwd='$pwd',emailid='$emailid',gen='$gen',lang='$line',mobile='$mobile',10marks='$marks_10',12marks='$marks_12' file1='$name' where id=$sid");
//print_r($qry);
$res=mysqli_query($this->con(),$val);
//print_r($run);
if($res)
{
move_uploaded_file($tmp_name,$loc.$name);
//echo "data saved";
//echo "Data inserted";
}
else
{
//echo "Data Not Inserted";
}
}
}
}
//print_r($val);
// return $res;
}
?>
Your html is broken:
</tr>
<?php
echo "<table>"; <--shouldn't this be </table>?
echo "</form>";
}

PHP if isset($_POST doesn't work

I have a simple form on my page and I want to make sure every field is filled before inserting the values into the database. The problem is the condition never met, even if every field is filled I still get "Something is missing"...
Search:
<form method="post" action="<?php echo $_SERVER[" PHP_SELF "]?>">
<input placeholder="e-mail address" type="text" name="email_search">
<input type="submit" name="search" value="Go">
<?php if (isset($_POST[ "search"])) { $email_search=m ysql_real_escape_string($_POST[ "email_search"]); $check=m ysql_query( "SELECT * FROM torzsvendegek WHERE email = '$email_search'"); $s=m ysql_fetch_array($check); }?>
<form method="post" action="<?php echo $_SERVER[" PHP_SELF "]?>">
<table width="440" border="0" style="text-align:right;">
<tr>
<td>E-mail:</td>
<td>
<input type="text" name="email" value="<?php echo $email_search;?>" disabled>
</td>
</tr>
<tr>
<td>Név:</td>
<td>
<input type="text" name="nev" value="<?php echo $s['nev'];?>">
</td>
</tr>
<tr>
<td>Mikor:</td>
<td>
<input type="text" name="mikor">
</td>
</tr>
<tr>
<td>Éjszakák száma:</td>
<td>
<input type="text" name="ejszakak">
</td>
</tr>
<tr>
<td>Nemzetisége:</td>
<td align="left">
<select name="nyelv">
<option value="magyar" <?php if($s[ 'nyelv']=="magyar" ) echo "selected=\"selected\ ""; ?>>Magyar</option>
<option value="nemet" <?php if($s[ 'nyelv']=="nemet" ) echo "selected=\"selected\ ""; ?>>Német</option>
<option value="lengyel" <?php if($s[ 'nyelv']=="lengyel" ) echo "selected=\"selected\ ""; ?>>Lengyel</option>
<option value="roman" <?php if($s[ 'nyelv']=="roman" ) echo "selected=\"selected\ ""; ?>>Román</option>
<option value="szlovak" <?php if($s[ 'nyelv']=="szlovak" ) echo "selected=\"selected\ ""; ?>>Szlovák</option>
<option value="egyeb" <?php if($s[ 'nyelv']=="egyeb" ) echo "selected=\"selected\ ""; ?>>Egyéb</option>
</select>
</td>
</tr>
<tr>
<td>Megjegyzés:</td>
<td>
<textarea name="megjegyzes">
<?php echo htmlspecialchars($s[ 'megjegyzes']);?>
</textarea>
</td>
</tr>
</table>
<br>
<table width="440">
<tr>
<td>
<input type="submit" name="submit_add" value="Hozzáad">
</td>
</tr>
</table>
</form>
<?php if (isset($_POST[ "submit_add"]) && !empty($_POST[ "nev"]) && !empty($_POST[ "email"]) && !empty($_POST[ "mikor"]) && !empty($_POST[ "ejszakak"])){ $nev=m ysql_real_escape_string($_POST[ "nev"]); $email=m ysql_real_escape_string($_POST[ "email"]); $mikor=m ysql_real_escape_string($_POST[ "mikor"]); $ejszakak=m ysql_real_escape_string($_POST[ "ejszakak"]); $nyelv=m ysql_real_escape_string($_POST[ "nyelv"]); $megjegyzes=m ysql_real_escape_string($_POST[ "megjegyzes"]); $check2=m ysql_query( "SELECT * FROM torzsvendegek WHERE email = '$email'"); $br="<br>" ; if (mysql_num_rows($check2)> 0) { $adatok = mysql_fetch_array($check2); $osszesen = ($adatok['ejszakak'] + $ejszakak); mysql_query("UPDATE torzsvendegek SET nev = '".$nev."', mikor = '".$adatok['mikor']."".$mikor."".$br."', ejszakak = '".$osszesen."', nyelv = '".$nyelv."', megjegyzes = '".$adatok['megjegyzes']."".$megjegyzes."".$br."' WHERE email = '".$email."'"); echo "
<br>".$email." Updated"; } else { mysql_query("INSERT INTO torzsvendegek (id, nev, email, mikor, ejszakak, nyelv, megjegyzes) VALUES (NULL, '$nev', '$email', '".$mikor."".$br."', '$ejszakak', '$nyelv', '".$megjegyzes."')"); echo "
<br>".$email." Added"; } } else { echo "Something is missing"; } ?>
You made 2 mistakes in your code:
1) You didn't close the first form (missing </form>)
2) You disabled the E-mail input field which resulted in always empty
Here's the updated (though deprecated and insecure!!!) code:
<?php
if(isset($_POST["search"])){
$email_search = mysql_real_escape_string($_POST["email_search"]);
$check = mysql_query("SELECT * FROM torzsvendegek WHERE email = '$email_search'");
$s = mysql_fetch_array($check);
}
if(isset($_POST["submit_add"]) && !empty($_POST["nev"]) && !empty($_POST["email"]) && !empty($_POST["mikor"]) && !empty($_POST["ejszakak"])){
$nev = mysql_real_escape_string($_POST["nev"]);
$email = mysql_real_escape_string($_POST["email"]);
$mikor = mysql_real_escape_string($_POST["mikor"]);
$ejszakak = mysql_real_escape_string($_POST["ejszakak"]);
$nyelv = mysql_real_escape_string($_POST["nyelv"]);
$megjegyzes = mysql_real_escape_string($_POST["megjegyzes"]);
$check2 = mysql_query("SELECT * FROM torzsvendegek WHERE email = '$email'");
$br = "<br>";
if (mysql_num_rows($check2) > 0){
$adatok = mysql_fetch_array($check2);
$osszesen = ($adatok['ejszakak'] + $ejszakak);
mysql_query("UPDATE torzsvendegek SET nev = '".$nev."', mikor = '".$adatok['mikor']."".$mikor."".$br."', ejszakak = '".$osszesen."', nyelv = '".$nyelv."', megjegyzes = '".$adatok['megjegyzes']."".$megjegyzes."".$br."' WHERE email = '".$email."'");
echo "<br>".$email." Updated";
} else {
mysql_query("INSERT INTO torzsvendegek (id, nev, email, mikor, ejszakak, nyelv, megjegyzes) VALUES (NULL, '$nev', '$email', '".$mikor."".$br."', '$ejszakak', '$nyelv', '".$megjegyzes."')");
echo "<br>".$email." Added";
}
} else {
echo "Something is missing";
}
?>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]?>">
Search: <input placeholder="e-mail address" type="text" name="email_search">
<input type="submit" name="search" value="Go">
</form>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]?>">
<table width="440" border="0" style="text-align:right;">
<tr>
<td>E-mail:</td>
<td><input type="text" name="email" value="<?php echo $email_search;?>"></td>
</tr>
<tr>
<td>Név:</td>
<td><input type="text" name="nev" value="<?php echo $s['nev'];?>"></td>
</tr>
<tr>
<td>Mikor:</td>
<td><input type="text" name="mikor"></td>
</tr>
<tr>
<td>Éjszakák száma:</td>
<td><input type="text" name="ejszakak"></td>
</tr>
<tr>
<td>Nemzetisége:</td>
<td align="left">
<select name="nyelv">
<option value="magyar" <?php if($s['nyelv']=="magyar") echo "selected=\"selected\""; ?>>Magyar</option>
<option value="nemet" <?php if($s['nyelv']=="nemet") echo "selected=\"selected\""; ?>>Német</option>
<option value="lengyel" <?php if($s['nyelv']=="lengyel") echo "selected=\"selected\""; ?>>Lengyel</option>
<option value="roman" <?php if($s['nyelv']=="roman") echo "selected=\"selected\""; ?>>Román</option>
<option value="szlovak" <?php if($s['nyelv']=="szlovak") echo "selected=\"selected\""; ?>>Szlovák</option>
<option value="egyeb" <?php if($s['nyelv']=="egyeb") echo "selected=\"selected\""; ?>>Egyéb</option>
</select>
</td>
</tr>
<tr>
<td>Megjegyzés:</td>
<td><textarea name="megjegyzes"><?php echo htmlspecialchars($s['megjegyzes']);?></textarea></td>
</tr>
</table>
<br>
<table width="440">
<tr>
<td><input type="submit" name="submit_add" value="Hozzáad"></td>
</tr>
</table>
</form>
You need to close your search form tag to keep the two forms separated
Search:<form method="post" action="<?php echo $_SERVER["PHP_SELF"]?>"><input placeholder="e-mail address" type="text" name="email_search"><input type="submit" name="search" value="Go"></form>
and
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]?>">
<table width="440" border="0" style="text-align:right;">
<tr><td>E-mail:</td><td><input type="text" name="email" value="<?php echo $email_search;?>" disabled></td></tr>
<tr><td>Név:</td><td><input type="text" name="nev" value="<?php echo $s['nev'];?>"></td></tr>
<tr><td>Mikor:</td><td><input type="text" name="mikor"></td></tr>
<tr><td>Éjszakák száma:</td><td><input type="text" name="ejszakak"></td></tr>
<tr><td>Nemzetisége:</td><td align="left"> <select name="nyelv">
<option value="magyar" <?php if($s['nyelv']=="magyar") echo "selected=\"selected\""; ?>>Magyar</option>
<option value="nemet" <?php if($s['nyelv']=="nemet") echo "selected=\"selected\""; ?>>Német</option>
<option value="lengyel" <?php if($s['nyelv']=="lengyel") echo "selected=\"selected\""; ?>>Lengyel</option>
<option value="roman" <?php if($s['nyelv']=="roman") echo "selected=\"selected\""; ?>>Román</option>
<option value="szlovak" <?php if($s['nyelv']=="szlovak") echo "selected=\"selected\""; ?>>Szlovák</option>
<option value="egyeb" <?php if($s['nyelv']=="egyeb") echo "selected=\"selected\""; ?>>Egyéb</option>
</select></td></tr>
<tr><td>Megjegyzés:</td><td><textarea name="megjegyzes"><?php echo htmlspecialchars($s['megjegyzes']);?></textarea></td></tr>
</table><br>
<table width="440"><tr><td><input type="submit" name="submit_add" value="Hozzáad"></td></tr></table>
</form>
You did not close your search form and you need to remove the disabled attribute from your email input field.
I re-wrote your code to help you will debugging. I commented out all the stuff related to the database so you can focus on the form fields only. Here is the code I re-wrote. I left comments so you can see what I did.
<?php
/******JUST TO MAKE DEBBUGGING EASIER***/
echo "<pre>"; // Start of the pre> tags
/**ANYTHING TO DO WITH THE DATABASE I HAVE COMMENTED OUT**/
if(isset($_POST["search"])){
$email_search = mysql_real_escape_string($_POST["email_search"]);
/**PRINT_R FOR DEBUGGING PURPOSES, REMOVE!!*/
print_r($email_search);
//$check = mysql_query("SELECT * FROM torzsvendegek WHERE email = '$email_search'");
//$s = mysql_fetch_array($check);
}
/***CHECK THE POST DATA, REMOVE FROM APPLICATION ONCE YOU HAVE DEBUGGED THE DATA**/
print_r($_POST);
/***I WILL STORE THE POST DATA IN VARIABLES BEFORE CHECKING**/
$nev = isset($_POST["nev"]) ? mysql_real_escape_string($_POST["nev"]) : null;
$email = isset($_POST["email"]) ? mysql_real_escape_string($_POST["email"]) : null;
$mikor = isset($_POST["mikor"]) ? mysql_real_escape_string($_POST["mikor"]) : null;
$ejszakak = isset($_POST["ejszakak"]) ? mysql_real_escape_string($_POST["ejszakak"]) : null;
$nyelv = isset($_POST["nyelv"]) ? mysql_real_escape_string($_POST["nyelv"]) : null;
$megjegyzes = isset($_POST["megjegyzes"]) ? mysql_real_escape_string($_POST["megjegyzes"]) : null;
if(isset($_POST["submit_add"]) && !is_null($nev) && !is_null($email) && !is_null($mikor) && !is_null($ejszakak)){
/*******
SINCE I ALREADY HAVE THEM, YOU NEED TO REMOVE THEM FROM THE CODE
$nev = mysql_real_escape_string($_POST["nev"]);
$email = mysql_real_escape_string($_POST["email"]);
$mikor = mysql_real_escape_string($_POST["mikor"]);
$ejszakak = mysql_real_escape_string($_POST["ejszakak"]);
$nyelv = mysql_real_escape_string($_POST["nyelv"]);
$megjegyzes = mysql_real_escape_string($_POST["megjegyzes"]);
******/
//$check2 = mysql_query("SELECT * FROM torzsvendegek WHERE email = '$email'");
$br = "<br>";
/*********
if (mysql_num_rows($check2) > 0) {
$adatok = mysql_fetch_array($check2);
$osszesen = ($adatok['ejszakak'] + $ejszakak);
mysql_query("UPDATE torzsvendegek SET nev = '".$nev."', mikor = '".$adatok['mikor']."".$mikor."".$br."', ejszakak = '".$osszesen."', nyelv = '".$nyelv."', megjegyzes = '".$adatok['megjegyzes']."".$megjegyzes."".$br."' WHERE email = '".$email."'");
echo "<br>".$email." Updated";
}else {
mysql_query("INSERT INTO torzsvendegek (id, nev, email, mikor, ejszakak, nyelv, megjegyzes) VALUES (NULL, '$nev', '$email', '".$mikor."".$br."', '$ejszakak', '$nyelv', '".$megjegyzes."')");
echo "<br>".$email." Added";
}
****/
}elseif (isset($_POST["submit_add"])) {
echo "Something is missing";
}
echo '</pre>';//end of pre
?>
Search:
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]?>">
<input placeholder="e-mail address" type="text" name="email_search">
<input type="submit" name="search" value="Go">
</form>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]?>">
<table width="440" border="0" style="text-align:right;">
<tr>
<td>E-mail:</td>
<td><input type="text" name="email" value="<?php echo $email;?>" ></td>
</tr>
<tr>
<td>Név:</td>
<td><input type="text" name="nev" value="<?php echo $nev;?>"></td>
</tr>
<tr>
<td>Mikor:</td>
<td><input type="text" name="mikor" value="<?php echo $mikor;?>"></td>
</tr>
<tr>
<td>Éjszakák száma:</td>
<td><input type="text" name="ejszakak" value="<?php echo $ejszakak;?>"></td>
</tr>
<tr>
<td>Nemzetisége:</td>
<td align="left">
<select name="nyelv">
<option value="magyar" <?php if($nyelv=="magyar") echo "selected=\"selected\""; ?>>Magyar</option>
<option value="nemet" <?php if($nyelv=="nemet") echo "selected=\"selected\""; ?>>Német</option>
<option value="lengyel" <?php if($nyelv=="lengyel") echo "selected=\"selected\""; ?>>Lengyel</option>
<option value="roman" <?php if($nyelv=="roman") echo "selected=\"selected\""; ?>>Román</option>
<option value="szlovak" <?php if($nyelv=="szlovak") echo "selected=\"selected\""; ?>>Szlovák</option>
<option value="egyeb" <?php if($nyelv=="egyeb") echo "selected=\"selected\""; ?>>Egyéb</option>
</select>
</td>
</tr>
<tr>
<td>Megjegyzés:</td>
<td><textarea name="megjegyzes"><?php echo htmlspecialchars($megjegyzes);?></textarea>
</td>
</tr>
</table><br>
<table width="440">
<tr><td><input type="submit" name="submit_add" value="Hozzáad"></td></tr>
</table>
</form>

send form data with serialize to php page : $_POST don't get data

Im getting crazy with this problem.
I try to use ajax to send data from a form in a way that I have not to reload all webpage (my webpage contain some queries for generate index menu that produce traffic); I create sendForm method, which handle form datas and pass it to php page to process.
This is the js code:
function sendForm(){
var http = false;
http = new XMLHttpRequest();
var ser = $(":input").serialize();
http.open("POST", "http://localhost/redir.php" ,true);
http.onreadystatechange= handleResponse();
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", ser.length);
http.setRequestHeader("Connection", "close");
http.send(ser);
return true;
}
My form data contain a variable numbers of inputs because there's some php code inside a for cycle.
<form name="form" id="form" class="table table-hover" method="post">
<?php while(.....)) { ?>
<tr style="line-height:40px">
<td><?php echo $home;?></td>
<td><?php echo $vis;?></td>
<td><input type="text" name="goal_h[]" class="input-mini"
<?php if ($sq[16] == "2"){ ?>
readonly value="<?php echo $goal_h;?>"
<?php }else if ($sq[16] == "3"){
?> readonly value="-"
<?php } else echo "value=\"-\"";
?> id="goal_h<?php echo $i?>[]" maxlength="2" size="2" />
<input type="hidden" name="id_sub" value="<?php echo $id_sub;?>" />
<input type="hidden" name="id" id="id" value="<?php echo $id_d;?>" />
<input type="hidden" name="data_gg" value="<?php echo $data_gg;?>" />
<input type="hidden" name="n_gg" value="<?php echo $n_gg;?>" />
<input type="hidden" name="id_p_home[]" id="idphome<?php echo $i?>" value="<?php echo $tmp_id_p;?>" />
<input type="hidden" name="id_p_vis[]" id="idpvis<?php echo $i?>" value="<?php echo $sq[10];?>" />
</td>
<td>
<input type="text" name="goal_v[]" class="input-mini" <?php if ($sq[16] == "2"){ ?> readonly value="<?php echo $goal_v;?>" <?php }else if ($sq[16] == "3"){ ?> readonly value="-" <?php } else echo "value=\"-\""; ?> id="goal_v<?php echo $i?>[]" maxlength="2" </td>
<td><input type="checkbox" <?php if ($sq[16] == "2"){ ?> checked <?php } ?> id="sosp<?PHP echo $i?>" name="sosp[]" value="<?PHP echo $i?>" onclick="cambiaStato(<?php echo $i?>);"/></td>
<td><input type="checkbox" <?php if ($sq[16] == "3"){ ?> checked <?php } ?> id="nd<?PHP echo $i?>" name="nd[]" value="<?PHP echo $i?>" onclick="cambiaStato(<?php echo $i?>);"/>
</td>
</tr>
<tr style="line-height:40px">
<td><input type="submit" id="submit" name="submit" value="AGGIORNA IL PUNTEGGIO" onclick="sendForm()" /></td>
<td colspan="5"></td>
</tr>
<?php } ?>
</form>
this code works if I don't use with ajax and simply use an action=name_of_file.php, but when I try to use sendForm() method, in redir.php file I lose $_POST variables.
$home_id_p=$_POST['id_p_home'];
$vis_id_p=$_POST['id_p_vis'];
$goal_home=$_POST['goal_h'];
$goal_vis= $_POST['goal_v'];
$sosp= (isset($_POST['sosp'])) ? $_POST['sosp'] : "99";
$nd= (isset($_POST['nd'])) ? $_POST['nd'] : "99";
and then I need to loop on $home_id_p.
I tried also wihout serialize(), and also with serializeArray() :
var ser = $(":input").serializeArray();
but with this I'm not able to send it, because I get an error "invalid argument" in
http.send(ser)
Any idea?
Thanks

Categories