473,396 Members | 1,671 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,396 software developers and data experts.

calling a javascript alert from php

hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?

Jul 13 '06 #1
13 18649
monomaniac21 wrote:
hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?

I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before* the
page is displayed. Therefore, Php cannot popup an alert like JavaScript
(which runs on the *client computer after* the page is loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request to
the server to display a new page with (2) as a form or hyperlinks.
Clicking on Y or N must return to the server again in able to perform
the action.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*****************************
Jul 13 '06 #2
Chuck Anderson wrote:
monomaniac21 wrote:
>hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?

I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before* the
page is displayed. Therefore, Php cannot popup an alert like JavaScript
(which runs on the *client computer after* the page is loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request to
the server to display a new page with (2) as a form or hyperlinks.
Clicking on Y or N must return to the server again in able to perform
the action.
or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-

Jul 13 '06 #3
David Haynes wrote:
Chuck Anderson wrote:
>monomaniac21 wrote:
>>hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before* the
page is displayed. Therefore, Php cannot popup an alert like JavaScript
(which runs on the *client computer after* the page is loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request to
the server to display a new page with (2) as a form or hyperlinks.
Clicking on Y or N must return to the server again in able to perform
the action.

or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-
But that's not "triggered in Php" and is simply JavaScript.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*****************************
Jul 13 '06 #4
Chuck Anderson wrote:
David Haynes wrote:
>Chuck Anderson wrote:
>>monomaniac21 wrote:

hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before*
the page is displayed. Therefore, Php cannot popup an alert like
JavaScript (which runs on the *client computer after* the page is
loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request
to the server to display a new page with (2) as a form or hyperlinks.
Clicking on Y or N must return to the server again in able to perform
the action.

or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-
But that's not "triggered in Php" and is simply JavaScript.
Yes, but you had already provided "you can't get there from here"
answer. Sometimes it pays to offer alternatives rather than just to
answer the question someone has asked.

-david-

Jul 13 '06 #5
"monomaniac21" <mc******@googlemail.comwrote in message
news:11**********************@35g2000cwc.googlegro ups.com...
hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
Not by PHP alone but have a look at http://www.xajaxproject.org/ to things
like this...

Norm
Jul 13 '06 #6
David Haynes wrote:
Chuck Anderson wrote:
>David Haynes wrote:
>>Chuck Anderson wrote:

monomaniac21 wrote:

hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
>
>
I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before*
the page is displayed. Therefore, Php cannot popup an alert like
JavaScript (which runs on the *client computer after* the page is
loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request
to the server to display a new page with (2) as a form or
hyperlinks. Clicking on Y or N must return to the server again in
able to perform the action.
or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-
But that's not "triggered in Php" and is simply JavaScript.
Yes, but you had already provided "you can't get there from here"
answer. Sometimes it pays to offer alternatives rather than just to
answer the question someone has asked.

-david-
I am following this thread because I am trying to do the same thing.
Problem is I do not know php\javascript all that well. I had posed my
code to this newsgroup but received no answer. So I do not know if I can
do what I am trying to do or I am just so far off that it does not
warent an answer. This is what I have so far. I can not get to work and
have comment out what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERVER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE='.$_POST[id].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK()>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_object($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javascript>';
//echo 'function getPK() {';
//echo
"document.author.author_pk.options[document.author.author_pk.selectedIndex].value
";
//echo '}';
//echo "</script>";

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Jul 14 '06 #7
David Haynes wrote:
Chuck Anderson wrote:
>David Haynes wrote:
>>Chuck Anderson wrote:

monomaniac21 wrote:

hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
>
>
I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before*
the page is displayed. Therefore, Php cannot popup an alert like
JavaScript (which runs on the *client computer after* the page is
loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request
to the server to display a new page with (2) as a form or
hyperlinks. Clicking on Y or N must return to the server again in
able to perform the action.
or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-
But that's not "triggered in Php" and is simply JavaScript.
Yes, but you had already provided "you can't get there from here"
answer. Sometimes it pays to offer alternatives rather than just to
answer the question someone has asked.

-david-
I am following this thread because I am trying to do something simular.
That is pass value back to php on a select ONCHANGE=. Problem is I do
not know php\javascript all that well. I had posted my code to this
newsgroup but received no answer. So I do not know if I can do what I am
trying to do or I am just so far off that it does not warent an answer.
This is what I have so far. I can not get to work and have comment out
what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERVER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE='.$_POST[id].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK()>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_object($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javascript>';
//echo 'function getPK() {';
//echo
"document.author.author_pk.options[document.author.author_pk.selectedIndex].value
";
//echo '}';
//echo "</script>";
--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Jul 14 '06 #8
Rik
IchBin wrote:
I am following this thread because I am trying to do something
simular.
That is pass value back to php on a select ONCHANGE=. Problem is I do
not know php\javascript all that well. I had posted my code to this
newsgroup but received no answer. So I do not know if I can do what I
am
trying to do or I am just so far off that it does not warent an
answer.
javascript/HTML is just plain text to PHP, you're better of asking an a
javascript group how you should accomplish what you're trying, get the
javascript code for that, and then build it in PHP.

What is it exactly you're trying to accomplish, because I can't make it out
from the following code?
(and BTW: <selectdoesn't have a cols attribute...).
This is what I have so far. I can not get to work and have comment out
what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERVER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20
ONCHANGE='.$_POST[id].'>'; //echo '<SELECT NAME=author_pk SIZE=20
COLS=20 ONCHANGE=getPK()>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_object($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javascript>';
//echo 'function getPK() {';
//echo
"document.author.author_pk.options[document.author.author_pk.selectedIndex].
value
";
//echo '}';
//echo "</script>";
I really just know the basics of javascript, but:

--------------------------------------------------------
<script type="text/javascript">
function getPK(arg){
alert(arg);
}
</script>
<form name="testform">
<select name="author_pk" size="20"
onchange="getPK(this.options[this.selectedIndex].value)">
<option value="first">foo</option>
<option value="another">bar</option>
<option value="last">baz</option>
</select>
</form>
--------------------------------------------------------

or alternatively:
--------------------------------------------------------
<script type="text/javascript">
function getPK(){

alert(document.testform.author_pk.options[document.testform.author_pk.select
edIndex].value);
}
</script>
<form name="testform">
<select name="author_pk" size="20"
onchange="getPK(this.options[this.selectedIndex].value)">
<option value="first">foo</option>
<option value="another">bar</option>
<option value="last">baz</option>
</select>
</form>
--------------------------------------------------------

or, if you make & know an ID:
--------------------------------------------------------
<script type="text/javascript">
function getPK(){
selectbox = document.getElementById('author_pk');
alert(selectbox.options[selectbox.selectedIndex].value);
}
</script>
</head>
<body>
<form name="testform">
<select id="author_pk" name="author_pk" size="20" onchange="getPK()">
<option value="first">foo</option>
<option value="another">bar</option>
<option value="last">baz</option>
</select>
</form>
--------------------------------------------------------

That's how you can get the value.

Now, passing it back to PHP? That will require a trip to the server, and why
would you want to know it before the form is submitted? As it requires a
trip to the server, you could just as easily read the $_POST value.

If you want to do something on your page after selecting the something, you
either should have sent al the relevant info to the server in the HTML or in
js, or you'd have to make use of XMLHTTPRequests
(http://ajaxpatterns.org/XMLHttpRequest_Call).

That's going a bit to far in this group, I'd say: check the pointers, and if
things are unclear, ask comp.lang.javascript.

--
Rik Wasmus
Jul 14 '06 #9
IchBin wrote:
I am following this thread because I am trying to do something simular.
That is pass value back to php on a select ONCHANGE=. Problem is I do
not know php\javascript all that well. I had posted my code to this
newsgroup but received no answer. So I do not know if I can do what I am
trying to do or I am just so far off that it does not warent an answer.
This is what I have so far. I can not get to work and have comment out
what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERVER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE='.$_POST[id].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK()>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_object($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javascript>';
//echo 'function getPK() {';
//echo
"document.author.author_pk.options[document.author.author_pk.selectedIndex].value
";
//echo '}';
//echo "</script>";
IchBin:
You don't need to use javascript at all to do what you want to do.
You can simply let PHP do all the work.
Take a look at this example based upon your posting:

<?php
// an example of a monolithic form processor in php
// connect to mysql database
// @note: add a lot more error checking.
mysql_connect($hostname, $username, $password);
mysql_select_db($database);

// This form uses the POST method, so process any post selections here
if( isset($_POST['author_pk']) ) {
// do whatever you need to do with the author_pk
$sql = "select * from book_detail where author_pk = {$_POST['author_pk']}";
$detail = mysql_query($sql);
}

// main form query
$sql = "SELECT * from users order by lastname, firstname, middlename ";
$result = mysql_query($sql);

mysql_close();
?>
<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF'];?>"
<SELECT NAME="author_pk" SIZE="20" COLS="20">
<?php
// a loop to populate the select options
while( $row = mysql_fetch_object($result) ) {
printf("<option value=\"%d\">%s, %s, %s, %s, %s</option>\n",
$row->id, $row->TITLE, $row->lastname,
$row->firstname, $row->middlename, $row->SUFFIX);
}
mysql_free_result($result);

// display any book details based on the user's selection
if( isset($detail) ) {
while( $row = mysql_fetch_assoc($detail) ) {
printf("Title: %s<br>\n", $row['title']);
}
}
?>
</SELECT>
</FORM>

Jul 14 '06 #10
David Haynes wrote:
IchBin wrote:
>I am following this thread because I am trying to do something
simular. That is pass value back to php on a select ONCHANGE=. Problem
is I do not know php\javascript all that well. I had posted my code to
this newsgroup but received no answer. So I do not know if I can do
what I am trying to do or I am just so far off that it does not warent
an answer. This is what I have so far. I can not get to work and have
comment out what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERVER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE='.$_POST[id].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK()>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_object($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javascript>';
//echo 'function getPK() {';
//echo
"document.author.author_pk.options[document.author.author_pk.selectedIndex].value
";
//echo '}';
//echo "</script>";

IchBin:
You don't need to use javascript at all to do what you want to do.
You can simply let PHP do all the work.
Take a look at this example based upon your posting:

<?php
// an example of a monolithic form processor in php
// connect to mysql database
// @note: add a lot more error checking.
mysql_connect($hostname, $username, $password);
mysql_select_db($database);

// This form uses the POST method, so process any post selections here
if( isset($_POST['author_pk']) ) {
// do whatever you need to do with the author_pk
$sql = "select * from book_detail where author_pk =
{$_POST['author_pk']}";
$detail = mysql_query($sql);
}

// main form query
$sql = "SELECT * from users order by lastname, firstname, middlename ";
$result = mysql_query($sql);

mysql_close();
?>
<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF'];?>"
<SELECT NAME="author_pk" SIZE="20" COLS="20">
<?php
// a loop to populate the select options
while( $row = mysql_fetch_object($result) ) {
printf("<option value=\"%d\">%s, %s, %s, %s, %s</option>\n",
$row->id, $row->TITLE, $row->lastname,
$row->firstname, $row->middlename, $row->SUFFIX);
}
mysql_free_result($result);

// display any book details based on the user's selection
if( isset($detail) ) {
while( $row = mysql_fetch_assoc($detail) ) {
printf("Title: %s<br>\n", $row['title']);
}
}
?>
</SELECT>
</FORM>
David, thank you so much for helping me out. I do not have much more
hair to pull out. I am a Java person. Anyway, I understand a lot more
after you sample code.

As an aside, this is my own little project to learn php and etc. I
already have a complete Java\swing application written around this DB so
I figure I could lean away from J2EE and try PHP. It is a different animal.

This DB is a Quotes DB. I have been building over the last few years.
Just a personal interest. I have around 1300 authors and over 32,000
quotes along with detail\quote like external Links and references for
each quote. And naturally detail information about the author.

I did mix your code with mine. The only problem I am having is with the
dropdown object. When I run the program the following displays: on and
on and not in the dropdown..

, , , , , Abbey, Edward, , , Abbott, William, Alexander, , Abelard,
Pete, , , Accius, Lucius, , , Acheson, Dean, , , Ackerman, Diane, , ,
Adams, Abigail, Smith, , Adams, Ansel, , , Adams, Bryan, , , Adams,
Douglas, , , Adams, Franklin, Pierce, , Adams, Henry, , , Adams, Joey,
Lauren, , Adams, John, , , Adams, John, Quincy, , Adams, Scott, , ,
Addison, Joseph, , , Ade, George, , , Adler, Alfred, , , Adler,
Mortimer, Jerome, , Adorno, Theodor, , , Aeschylus, , , , Aesop, , , ,
Afer, Publius, Terentius, , Agathon, , , , Agesilaus, , , II , Aiken,
George, , , Aiken, Howard, , , Alcott, Amos, Bronson, , Alcott, Louisa,
May, , Alcuinus or Ealhwine, Flaccus, Albinu, , Alda, Alan, , ,
Alexander, Shana, , , Ali-Haj, Muhammad, , , Allen, Fred, , , Allen,
Woody, , , Alzado, Lyle, , , Amiel, Henri-Frédéric, , , Amory,
Cleveland, , , Anaxagoras, , , , Ancient Chinese Curse, , , , Andersen,
Hans, Christian, , Angell, George, Thorndike, , Angelou, Maya, , The
Princess, Anne, , , , Princess Royal , Anonymous, , , , Anouilh, Jean, ,
Saint, Anselm, , , of Canterbury , Anthony, Susan, B., , Antiphanes, , ,
, Antisthenes,

Here is the code but I guess the concern is the dropdown.

<?php
//
// Open DB
include 'library/opendb.php';

// This form uses the POST method, so process any post selections here
if( isset($_POST['author_pk']) ) {
// do whatever you need to do with the author_pk
// $sql = "select * from book_detail where author_pk =
{$_POST['author_pk']}";
// $detail = mysql_query($sql);
}
//
// main form query
$sqlcmd = 'select id, TITLE, lastname, firstname, middlename, SUFFIX
from author_detail order by lastname, firstname, middlename';
$result = mysql_query($sqlcmd);
if (!$result) {
die('Database Error: ' . mysql_error());
exit;
}
//
// Close DB
include 'library/closedb.php';
?>

<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF'];?>"
<SELECT NAME="author_pk" SIZE="20" COLS="20">

<?php
// a loop to populate the select options
while( $row = mysql_fetch_object($result) ) {
printf("<option value=\"%d\">%s, %s, %s, %s, %s</option>\n",
$row->id, $row->TITLE, $row->lastname,
$row->firstname, $row->middlename, $row->SUFFIX);
}

mysql_free_result($result);

// display any book details based on the user's selection
if( isset($detail) ) {
// while( $row = mysql_fetch_assoc($detail) ) {
// printf("Title: %s<br>\n", $row['title']);
// }
}
?>
</SELECT>
</FORM>

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Jul 14 '06 #11
IchBin wrote:
David, thank you so much for helping me out. I do not have much more
hair to pull out. I am a Java person. Anyway, I understand a lot more
after you sample code.

As an aside, this is my own little project to learn php and etc. I
already have a complete Java\swing application written around this DB so
I figure I could lean away from J2EE and try PHP. It is a different animal.

This DB is a Quotes DB. I have been building over the last few years.
Just a personal interest. I have around 1300 authors and over 32,000
quotes along with detail\quote like external Links and references for
each quote. And naturally detail information about the author.

I did mix your code with mine. The only problem I am having is with the
dropdown object. When I run the program the following displays: on and
on and not in the dropdown..

, , , , , Abbey, Edward, , , Abbott, William, Alexander, , Abelard,
Pete, , , Accius, Lucius, , , Acheson, Dean, , , Ackerman, Diane, , ,
Adams, Abigail, Smith, , Adams, Ansel, , , Adams, Bryan, , , Adams,
Douglas, , , Adams, Franklin, Pierce, , Adams, Henry, , , Adams, Joey,
Lauren, , Adams, John, , , Adams, John, Quincy, , Adams, Scott, , ,
Addison, Joseph, , , Ade, George, , , Adler, Alfred, , , Adler,
Mortimer, Jerome, , Adorno, Theodor, , , Aeschylus, , , , Aesop, , , ,
Afer, Publius, Terentius, , Agathon, , , , Agesilaus, , , II , Aiken,
George, , , Aiken, Howard, , , Alcott, Amos, Bronson, , Alcott, Louisa,
May, , Alcuinus or Ealhwine, Flaccus, Albinu, , Alda, Alan, , ,
Alexander, Shana, , , Ali-Haj, Muhammad, , , Allen, Fred, , , Allen,
Woody, , , Alzado, Lyle, , , Amiel, Henri-Frédéric, , , Amory,
Cleveland, , , Anaxagoras, , , , Ancient Chinese Curse, , , , Andersen,
Hans, Christian, , Angell, George, Thorndike, , Angelou, Maya, , The
Princess, Anne, , , , Princess Royal , Anonymous, , , , Anouilh, Jean, ,
Saint, Anselm, , , of Canterbury , Anthony, Susan, B., , Antiphanes, , ,
, Antisthenes,

Here is the code but I guess the concern is the dropdown.

<?php
//
// Open DB
include 'library/opendb.php';

// This form uses the POST method, so process any post selections here
if( isset($_POST['author_pk']) ) {
// do whatever you need to do with the author_pk
// $sql = "select * from book_detail where author_pk =
{$_POST['author_pk']}";
// $detail = mysql_query($sql);
}
//
// main form query
$sqlcmd = 'select id, TITLE, lastname, firstname, middlename, SUFFIX
from author_detail order by lastname, firstname, middlename';
$result = mysql_query($sqlcmd);
if (!$result) {
die('Database Error: ' . mysql_error());
exit;
}
//
// Close DB
include 'library/closedb.php';
?>

<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF'];?>"
<SELECT NAME="author_pk" SIZE="20" COLS="20">

<?php
// a loop to populate the select options
while( $row = mysql_fetch_object($result) ) {
printf("<option value=\"%d\">%s, %s, %s, %s, %s</option>\n",
$row->id, $row->TITLE, $row->lastname,
$row->firstname, $row->middlename, $row->SUFFIX);
}

mysql_free_result($result);

// display any book details based on the user's selection
if( isset($detail) ) {
// while( $row = mysql_fetch_assoc($detail) ) {
// printf("Title: %s<br>\n", $row['title']);
// }
}
?>
</SELECT>
</FORM>
IchBin:
1. I made a mistake in the sample code I sent you in that the <FORM>
tag is not properly terminated. The line should read:
<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF']'?>">
The last '>' was missing.
2. if you run the SQL query from the mysql command line, do you get
what you expect?
Hint:
Add 'echo $sqlcmd;exit;' after the $sqlcmd= line and then cut and
paste into a mysql command session
3. Adjust the sqlcmd and add 'limit 1' so that only one row is returned
while debugging. If it is still not right, post the code and the output
and I'm sure folks here will be all over it offering advice.

-david-

Jul 14 '06 #12
David Haynes wrote:
>
IchBin:
1. I made a mistake in the sample code I sent you in that the <FORM>
tag is not properly terminated. The line should read:
<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF']'?>">
The last '>' was missing.
2. if you run the SQL query from the mysql command line, do you get
what you expect?
Hint:
Add 'echo $sqlcmd;exit;' after the $sqlcmd= line and then cut and
paste into a mysql command session
3. Adjust the sqlcmd and add 'limit 1' so that only one row is returned
while debugging. If it is still not right, post the code and the output
and I'm sure folks here will be all over it offering advice.

-david-
David, thanks for all your help and tips. The sql is correct.

IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Jul 14 '06 #13
monomaniac21 wrote:
hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
print "<scriptalert('Hello world'); </script>";

(needs some tidying, and watch out for the quotes)

C.
Jul 16 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kim Forbes | last post by:
Hello all, I have simple function that I call from an alert box alert(testScore); It works fine. Unfortunately, I do not like the sound and Exclamation point icon that appears. I'd like a...
14
by: Michael Winter | last post by:
In an attempt to answer another question in this group, I've had to resort to calling the DOM method, Node.removeChild(), using a reference to it (long story...). That is, passing Node.removeChild....
5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
18
by: Simula | last post by:
I am developing an HTML javascript application and I want to preserve state in a way that can be book-marked. I chose HTML anchors as a means of preserving state. When the application changes...
10
by: Tony Rice | last post by:
If I've loaded a set of functions in a webdocument like this: <script language="JavaScript" type="text/javascript" src="/js/foo.js"</script> Shouldn't I be able to call a function from...
3
by: Tanmaya Kulkarni | last post by:
Hi, I have a web application where I need to call backend C#/VB.Net functions from javascript. Is it possible..and how? Thanks, Tanmaya
16
by: deepres | last post by:
Hi, I have the following problem. In my application I'm dynamically replacing some of web-page content. For example, I have something like that: <span id="ui_tr_22_1_treeJ_span" > <div...
4
omerbutt
by: omerbutt | last post by:
hi there i am making an application in which i have a drop down menu which onchange passes a value(this.value) to a js function which gets the value and calls an ajax routine and passes that value...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.