0

Thanks for your patience, i'm still trying to learn I've gotten most of my stuff on my website to work, but i'm trying to do one more thing

I have a WORKING insertion script for a mysql database using a php page that forces the CharName in the database to match their site username. Additionally I have a WORKING update script that will allow a user to update their information.

What I need is a if/else for the following situation

User clicks 'insert new data' their CharName exists in the database so instead of loading the INSERT NEW page it redirects them to the UPDATE page.

Ex. JohnDoe has already input their character information into the database. The next time they click the 'insert.php' link the site would see 'this user has already a record in the database' and sends them to the 'update.php' page instead.

ELSE

JohnDoe actually has not got a record under his name in the database and the 'insert.php' page allows them to continue loading the insert page.

I'm sorry if thats confusing at all but I've searched all over to find what I need in order to make this work. Please help I would greatly appreciate it. And feel free to ask any additional questions you need to. Thanks much.

3
Contributors
5
Replies
34
Views
3 Years
Discussion Span
Last Post by Banderson
1

You simply need to do a query to the table searching for that user name. If one row is returned then they have already created their account so redirect to the update page. If no rows are returned, they don't exist in the database so redirect to the insert page.

So,on the link click run a SELECT statement with the user name as a parameter. The result tells you which option you redirect to.

0

you dont happen to know an example of this do you? that I can look at

0

Assuming you have the user name stored in a variable do a SELECT against the database

SELECT username FROM table_name WHERE username = ' . $username . ';'

I'm not sure what PHP version or framework you're using so the method of runnign the query and checking the result will vary but once you have a result check the value against $username. Based on the result, redirect as needed

$result = .. do query with PDO, ORM or whatever is workig in your situation

if($result[0] == $username) {
  $url = user exists page
} else {
  $url = user doens't exist page
}

header('Location: '.$url);

This is some pretty rough pseudo code but it should be enough to give you an idea.

0

After some playing I got it :-D tyvm for your help I appreciate it :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.