Jump to content

Recommended Posts

ok, I have a file called test1.php,  I run a form that obtains some information from a user.

 

I set <form action="test1.php".........>  so that It doesn't redirect the user to a different

page yet. 

 

I then put the information i obtained from the form into a variable $test1var

 

I load a database and insert it into a table.

 

close mysql connection

 

Now I want it to redirect to test2.php after I insert the variable into the database.

I can't seem to figure out a way to get this to go to another php file after I close my database.

 

If i set the form action=test2.php , then it skips the whole mysql thing.

 

any ideas?

 

thanks.

I was under the impression that this only works if you do that right away, and not run any forms. I tried using that earlier and did not have any luck.

 

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

I was under the impression that this only works if you do that right away, and not run any forms. I tried using that earlier and did not have any luck.

You could echo this,

<script type="text/javascript">
<!--
window.location = "test2.php"
//-->
</script>

 

This is just a redirect in Javascript. It won't give u an error.

why not just put the form processing stuff on test2.php? you could also use a javascript or html redirect if you absolutely can't bring yourself to use a header()

Ya, you could also have your form post to test2.php and put this at the top

if ($_POST['form_name']){
// Do stuff //
}

why not just put the form processing stuff on test2.php? you could also use a javascript or html redirect if you absolutely can't bring yourself to use a header()

 

Because my test2.php is set to refresh every 15 minutes. So upon refresh I lose all my variables.  Thats why I want to save my variable into my database on test1.php, then on test2.php I can start out by loading the variable out of the database and use it, then after the page refreshes, it can load it out of the database and use it again.

 

I tried using javascript as well earlier this evening, and it would skip the mysql database code.... Im not sure why though.

you should probably echo the javascript refresh with PHP in that case, but without seeing the code I can;t be of any help

 

 

ok here is the code, sorry its a bit sloppy at the moment, haven't had time to clean it up

 

 

 

 

<form action="test1.php" method="post"><br>

<p>user input: <input type="text" name="input" /><input type="submit" /></p>

</form>

 

<?php $test1var = $_POST['input'];?>

 

//insert test1var into temporary database so I can refresh next page and pull it out

 

<?php

//server information

$host="localhost"; // Host name

$username="root"; // Mysql username

$password="*****"; // Mysql password

$db_name="db01"; // Database name

$tbl_name="temp"; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// Insert data into mysql

$sql="UPDATE $tbl_name SET tempvar ='$test1var'";

 

$result=mysql_query($sql);

 

// if successfully insert data into database, displays message "Successful".

if($result){

echo "</br></br>Successful";

}

else {

echo "ERROR";

}

 

// close connection

mysql_close();

 

?>

 

// AT THIS POINT I WOULD LIKE TO GO TO NEXT PHP FILE.

 

//the next file begins like this....

------------------------------------------------------

     

 

<meta http-equiv="refresh" content="300;url=test2.php">

 

<?php

 

load mysql

pull variable out of table

use it

close mysql and wait for refresh...

 

 

**So basically I need to have that variable in my database before I come to this second page, otherwise upon the first refresh, the variable gets cleaned out.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.