Page 1 of 1
Alert box on PHP if name==NULL
Posted: Sat Jan 21, 2012 7:32 pm
by ShadowSkill
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
Re: Alert box on PHP if name==NULL
Posted: Sat Jan 21, 2012 8:27 pm
by califdon
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
Posted: Sat Jan 21, 2012 10:21 pm
by Celauran
Since this looks like form validation, you can use PHP to do it. Place your JS alert code inside the PHP if condition.
Code: Select all
if (empty($name) || empty($address))
{
echo "<script type=\"text/javascript\">alert('All fields must be completed');</script>";
}
or something to that effect.
Re: Alert box on PHP if name==NULL
Posted: Sun Jan 22, 2012 11:57 am
by califdon
@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.
Re: Alert box on PHP if name==NULL
Posted: Sun Jan 22, 2012 9:50 pm
by ShadowSkill
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...
Re: Alert box on PHP if name==NULL
Posted: Sun Jan 22, 2012 10:05 pm
by califdon
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...
That's a bummer. I know it happens (I used to teach database and Internet courses in a community college), but it shouldn't.
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.