If the user inputs a blank/null value at $name
then id like to make a alert box that says please enter the missing values
ex:
if ($name==' ' or $address==' ' or $age==' ')
{
// Alert Box saying "Please enter the missing values"
}
Thank you to those who will help...
Love this helpful forum <3
Alert box on PHP if name==NULL
Moderator: General Moderators
-
ShadowSkill
- Forum Newbie
- Posts: 22
- Joined: Sun Jan 01, 2012 5:45 am
Re: Alert box on PHP if name==NULL
Remember, PHP is a server side language and only works in the server, not the browser, so it can't possibly detect anything that the user does. You have to do this in Javascript. Rephrase your question and post in the Javascript forum here.
Re: Alert box on PHP if name==NULL
Since this looks like form validation, you can use PHP to do it. Place your JS alert code inside the PHP if condition.
or something to that effect.
Code: Select all
if (empty($name) || empty($address))
{
echo "<script type=\"text/javascript\">alert('All fields must be completed');</script>";
}Re: Alert box on PHP if name==NULL
@ShadowSkill: Be sure you understand what Celauran is saying. He described a way to test for a blank required field after the form has been submitted to the PHP script that will process the data, to send a new page back to the browser, in which the pop-up will appear, but unless you include substantial additional code, all the previous form data will be reset, which is not very user-friendly. It is still Javascript that creates the alert pop-up. Usually you would want to check for blank required fields before submitting the form, since you don't want to process the data until the omission has been corrected. To do that, you would use Javascript, and thus this thread should be moved to our Javascript forum.
-
ShadowSkill
- Forum Newbie
- Posts: 22
- Joined: Sun Jan 01, 2012 5:45 am
Re: Alert box on PHP if name==NULL
Thanks will try to read more and understand more about Java...
I'm sorry about this, its just that i'm studying this where my professors doesn't even know PHP...
They only know HTML...
I'm sorry about this, its just that i'm studying this where my professors doesn't even know PHP...
They only know HTML...
Re: Alert box on PHP if name==NULL
That's a bummer. I know it happens (I used to teach database and Internet courses in a community college), but it shouldn't.ShadowSkill wrote:Thanks will try to read more and understand more about Java...
I'm sorry about this, its just that i'm studying this where my professors doesn't even know PHP...
They only know HTML...
Here are a few online tutorials that might help you:
http://www.maconstateit.net/tutorials/
http://www.w3schools.com/
http://www.tizag.com/
My recommendation is that you first learn HTML, then CSS, then Javascript (the 3 languages that are used by a browser), then PHP (the web server language).
Note that Javascript is NOT Java, not even close. They are 2 utterly different programming languages. Why did they name it Javascript? Everybody asks and there isn't a very satisfactory answer. Technically, its official name is ECMAScript, but nobody likes that, either.
Last edited by califdon on Sun Jan 22, 2012 10:22 pm, edited 1 time in total.
Reason: Added some references
Reason: Added some references