-1

This is my php file I want to insert value of the status in two row at the same time.

<?php
include_once 'db_connect.php';
if(isset($_POST['btn-signup']))
{
    $PersonID = mysql_real_escape_string($_POST['PersonID']);
    $FirstName = mysql_real_escape_string($_POST['FirstName']);
    $Status = mysql_real_escape_string($_POST['Status']);

    $uname = trim($uname);
    $email = trim($email);
    $upass = trim($upass);

    // email exist or not
    $query = "SELECT PersonID FROM attandance WHERE PersonID='$PersonID'";
    $result = mysql_query($query);

    $count = mysql_num_rows($result); // if email not found then register

    if($count == 0){
        if(mysql_query("INSERT INTO state(PersonID,FirstName,Status)    VALUES('$PersonID','$FirstName','$Status')"))
        { ?>
            <script>alert('successfully Added ');</script>
            <?php
        }
        else
        { ?>
            <script>alert('error while registering you...');</script>
            <?php
        }       
     }
     else
     {
     ?>
        <script>alert('Sorry PersonID already taken ...');</script>
        <?php
     }
 }

echo "<!DOCTYPE html>\n"; 
echo "<html>\n"; 
echo "<head>\n"; 
echo "  <meta charset=\"utf-8\">\n"; 
echo "  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n"; 
echo "  <title>AdminLTE 2 | Blank Page</title>\n";
echo "</head>\n";
echo "<body>\n";

echo "          \n"; 
echo "\n";
echo "\n";
include_once 'dbconnect.php';
$query  = "SELECT * FROM attandance ";
$result = mysql_query($query);
echo "<table border=\"2\">\n"; 
echo "   <tr>\n"; 
echo "      <th>PersonId</th>\n"; 
echo "      <th>First Name</th>\n";
echo "      <th>Status</th>\n"; 


echo "    </tr>\n";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{   
    $PersonID=$row['PersonID'];
    $FirstName=$row['FirstName'];
    echo "<td> <input type=\"text\" name=\"user_id\" value=\" $PersonID\">   </td>\n"; 

    echo "<td> <input type=\"text\" name=\"full_name\" value=\" $FirstName\"></td>\n"; 
    echo "<td> <input type=\"text\" name=\"full_name\" value=\" $Status\"></td>\n"; 

    echo "</tr>\n";
}

echo " </table>\n";
echo "<input id=\"button\" type=\"submit\" name=\"btn-signup\" value=\"Sign-Up\">\n";

echo "</body>\n";
echo "</html>\n";
echo "\n";
?>

I want to add the status of both field at once using the button. But it is not working. Can anyone help me. In the state table I want to add values to two rows at the same time.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pittz
  • 19
  • 3
  • 12

1 Answers1

0

Bad Code :) but

your read this POST

$PersonID = mysql_real_escape_string($_POST['PersonID']);
$FirstName = mysql_real_escape_string($_POST['FirstName']);
$Status = mysql_real_escape_string($_POST['Status']);

and this input

echo "<td> <input type=\"text\" name=\"user_id\" value=\" $PersonID\">   </td>\n"; 

echo "<td> <input type=\"text\" name=\"full_name\" value=\" $FirstName\"></td>\n"; 
echo "<td> <input type=\"text\" name=\"full_name\" value=\" $Status\"></td>\n"; 

change the name of the input, try this

echo "<td> <input type=\"text\" name=\"PersonID\" value=\" $PersonID\">   </td>\n"; 

echo "<td> <input type=\"text\" name=\"FirstName\" value=\" $FirstName\"></td>\n"; 
echo "<td> <input type=\"text\" name=\"Status\" value=\" $Status\"></td>\n"; 

and where is the form? read this: http://php.net/manual/en/tutorial.forms.php

Provie9
  • 379
  • 2
  • 14
  • I changed the name even then when i click button nothing happens – Pittz Aug 29 '16 at 08:39
  • you need around the input this:
    – Provie9 Aug 29 '16 at 08:40
  • thank you, i also want to know how can we add date type from the input field in sql while creating Table – Pittz Aug 29 '16 at 08:44
  • the best anwser is :) read this article: http://stackoverflow.com/questions/12120433/php-mysql-insert-date-format , all what you need found here :) – Provie9 Aug 29 '16 at 08:47
  • when i click the button only the last row is getting updated, and in the database only the last row shows – Pittz Aug 29 '16 at 08:54
  • okay you need a array of input like this: `echo " \n"; echo " \n"; echo " \n";` and then you need a loop for the request! Search for a Tutorial like "input array php" – Provie9 Aug 29 '16 at 09:03