help - need to add page redirect or echo statement

Discussion in 'PHP' started by saturn100, Nov 23, 2011.

  1. #1
    I have this script below that allows me to ad data to a database via a HTML form

    It works fine (you can use it if you want)

    But when it works the page just loads as white

    I need it to either load to a thankyou style html webpage or send out an echo statement confirming it has worked

    Thanks

    The script is

    <?php
    
    define ('DB_NAME' , 'demo');
    
    define ('DB_USER' , 'root');
    
    define ('DB_PASSWORD' , '');
    
    define ('DB_HOST' , 'localhost');
    
    $link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
    
    if (!$link) {
        die('could not connect:  ' . mysql_error ());
    	
    
    	}
    	
    	$db_selected =mysql_select_db (DB_NAME, $link);
    	
    	if (!$db_selected) {
    	die('can\'t use ' . DB_NAME . ':' . mysql_error ());
    	}
    
    $value = $_POST['input1'];
    
    $value2 = $_POST['input2'];
    
    
    
    
    
    
     
    $sql = "INSERT INTO demo1 (input1, input2)  VALUES ('$value','$value2')";
    
    
    if (!mysql_query($sql)) {
        die('ERROR: ' . mysql_error());
    }
    
    ?>
    PHP:
    anyone know the code and where to put it
     
    saturn100, Nov 23, 2011 IP
  2. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #2
    Just write it below

    <?php
    
    define ('DB_NAME' , 'demo');
    
    define ('DB_USER' , 'root');
    
    define ('DB_PASSWORD' , '');
    
    define ('DB_HOST' , 'localhost');
    
    $link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
    
    if (!$link) {
        die('could not connect:  ' . mysql_error ());
       
    
        }
       
        $db_selected =mysql_select_db (DB_NAME, $link);
       
        if (!$db_selected) {
        die('can\'t use ' . DB_NAME . ':' . mysql_error ());
        }
    
    $value = $_POST['input1'];
    
    $value2 = $_POST['input2'];
    
    
    
    
    
    
     
    $sql = "INSERT INTO demo1 (input1, input2)  VALUES ('$value','$value2')";
    
    
    if (!mysql_query($sql)) {
        die('ERROR: ' . mysql_error());
    }
    
    ?>
    <p>This is my page in html</p>
    <p>Thank you for using my form, it has been submitted</p>
    PHP:
     
    Anveto, Nov 23, 2011 IP
  3. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #3
    if (!mysql_query($sql))
    {
    die('ERROR: ' . mysql_error());
    }
    else
    {
    header("Location: thanks.php");
    }
    ?>
     
    kmap, Nov 23, 2011 IP
  4. iliveforyou

    iliveforyou Active Member

    Messages:
    207
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    iliveforyou, Nov 25, 2011 IP