-1
<?php
if( $_SESSION['user_id'] == '1' || $_SESSION['user_id'] == '7' )
{
    echo '<hr class="mx-3 my-0">
            <div class="callout callout-warning m-0 py-3">
              <div>
                <strong>Sas Andreea</strong>
              </div>
              <small class="text-muted mr-3"><i class="icon-calendar"></i>Salariu Lunar:</small>
              <small class="text-muted"><i class="icon-location-pin"></i><input type="text"  name="salariulunar" value="' . $row[
  'salariulunar'] . '"  maxlength="4" size="4"> lei 
              <br /> Data contract: <input type="text"  name="datacontractului"  maxlength="10" size="7" value="' . $row['datacontractului'] . ' ">
              <br /> Datorie: <input type="text"  name="datorie" value="' . $row['datorie'] . '"   maxlength="4" size="4"> Lei
              <br /> Salariu in avans: <input type="text" value="' . $row['salariuavans'] . ' " name="salariuavans"  maxlength="4" size="4"> Lei
              <br /> Zile de concediu luate: <input  type="text" value="' . $row['zileconcediu'] . '"  name="zileconcediu"  maxlength="2" size="2"> Zile
              </small>
            </div>';
}
?>
<!-- Sfarsit angajat -->
<?php
if( $_SESSION['user_id'] == '1' )
{
    echo '<button type="submit" name="submit" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o" ></i> Modifica</button>';
}
?> 
</form>

I have this form , but i need to use it for more users ex for user_id=1 to submit 1 form for user_id=2 to submit another form, can you guys help?

the database table have a column u_userid where 1 = admin 2,3,4,5,6,7 is normal user, each user has more columns wich i need to update data from database

Rohan Khude
  • 3,604
  • 5
  • 43
  • 37
  • 4
    I didn’t even understand the question – omkaartg Dec 07 '17 at 21:29
  • _"when it should insert it only on user id = 2"_ That's not what your `if` statement is doing... – Alex Howansky Dec 07 '17 at 21:30
  • You can’t insert for specific user id you can only select, delete, and edit the record – omkaartg Dec 07 '17 at 21:30
  • 1
    So are you _inserting_ or _updating_? You should include the code that handles the form submit. And "it insert the data from form for all users" isn't understandable at all. – Patrick Q Dec 07 '17 at 21:38
  • Well im actually updating – Pirjol Nelu Dec 07 '17 at 21:46
  • Hi Pirjol - has your question been answered? Do you have any further parts to _this_ question that we can help with? If your question has been more-or-less answered by someone below, please use the checkmark to choose a best answer and to close out this question. Also, please upvote any answers that you found helpful (you can also upvote the "correct" answer if it was helpful). Otherwise, please *edit* your question to explain how we can help further. – cssyphus Dec 09 '17 at 14:53

2 Answers2

1

You can fix it by making the If statement like this... If($_SESSION['user_id'] == '2')
{

Use the update feature and then add a ‘where user_id = 1’ in the end of your statement

omkaartg
  • 2,228
  • 1
  • 6
  • 21
1

You have two options:

  1. You can use a form, which requires that you have the
    <form action="nameOfYourBackEndFile.php" method="post">
           Your existing stuff in here
    </form>
    tags surrounding your existing code AND you need a button type="submit" to submit the form.

or

  1. You can use javascript/jQuery. Either way is fine.

Also, you need a way to identify which user this form is being filled out for. You have the user_id in a session variable, so why not use that? Your submit button can look like this:

<button id="submit_<?php echo $_SESSION['user_id']; />" type="submit">Go</button>

See this example for more information about what you are trying to do:

How can I make, when clicking a button, send an email with the data included from the form?

PHP - Secure member-only pages with a login system

AJAX request callback using jQuery

cssyphus
  • 31,599
  • 16
  • 79
  • 97
  • if you watch here https://jsfiddle.net/k8pjfr0h/ you will understand what i mean. aftear each STRONG text there is user informations that only admin (me) can edit , the users can only see they'r info – Pirjol Nelu Dec 07 '17 at 21:49
  • 1
    You really have multiple questions. Your first question is, `"How do I send the information typed by a user to a back-end file so that it can be added into a MySQL database"`. Your next question is, `"How do I receive data from a form or from ajax in a back-end PHP file?"`. Your third question is `"How do I update an existing record in MySQL with new data, and then return an answer to the user?"` You should study the examples I provided - read them over and over until you understand - and then try to implement your solution. By the way, AJAX is the way to go. Forms are so pre-2000. – cssyphus Dec 07 '17 at 21:57
  • Sorry, please do not misunderstand. I was not being critical. I was attempting to help you understand your needs. It is a good idea to break down a complex task into smaller steps. Take each task by itself and solve that. One step at a time. – cssyphus Dec 07 '17 at 22:17
  • its ok :D dont worry m8t :P – Pirjol Nelu Dec 07 '17 at 22:19