PHP MySQL Help!

Status
Not open for further replies.

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hello all,

I am trying to make something which will be useful for job application in hotel's.
I have a slight problem, whenever I go to send a job app, I have to put the id of the app in manually through a text box, rendering it pretty useless to other users unless they knew what id to put.
Is there any way I can get the last id from the database and increment it by one each time the form is sent.
For instance each time the form button 'Send' is clicked, it goes to the file which inserts everything into the db and if theres an id '4' it put's the next one in at '5'.

Here is my code so far, also, I know I haven't used the variables at the top yet... please don't point it out.

PHP:
<?php
    $id = $_POST[id];
    $why = $_POST['why'];
    $job = $_POST['job'];
    $username = $_POST['username'];
    $experience = $_POST['experience'];
   
    $con = mysql_connect("localhost","root","password");
   
        if (!$con)
            {
                die('Could not connect: ' . mysql_error());
            }
                   
        mysql_select_db("revdb", $con);
       
        $mysql_id = mysql_query("SELECT id FROM `jobs` LIMIT 1");
       
        $query = mysql_query("INSERT INTO jobs (id, why, job, username, experience, age, other)
                VALUES(3,'I love it', 'Mod', 'Josh', 'None', 16, 'None')");
       
        if($query){
            echo "Success!";
        }
        else{
            echo "Error: " . mysql_error();
        }
           
           
   
    mysql_close($con);
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,639
2,397
So you want to get the ID of the latest record in the database?

PHP:
$num = mysql_num_rows("SELECT * FROM `jobs`");

Also, use mysql_real_escape_string() around your $_POST variables when entering data into a database.
 
Status
Not open for further replies.

Users who are viewing this thread

Top