Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

forms, functions and PHP

Options
  • 06-03-2005 2:31pm
    #1
    Registered Users Posts: 721 ✭✭✭


    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