PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Jul 06, 2020 1:02 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Feb 18, 2016 7:50 pm 
Offline
Forum Newbie

Joined: Thu Feb 18, 2016 7:42 pm
Posts: 3
Want to redirect back to the form page after successful entry. The redirect method does not work all the time (part is commented out) I want echo below the form Successful entry.

//These are the variables for our redirect.
$redirect=$_POST['redirect_to'];
$referred=$_SERVER['HTTP_REFERER'];
$query=parse_url($referred,PHP_URL_QUERY);
$referred=str_replace(array('?',$query), '', $referred); echo "referred", $referred;

full code
Syntax: [ Download ] [ Hide ]

<?php
require_once ('core/connect.php');
$mysqli = mysqli_connect($dbhost, $dbuser, $dbpass) or die($dberror1);
$select_db = msqli_select_db($msqli, 'dustysvi_oregon2') or die ($dberror2);

$fields = mysql_query("SHOW columns FROM dustysvi_oregon2");echo $fields;
while($row = mysql_fetch_array($fields))
{
    echo '<tr>';
    echo '<td>';
    echo $row["Field"];
    echo '</td>';
    echo '<td>';
    echo "<input type='text' class='' name='tags' id='tags' value=''>";
    echo '</td>';
    echo '</tr>';
}
if (isset($_SERVER['HTTP_REFERER'])) { // check there was a referrer

        $uri = parse_url($_SERVER['HTTP_REFERER']); // use the parse_url() function to create an array containing information about the domain
        Echo $uri['host']; // echo the host

}
$domain = $_SERVER['HTTP_HOST'];
$uri = parse_url($_SERVER['HTTP_REFERER']);
$r_domain = $uri['host'];

echo "uri", $uri, $domain;
 /*Checks to see if the specified field exists and if it doesn't, creates it.;*/
function f_fieldExists($table, $column, $column_attr = "VARCHAR( 30 ) NULL" , $mysqli) {
        $exists = false;
          $columns = mysqli_query($mysqli,"show columns from $table");  
        while($row = mysql_fetch_assoc($columns))
{
    foreach($row as $key => $value){
        echo "$key=$value";
    }
                if($c['Field'] == $column){
                        $exists = true;
                        break;
                }
        }
        if(!$exists){
                mysqli_query($mysqli, "ALTER TABLE `$table` ADD `$column`  $column_attr ");
        }
}
       
       

//if ( $domain == $r_domain ) {
       

       
       
    //These are the main variables we'll use to process the form.
    $table=$_POST['county'];  print_r($_POST); echo "<br \n>";
       
        unset($_POST['submit']);
       
unset($_POST['county']);

print_r($_POST);
    $keys=implode(", ",(array_keys($_POST))); echo "<br \n>";  echo "keys =", $keys;
    $values=implode("', '",(array_values($_POST)));  echo "<br \n>";  echo "values =", $values;

 /*Check to see if the fields specified in the form exist and if they don't, create them.*/
    foreach ($_POST as $key => $value) {
        $column = mysqli_real_escape_string($mysqli,$key);
        $alter = f_fieldExists($table, $column, $column_attr = "VARCHAR( 30 ) NULL", $mysqli );

        if (!$alter) {
                        echo "<br \n>";
                       
            echo 'Unable to add column: ' . $column;
        }
    }

 //These are the variables for our redirect.
    $redirect=$_POST['redirect_to'];
    $referred=$_SERVER['HTTP_REFERER'];
    $query=parse_url($referred,PHP_URL_QUERY);
    $referred=str_replace(array('?',$query), '', $referred); echo "referred", $referred;


       
    /*Insert out values into the database.*/
    $sql="INSERT INTO $table ($keys) VALUES ('$values')";echo "<br \n>"; Echo $sql;

    if (!mysqli_query($mysqli,$sql)) {
        die('Error: ' . mysqli_error($mysqli));
    }


$mysqli->close();




 /*Redirect the user after a successful form submission*/
   
        header("Location: $referred?msg=1");
   
//}
//else {
    die('You are not allowed to submit data to this form');
//}

?>


Top
 Profile  
 
PostPosted: Fri Feb 19, 2016 2:23 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
I suspect that your redirect does not work because there are echo() statements sending output before your header() statement. You cannot have any output before calling header().

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group