On Thu, 28 Jun 2001 10:36, Stephen Reynolds wrote:
> I only want this INSERT INTO php sql script to run when the input
> button is pressed. How do I stop the script running when the page is
> loaded?
>
> +++ Begin HTML Page +++
>
> <?php
> //create database connection
> include("d:\bin\Apache\include\dbcon.inc");
> ?>
> <html>
> <head>
> <title>Test Script</title>
> </head>
> <body>
> <form name="update_names" method="post" action="<?php $PHP_SELF ?>">
> <p>First Name<br>
> <input type="text" name="first_name" maxlength="25" size="25"></p>
>
> <p>Last Name<br>
> <input type="text" name="last_name" maxlength="25" size="25"></p>
>
> <p><input type="submit" name="Submit" value="Save"></p>
> </form>
>
> <?php
> $sql = "INSERT INTO address (first_name, last_name) VALUES
> ('$first_name', '$last_name')";
> $result = mysql_query($sql,$dbcon);
> print ("Your new record has been entered.");
> ?>
> </body>
> </html>
>
> +++ End HTML Page +++
>
> Regards, Steve
You only want the INSERT to run when the INPUT button has been clicked?
Test to see if the variable $Submit is empty - if not the button has been
clicked and you can do the insert (after you validate the incoming data,
of course). You might want to only show the input fields if the action is
not an insert.
--
David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA
(C) 1992 Wild Bill's Machine Gun Shop and House of Wax.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php