It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
...the conditions of an if statement are fulfilled?
I have some code to add data to a database if certain conditions are met, after the data is added I want the page to redirect to another page? How can I do this?
Use if-else condition. You can use header() of PHP .
if(/* Your conditions */){
// redirect if fulfilled
header("Location:nxtpage.php");
}else{
//some another operation you want
}
You shoul use header php function
<?php
//some conditions
header("Location: http://www.example.com/");
?>
try this code
$query ="insert into test values (1,'test')";
if(mysql_query($query) == true)
{
header('location:index.php');
exit();
}
else
{
echo " insert failed";
}
Try PHP Header:
header('Location: http://www.example.com/');
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a page count to limit the number of times a logged out user can view profiles. If a user is logged out they are redirected to a sign-up page, this is right and should be what's happening but i'm getting the same thing happen when the user is logged in, how can i add an else statement or if statement to say only redirect to sign up page or only limit profile hits if not logged in?
Thanks
<?
!session_id() ? session_start() : null;
verify_profile_visit_limit();
function verify_profile_visit_limit(){
$free_profiles = array(99999,99998,99997,99996,99995,99994,99993);
if(in_array($_GET["id"], $free_profiles)) return;
if(! isset($_SESSION["page_access_count"])){
$_SESSION["page_access_count"] = 1;
}
$_SESSION["page_access_count"]++;
if($_SESSION["page_access_count"] > 5){
header("Location: limit.php");
exit();
}
}
?>
Just add an OR condition so you return if the user is logged in:
if(in_array($_GET["id"], $free_profiles) || isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']) return;
With that your function will return before running the limit check. Assuming you store a boolean (true/false) in $_SESSION['loggedIn'].
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I made this code where I define an array, fliepath, in which I store the locations of some files.
include 'last_file.php'; // Include the function last_file
$last_file = last_file(); // assign to the function a variable and call the function last_file
// Connect to the database
include('connect_thesis.php');
// Defining an array, which has the three paths to the three different gps receivers
$file_path[0] = "/Applications/MAMP/htdocs/php_test/check/".$last_file[0];
//echo $file_path[0]; echo "<br>";
$file_path[1] = "/Applications/MAMP/htdocs/php_test/check2/".$last_file[1];
//echo $file_path[1]; echo "<br>";
$file_path[2] = "/Applications/MAMP/htdocs/php_test/check3/".$last_file[2];
//echo $file_path[2]; echo "<br>";
Then I made a function called insert() which I want to take as input the $file_path[0]:
function insert($file_path){
$fh = fopen($file_path,'r') or die ("Could not open:".mysql_error()).......;
I call the function from the main script as:
insert($file_path[0]);
I am new in programming and I am sure somewhere I am missing something basic!
The problem is that the function doesn't run!!!
Can you help me?
Thanx
D.
I THINK I DONT PASS CORRECTLY THE VALUE TO THE FUNCTION. CAUSE I GET NOTHING AS AN ERROR!
A few points to note:
You are calling insert using only the index 0, consider using a foreach and call the function on each items in your array.
insert() -> we are missing part of the implementation, but if the file exists, you should not get an error. Keep in mind that you need to close files that you open.
or die -> it looks like you copy pasted code from elsewhere... mysql_error() will not help you much as you're dealing with files at the moment. Consider changing it to
$fh = fopen($file_path,'r') or die ("Could not open:".$file_path)
You should probably handle graciously the error instead of using "die"
I think you need this:
function insert($file_path) {
foreach ($file_path as $file) {
//Your code here
}
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
My pseudo code is as follows:
if($_GET['action'] == 'list'){
do function getFileList($dir)
else
do nothing
exit;
}
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
}
Your psuedo code is almost there.
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
/* ... */
}
if($_GET['action'] == 'list') {
getFileList($dir);
}
Are you asking how to send a variable via GET to a PHP file from within the same PHP file? You can create a form that submits to itself: http://www.tellingmachine.com/post/Simple-self-submitting-PHP-forms.aspx.
If you are looking to do something else, please provide additional details.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I found a great contact form over here. How to show a "Successfully sent" message right under the contact from instead of using a redirect to an other page?
$formproc->SetFormRandomKey('9nLzAt2cQM2Zysm');
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$formproc->RedirectToURL("thank-you.php");
}
}
Change the form process code to this.
$formproc->SetFormRandomKey('9nLzAt2cQM2Zysm');
$successful = false;
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$successful = true;
}
}
Where you want the message to show.
if($successful){
echo "Successfully sent.";
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a php page from where my users log-in to the application. It is working fine.
Yesterday, all of a sudden the users were able to login but were forced out and redirected to the login page again.
My database has logged in the user's login timings and this problem was automatically solved after about 2 hours.
Why will like this happen?
In the following code it will check for the session value and if it is not found then redirect to the error page.
Yesterday, it was redirecting to error page even if the session value was set.
<?php
if($_SESSION['ucd']<>"" && $_SESSION['sid']<>"" && $_SESSION['sid']<>0)
{
$query="select count(*) from active_sessions where user_cd='".$_SESSION['ucd']."'
and session_no='".$_SESSION['sid']."' and START_TM like DATE_FORMAT(now(),'%Y-%m-%d%')";
//echo $query;
$cnt=$dbop->select($query);
if($cnt[0] == '0')
{
$sender = "sender=".urlencode($_SERVER['PHP_SELF']);
session_unset();
header("Location:../login/error.html?$sender");
die;
}
else{
$query = "update active_sessions set LAST_ACTIVITY = NOW() WHERE SESSION_NO = ".$_SESSION['sid'];
mysql_query($query);
?>
<?php
}
}
else
{
$sender = "sender=".urlencode($_SERVER['PHP_SELF']);
session_unset();
header("Location:../login/error.html?$sender");
die;
}
?>
I don't see session_start() anywhere in your code.