Jump to content

PHP Variables, Frames


alka

Recommended Posts

Hi,

 

I'm trying to make a simple website approving tool. The websites should be shown within a html frame. I know frames are controversial, but in this case there is no alternative and its a perfect use of frames... So basicallly there is a top frame and a bottom where the website is shown, the top only holds some detaisl about the site/ads with some action buttons. I know my code is faulty but I have no clue as to where/how to continue. Maybe I'm requiring javascript i don't know any tips are welcome and appreciated. So here is the code:

 

Main file:

<?php
include '../libs/db.php';
$dbconnect =   mysql_connect("$dbhost", "$dbuser", "$dbpwd");
                           mysql_select_db("$dbname");

if ($_GET['action'] == "approve") {
$id = $_GET['id'];
@mysql_query("UPDATE usersites SET state = Rotating WHERE id = '$id'");
}
$query = mysql_query("SELECT id,usrid,url FROM usersites WHERE state = 'unverified' LIMIT 1");
	$res = mysql_fetch_array($query);
	$id = $res['id'];
	$usrid = $res['usrid'];
	$url = $res['url'];

$query2 = mysql_query("SELECT username,credits FROM users WHERE id = '$usrid'");
	$res2 = mysql_fetch_array($query2);
	$username = $res2['username'];
	$credits = $res2['credits'];
?>
<frameset rows="100,100%">
  		<frame src="<?php echo 'top.php?username=' . $username . '&url=' . $url . '&id=' . $id ?>" />
	<frame src="<?php echo $url; ?>" />
</frameset>

<body>
</body>
</html>

 

Firstframe: "top.php"

<?php
$id = $_GET['id'];
echo "Username:" . $_GET['username'];
echo "<br>";
echo "URL: " . $_GET['url'];
echo "<br>";
echo "ID: " . $_GET['id'];
echo "<FORM METHOD=\"LINK\" ACTION=\"SiteManager.php?action=approve&id=$id\">"
?>
<INPUT TYPE="submit" VALUE="Approve">
</FORM>

 

The part that isnt working as intended for now is when I hit the approve button.

I have no idea how to re-load the code/frame properly. It does simply not approve the

page/ad. In addition it opens up a new frame so the ad is shown twice (one in each frame)

 

Any tips in where to go from here would be appreciated :).

Link to comment
Share on other sites

you need to encase Rotating with ' in your SQL update query

@mysql_query("UPDATE usersites SET state = 'Rotating' WHERE id = '$id'");

 

As for the duplicating of top.php, are you reloading the frameset into the bottom frame? or reloading the entire page/frameset...?

i.e. index.php has frameset with top.php & page.php, you need to reload the entire index.php page, not into a frame.

Link to comment
Share on other sites

Hi,

 

Thanks for your replay. I fixed the mysql query by encasing as you described. Anyway.

I reloaded it and expected it to atleast approve the ad/page when I hit the approve

button, but unfortunately it did not.

 

Regarding page re-load. I simply added a form/button as follows:

 

<?php echo "<FORM METHOD=\"LINK\" ACTION=\"SiteManager.php?action=approve&id=$id\">" ?>
<INPUT TYPE="submit" VALUE="Approve">

 

This form is in the top.php. This file is the first frame in the frameset.

 

So I basically have two problems it seems. First the Approve button does not change the status in mysql

then second I'm obviously reloading the page improperly by calling SiteManager.php (the main php/html file

described/pasted in the first post).

 

Any tips appreciated :). Maybe I'm doing this all wrong?..  :confused:

Link to comment
Share on other sites

1) [This is not causing your problem] You don't need to put double-quotes around variable names

$dbconnect =   mysql_connect($dbhost, $dbuser, $dbpwd);
                           mysql_select_db($dbname);

 

2) As joel24 said, you need quotes around the literal "Rotating" (unless it is a column name)

3) Never use the @-sign to hide errors. It will leave you thinking everything is fine.

if (! mysql_query("UPDATE usersites SET state = 'Rotating' WHERE id = '$id'")) {
  echo "UPDATE failed, fix it"; 
  // Or some other code to be done when we can't process the request
}

 

4) I have never heard of a FORM METHOD of LINK. Shouldn't that be GET?

5) Try adding a target to the FORM tag - this should cause it to load over the entire document instead of loading in the current frame

echo "<FORM METHOD=\"GET\" ACTION=\"SiteManager.php?action=approve&id=$id\" target='_top'>"

 

Link to comment
Share on other sites

Hi again,

 

Thanks for your tips :).. dont know why I ad  double-quotes there, I've now removed them.

 

Your suggestion to add target = '_top' to the url worked nicely as well it seems. So that part is

ok for now. I also replaced FORM METHOD LINK with GET, that didnt seem to change anything

and I'm not sure where I got LINK from in the first place. Been trying to solve this with the help

of google etc. So prolly got it from some tips on a site. They seem to do the same thing?

 

Finally... When I do hit Approve. It does not execute:

 

if ($_GET['action'] == "approve") {
$id = $_GET['id'];
@mysql_query("UPDATE usersites SET state = Rotating WHERE id = '$id'");
}

 

I also tried replacing the mysql query with your suggested variant below but

that did not change anything or show an error:

 

if (! mysql_query("UPDATE usersites SET state = 'Rotating' WHERE id = '$id'")) {
  echo "Failed, check query"; 
}

 

I suspect the IF statement is simply failing.... Any tips? :)

 

Again really appreciate the feedback,

help and support so far on this forum.

Link to comment
Share on other sites

for now put in an or die(); condition to print any mysql errors.

and also for the development site, put in print_r($_GET) and print_r($_POST) and ensure all the correct variables are being sent

if ($_GET['action'] == "approve") {

$id = $_GET['id'];
$sql = mysql_query("UPDATE usersites SET state = Rotating WHERE id = '$id'");
if ($sql) { 
echo 'approved'; 
} else { 
echo 'failed...<br/>'.mysql_error(); 
}

}

echo '<p><b>$_GET:</b><br/>';
print_r($_GET);
echo '</p>';
echo '<p><b>$_POST:</b><br/>';
print_r($_POST);
echo '</p>';

Link to comment
Share on other sites

Follow joel24's advice, let's see what the script is receiving.

 

Also, do you have any other fields defined inside that FORM tag? Like maybe one called "action"? I don't see any in the code you posted, but if you only posted part of the form, check it and make sure you are not using form field names that are the same as the variables in your query-string in the ACTION phrase. If you do need both, you can POST the form to get the fields in $_POST and still get the query-string in $_GET (of course $_REQUEST will be hosed).

 

Edit: I do NOT recommend this except in very special circumstances.

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.