Jump to content

[SOLVED] PHP/mySQL INSERT and UPDATE questions


scarlson

Recommended Posts

Here is what I am wanting to do but not sure exactly how to. 

 

Once a user logs in, they are now sent to a setup page to start entering in their personal information along with details of their items they want to post.

 

What I want is if the user has already created a "ticket" their info will be showing already.  If it's their first time there, then all the text area boxes will be blank and they will be able to create their new "ticket" and INSERT that into the database.

 

The users who already have a ticket created can also edit this ticket so a UPDATE would be needed.

 

Anyone have examples or suggestions on how I should go about this?

 

Thanks in advance,

 

Scott

Link to comment
Share on other sites

When the user Registers, you would want to build their DB row at that time.

 

When they log in, just have a form come up that reads their Row and populates any data that they already have in their record.

 

Provide a update button that UPDATES the DB with the new data.

Link to comment
Share on other sites

I don't want them to create this ticket when they register because I built in a email verification for them to verify their account.  Once verified they can go to the login page to login.  Then redirected to this create ticket page that might already have info depending if they are an exisiting user or not.  I don't want to create 2 different .php files one for the first time setting up the ticket and another one for editing a ticket, unless I have to.

Link to comment
Share on other sites

On the page, use their id and query the database for their record. If the query returned a row, put the values into the value="..." parameters in the form.

 

When they submit the form, use their id and query the database for their record. If the query returned a row, they already have a row and you need to perform an UPDATE query. If the query did not return a row, you need to perform an INSERT query.

 

Pretty basic if() {// a row was found, do an UPDATE } else {// no row found, do an INSERT } logic -

 

if(mysql_num_rows($result) > 0)
{
// They already have a record, use an UPDATE query
} else {
// They don't have a record, use an INSERT query.
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.