This is the first time I've ever tried using Javascript, so please bear with me. I searched for an example on the web, and found something that said it should work, but doesn't. I have a PHP web page that I've added a javascript to that displays a prompt box. (I probably should be using something with an "ok" and "cancel" button.) I want to be able to pass the users answer from the javascript to a variable in the PHP. I've posted the code below, so if someone can tell me where I've screwed this up I'd appreciate it. The javascript is hilighted in red.
Code:
<?php
// Updated: Friday July 10, 2009 - 4:31 AM
//create_tables.php
include("../INCLUDES/dbconnect.php");
//
?>
<html>
<head>
<title>Drop Author Table Confirmation</title>
<LINK href="/~peterv/css/mybooks_form.css" type="text/css" rel=stylesheet>
[b][COLOR=red]<script type="text/javascript">
function show_prompt()
{
var reply=prompt("Enter Yes to continue, No to exit");
if (reply!=null && reply!="")
{
location.href="create_tables.php?reply=" + reply;
} else {
document.write("Invalid entry.")
}
}
</script>[/color][/b]
</head>
<body>
<!--<h3>* denotes required field!</h3>-->
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<div>
<fieldset><legend><b><em>Select Table To Create</em></b></legend>
<div class="required">
<label for="author"> Author</label><input type="radio" name="process_what" id="author" value="author"/>
</div>
<div class="required">
<label for="book"> Book</label><input type="radio" name="process_what" id="book" value="book"/>
</div>
</fieldset>
<fieldset><legend><b><em>Confirm Dropping Table</em></b></legend>
<div class="required">
<center><h4> You have to DROP the table before creating it.</h4></center>
<center><h4> Are you 100% SURE????</h4></center><br />
<!--<label for="name">Drop(Y/N):</label>-->
<!--<input id="drop" type="text" name="drop" maxlength="21" /><br />-->
<!--<label for="submit"></label>-->
<!--<input id="submit" type="submit" value="Drop Table" /><br />-->
<center><input id="submit" type="button" onclick="show_prompt()" value="Click to confirm" /></center>
</div>
</fieldset>
</div>
<?php
[b][COLOR=blue]$reply = $_POST['reply'];
echo "<br>reply: $reply";[/color][/b] <= returns blank!
$reply = strtoupper($_POST['drop']);
$process_what = $_POST['process_what'];
if ($reply == 'Y') {
switch ($process_what) {
case 'author':
$query ="DROP TABLE IF EXISTS MYAUTHORS";
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}else{
echo "Authors table dropped.<br>";
//
$query ="create table MYAUTHORS
(authorid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
lname VARCHAR(20) NOT NULL,
mname VARCHAR(20),
fname VARCHAR(20))";
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}else{
echo "";
echo "Authors table created.";
// $message .= 'Whole query: ' . $query;
// die($message);
}
}
break;
case 'book':
$query ="DROP TABLE IF EXISTS MYBOOKS";
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
echo "Books table dropped.<br>";
$query ="create table MYBOOKS
(bookid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
authorid INT NOT NULL,
title VARCHAR(60) NOT NULL,
isbn VARCHAR(20),
type VARCHAR(20) NOT NULL,
cover_type VARCHAR(10) NOT NULL,
pages INT,
copyright YEAR,
date_finished DATE,
has_been_read CHAR(01),
FOREIGN KEY (authorid) REFERENCES authors (authorid))";
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
echo "Books table created.";
break;
default:
$display_block = "Error - no option selected.";
} // End "switch".
}elseif (strtoupper($reply) == "N") {
echo "Books Table NOT dropped.";
}else{
// no-op.
}
?>
</form>
</body>
</html>
<?php