473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can this be done in PHP

I am new to PHP but not programming. I'd like to know if this can be done before I do more research on how to do it.

I have existing PHP code that I inherited. It reads a database
and displays data. I've added an edit button. What I want to do
is open a login window and get a username and password.
If the login is successful, the data display should change. If not
no difference.

Is this PHP do-able? Do I need the help of Javascript as well?
Thanks for any pointers in the right direction that you might
provide.

Ira
Mar 22 '08 #1
6 1756
Markus
6,050 Expert 4TB
Most things are possible with php.

What youre speaking of seems like an ajax problem, but at the moment i cant' give a hand - bedtime :D

Regards.
Mar 23 '08 #2
ronverdonk
4,258 Expert 4TB
You can do this is either PHP or in PHP along with Javascript (Ajax). What intrigues me is the function of the EDIT button.

You state that it is a (db row) display screen with an edit button. What is the function of that edit button? Do you want to edit the content of the database row and write it back into the db? After a login?

Please explain in a bit more detail.

Ronald
Mar 23 '08 #3
Right now, I have a function that displays the data in a reasonable format. When the user hits the "edit" button, a logon screen would appear. If there is a successful login, the data display function gets called again, but now one of the fields would now display as a hyper link. Clicking this hype rlink for any record gets a new window to edit the contents. This is the easy part because the code I inherited does the form and the resave to the database. All I need to do is get the login to work such that I can send the display function a flag telling what kind of display to do.
Apr 4 '08 #4
coolsti
310 100+
You could do this in various ways. One way would be a Javascript snippet that opens a popup window (a new window) while calling another php script, let us call this popup.php. This script can present the login forms for the user as well as a login button and to be nice, a cancel button. When the user clicks on login, a form on this popup window is submitted. With proper scripting and interpretation of submitted variables, it can call the same popup.php or you can just make a different script, say popup2.php. This script can then do the login authorization. If failed, you could have the login window appear again with a message that the login failed.

If success, you are ready to continue and how you do this is up to you. You can have the popup window script after the authorization is successful then present in the popupwindow whatever edit fields are needed for the database edit. After the user submits his values, if the receiving php script finds a validation error (user input something incorrect) the script can show once again the input fields with an appropriate error message.

If the edit was successful, and you want to refresh the main page so that updated results appear, you can have this done also with some javascript. Let us say the user submits the form in the popup window with his new values and these are ok, then the popupwindow php script can send a new page to the popupwindow with some javascript that calls a javascript function on the "opener" page (invoked from the popupwindow with the "opener" keyword) that resubmits the main page, and then closes the popupwindow.

This could all be done also and perhaps more elegantly with an iframe embedded on the main page, perhaps with <div> layers for showing and hiding login and edit forms, rather than using a popup window.

Steve, Denmark
Apr 4 '08 #5
I am beginning to see the light with this reply. In fact, I already have javascript that opens a login window. Are you suggesting that the submit button call what you refer to as popup.php? The popup.php would check the login values an act appropriately? If so, then my final question is how to I get the login variable values from javascript to popup.php.

Thanks VERY much!
Apr 5 '08 #6
coolsti
310 100+
You can do it several ways. The javascript opens a popup window and in doing so can call a php script to fill that window with html code showing the login fields. This doesn't even have to be a php script, it coud be just a static html file, but in my applications, I am always using php. But let us just call it "login.php".

The popup window is a little html page in its own right. It contains your log in fields, and you could have the php script that presents this window to the user make it encrypted with https so that the user is not sending his password as clear text. This window will contain a submit button (which for example says submit or log in) and this should be as a form of type Post to that the user name and ID is sent as post variables and not tacked on to the URL.

When submitted, the popup window will then call another php script. This can be the same php script "login.php" if you also send some hidden variable that indicates the user is submitting something. This simplifies showing the log in fields again in the event the user did not supply valid login information. But for the sake of clarity, let us call this script "login2.php". This php script gets the user's ID and password from the $_POST array and can then do whatever is needed to verify the user and password are valid.

Let us say the user has entered a valid ID and password. The script "login2.php" then does whatever tasks are needed after the user has been authenticated. But for this way of doing things with a popup window, you need somehow to give control over to the main window. You can do this by having login2.php output some javascript to the popup window which will 1) call a javascript function on the main page to, for example, refresh the page or do some other kind of submit and 2) close the popup window as you are now done with it.

To refer to the main window from a popupwindow in Javascript, you use the "opener" keyword. To close the popup window you use the Javascript command window.close(). I think you get the idea from this.

Again, you can do more or less the same using a hidden iframe and a div layer containing the log in fields, avoiding the need for a popup window. Instead of opening up a popup window with javascript, the javascript would make the div layer containing the login fields visible. The login or submit button would now call a javascript function to submit the iframe, calling a script that does the authentications, etc. and if the user is authenticated, it can then call the function on the main page to do a submit or refresh or whatever, now instead of referring to the main page javascript with "opener", you use "parent".

There may be more elegant ways to do this, what I describe just uses basic building blocks without any exotic tools like Ajax.

Hope that helps.

Steve, Denmark
Apr 5 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: itsharkopath | last post by:
Hi, Imagine a user in a hotspot, when he comes to the hotspot and tries to load a webpage (on the internet), he would automatically redirected to login page. I believe the following is to be...
9
by: Steven T. Hatton | last post by:
This was written for the gnu.g++.help list. It rather clearly spells out the most important feature of Java that I believe C++ lacks. I really don't believe the C++ Standard sepcifies enough for a...
16
by: jaialai technology | last post by:
I want to reload a url in a browser window so I do something like this: open(window.location.href= "www.yahoo.com"); ok, so now I want to do something when that page is done loading completely....
5
by: Morten Overgaard | last post by:
Hi I have a C# component which fires events. I want to catch these events in my MFC app compiled with the /clr. I know I can define a managed class in my MFC app which traps the events - but I...
11
by: Sharon | last post by:
I'm writing a new control derived from UserControl. I need to get an event when the control is done resizing. I tried the Resize, SizeChanged, Move and the Layout events and I also tried to...
3
by: Miguel Dias Moura | last post by:
Hi, When I subscribe a web site I usually receive an email to confirm my subscription. Only after I follow the link in the email my account gets activated. In general, how is this done? Can...
4
by: BrianDH | last post by:
Group Early this week I ask for examples on how to call a VB.NET Web Service and access its DataSet for a traditional ASP page. I was told, "you can't", "won't work", "not possible". Well I...
12
by: Ark | last post by:
Hello NG, I arrange data in structs like { members... uint16_t crc; more members, maybe... } Then I need to save them, up to and including crc, in non-volatile memory or a file, as the case...
2
by: maya | last post by:
http://news.yahoo.com/news?tmpl=index2&cid=703 down the page, under "More Stories", there's a section with two interchangeable divs which slide back and forth into view.. how is this done? I...
2
by: poolboi | last post by:
hey guys, i've done most of my web app. for searching almost done but then i got a small little problem with logging in i need to know how session tracking is done in perl if not my log in page...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.