0

so i have this website where i can log in and then make a job offer from the account, all my accounts have an auto increment id in my database. if i fill in this form it'll save all the information to my database with a new id for the job offer but i also need to link the id from the logged in account with it, whenever i save it it just says 0 at the id cause i haven't linked it. any idea how i have to do this?

<form method="post">
    <div id="formbackground"><br><br>
        <label for="adres">Functie: </label>
        <br> <textarea rows="4" cols="32" name="functie" required></textarea> <br><br>
        <label for="adres">Omschrijving: </label>
        <br> <textarea rows="4" cols="32" name="omschrijving" required></textarea> <br><br> 
        <label for="adres">Salaris: </label>
        <br> <textarea rows="4" cols="32" name="salaris" required></textarea> <br><br>
        <input type="submit" name="verzenden" value="Vacature publiceren" class="btn-login">
    </div>
</form>

</div>

<?php

if(isset($_POST['verzenden'])){

    $conn = mysqli_connect('localhost', 'root', '', 'powerjobs');
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 

    $functie = htmlspecialchars($_POST['functie']);
    $omschrijving = htmlspecialchars($_POST['omschrijving']);
    $salaris = htmlspecialchars($_POST['salaris']);

    $sql = "INSERT INTO vacature 
                    (functie, omschrijving, salaris)
            VALUES ('$functie', '$omschrijving', '$salaris')";

    if ($conn->query($sql) === TRUE) {
        header("Location: inlog-bedrijf.php");  
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
}
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Melissa
  • 1
  • 2
  • Save your users unique value to the database as well? – GrumpyCrouton Aug 01 '17 at 13:08
  • 2
    Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Aug 01 '17 at 13:09
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Aug 01 '17 at 13:10
  • @GrumpyCrouton thats the problem, i dont know how to – Melissa Aug 01 '17 at 13:11
  • 1
    We cannot see anywhere where you have access to the currently logged in user information? – RiggsFolly Aug 01 '17 at 13:12
  • There must be a 1,000,000 tutorials out there that you could have a look at that cover this basic process – RiggsFolly Aug 01 '17 at 13:13
  • @RiggsFolly would be great if you'd help me find them, i have no idea how to look for this problem when i don't know what it's "called" – Melissa Aug 01 '17 at 13:14
  • https://www.tutorialspoint.com/mysql/ – RiggsFolly Aug 01 '17 at 13:17
  • @Melissa Given what you say, I doubt we could help you even if we tried, you don't seem to have aquired the basic skills regarding programming, since you admit to be unable to understand your errors, search for clues and solutions and learn from documentation. My belief is that you only want a ready solution from us so that you can continue to pass as a programmer. – Sarkouille Aug 01 '17 at 13:19
  • @ksjohn i don't have any errors, i mean everything is fine but i only need to link the id. this is something i have to finish before i go back to school and since it's summer break rn i can't get any help from anyone but the internet – Melissa Aug 01 '17 at 13:33
  • @Melissa That's the point. The Internet is full of resource to learn how to do that. You should ask for help if everything else fails. Besides, you didn't give anough information. From where I stand, I cannot know in what form you have the user_id, or even if you actually have that data at hand. – Sarkouille Aug 01 '17 at 14:02

0 Answers0