Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

forms, functions and PHP

  • 06-03-2005 02:31PM
    #1
    Registered Users, Registered Users 2 Posts: 722 ✭✭✭


    hi all,

    beginner at PHP, doing an installation script for PHP project. at the moment im just throwing information from one page to another, which means the installation script is four pages long

    1) enter mysql information
    2) check mysql info, start session, connect to db, enter user information
    3) check user info, create user account, enter site config information
    4) check config info and enter into database

    these are all functions in one page being called in the next

    what i wanted to do for my own mental health was (if possible)

    throw values from one function to another, allowing them to act like pages so i only have one install.php instead of install1.php, install2.php and so forth...



    here is some example code

    install.php


    function step1()
    {

    if (!isset($_POST)) $_POST = ' ';
    if (!isset($_POST)) $_POST = ' ';
    if (!isset($_POST)) $_POST = ' ';

    echo '<p>All fields are required.</p>';
    echo '<form action="testfunction4.php" method="post">';
    echo '<table border="0" cellspacing="4" cellpadding="0">';
    echo '<tr><td>mySQL Server:::: </td><td><input type="text" name="mysql_server" value="'.htmlspecialchars($_POST).'"></td></tr>';
    echo '<tr><td>mySQL Username:: </td><td><input type="text" name="mysql_user" value="'.htmlspecialchars($_POST).'"></td></tr>';
    echo '<tr><td>mySQL Password:: </td><td><input type="password" name="mysql_pass" value="'.htmlspecialchars($_POST).'"></td></tr>';
    echo '<tr><td colspan="2"><input type="submit" value="Submit" name="submit"></td></tr>';
    echo '</table>';
    echo '</form>';
    }



    error check on next page

    install2.php

    <?php


    require_once 'install.php';


    if (isset($_POST)) {

    $error_str = ''; // initialise $error_str as empty
    if (empty($_POST)) $error_str .= '<li>You did not spcify a server.</li>';
    if (empty($_POST)) $error_str .= '<li>You did not specify a username.</li>';
    if (empty($_POST)) $error_str .= '<li>You did not specify a password.</li>';

    if (strlen($_POST) < 2) $error_str .= '<li>Server name must be longer than 1 letter.</li>';
    if (strlen($_POST) < 4) $error_str .= '<li>Username must be longer than 3 letters.</li>';
    if (strlen($_POST) < 4) $error_str .= '<li>Password must be longer than 3 letters.</li>';

    if (!empty($error_str)) {

    echo '<p>There were errors in the information you entered, they are listed below:</p>';
    echo '<ul>'.$error_str.'</ul>';

    step1();
    exit; // die
    }

    } else {

    step1();
    }

    ?>

    followed by a connection to db and what not

    any suggestions???


Advertisement