Jump to content

php mysql page frozen unless standalone


PNewCode

Recommended Posts

Here is my new project. I have everything working wonderfully. I was so happy with it.... Untill...

This is to be in an iframe. There's many reasons for that, none of the "why an iframe" are important really. It's just mainly to keep this part of a flow that is also in the same iframe.

The problem is, once the database gets to 10 (yes I posted similar to this before but this is stemming off of that)
Then it redirects. YAY! that works, unless its in an iframe.

I suspected it might be the header redirect so I changed it to just echo some random text, and that didn't matter. It seems to be the 10 entry functioning that I'm doing that puts it at a full stop in the flow of pages.

Any thoughts?

 

<?php

//// connection stuff here deleted for posting ////

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id FROM nametable";
$result = $conn->query($sql);


$resultt = mysqli_query($conn, "select COUNT(id) AS count FROM `nametable` ");


if(!$result) {
    die('Error: ' . mysqli_error($link));
} else {
    $num_rows = mysqli_fetch_assoc($resultt);
    
    // echo it


   
}

if ($num_rows['count'] == 10) {
    header("Location: free-off3.php");
}else{
 echo "<font color='#000000'>TADA</font> ";
}


?>

 

Link to comment
Share on other sites

@ginerjm Thats exactly it. You got it :) The point of it is to have a limit on certain entries then get redirected. The redirect lands on a page that clears out those entries AND resets a different database (4 of them actually) to defauly entries. It's a series of games like bingo and stuff.

The problem is, I want all of this in an iframe. It works great as a stand-alone page (not in an iframe, in case I'm using the wrong termonology). But having this page inside an iframe then it locks up and freezes when the 10th entry is entered.

I saw somewhere that header redirects don't work in iframes but I know thats not true because I have a different page that has one within an iframe. And I tested that theory by changing the redirect to some random text to echo out.

Link to comment
Share on other sites

Can you expand on what you mean by it freezes?  Does it sit there trying to load but never does?  Do you just get a blank page?

When hearing something works by itself but not in a frame, my first guess would be an X-Frame-options restriction.  You'd get an error in your browser's dev tools if that's the case.

Link to comment
Share on other sites

@ginerjm forms are on various different pages. There's a bunch of little games. Trivia, bingo, etc. When they enter their guess for whatever game they play, the entry goes into the database. 

This is just one of many. Some of these will redirect after 20 entries, some after 5, depends on the game. I just chose this one because it's a nice round number.

For the sake of answering your question though...

This is game "A". When the person opens GAME A, they get 10 trivia questions. One at a time these get entered because each question is on a timer.
So at the end of GAME A, 10 entries are in the database. And this is working just fine.

If they try to go back to GAME A, they can't because all 10 entries are full, and they have to start all over again (this is an entirely different set of pages and functions to start over. So it doesn't matter here)

And then after they reset, they can enter 10 more answers.

SO... this page sits in an iframe so that it is open and active on the side. Untill all ten entries are used, it just says "TADA" (I plan to change that to something more fun)
And then, when all 10 are done, they get redirected to free-off3.php, which sets the game to close.

But anyways... all is working. The problem isn't where or how everything is getting entered. The problem is WHEN it hits that 10th one then instead of redirecting, the page freezes like a deer in headlights. But only when it's in an iframe

Link to comment
Share on other sites

@kicken So when the user enters in the 10th entry, then tries to go back to do an 11th try, they can't because the redirect goes to a page that shuts off the game with some other code. This works fine outside an iframe on a page of it's own. But when inside an iframe then it just freezes up to a blank page (no errors, not logged errors that I can find either). It's like it's saying "ummmm..... what do you want me to do now" but only when in an iframe

Link to comment
Share on other sites

I still don't understand your overall process really.   If the count is less than 10, then this frame would just sit there displaying TADA, there's nothing in the posted code that would make it reload and check the count again.  If you're just reloading the entire main page when they submit an answer, then I fail to see the point of the iframe.   If the main page also checks if they have answered 10 questions and blocks access, then after they submit the 10th question the iframe would never get loaded in the first place so it can't actually do anything.

The whole thing sounds like a mess that needs to be re-designed to me.  Like, skip all the iframe junk and just have the page when loaded check if the user has answered all 10 questions and if so display a 'You've completed this already, do you want to start again?' type page and if they hit yes then do your DB reset.

Link to comment
Share on other sites

@kicken please forgive the crude drawing. I hoped that this will make it more clear because I am aware that I am not gifted in explaining my end goal

The biggest thing though, is that all would be right as rain and wonderful if I could just make the redirect work while it's in an iframe. I don't know what is making it stop. But if I have that page on the side in a different tab, while the game is being played, then everything works. I just can't get it to work while it's in the same page in an iframe.
PS... it's okay to laugh at my people drawing. I am too haha

image.thumb.png.eb10bda6386debb5a9c41a04c4fdb6df.png

Edited by PNewCode
Link to comment
Share on other sites

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.