Jump to content

[SOLVED] [PHP5] $_GET['var'] issue


boardy

Recommended Posts

I have been writing a simple blog for a friend of mine who doesn't want a load of extra stuff like WordPress or and of the other blogging systems have, just a nice simple does what it says on the tin blog.

 

I have everything working perfectly on the local XAMPP server on OS X, but for some reason, things stop working on the remote Win2k3 Web IIS6 server. XAMPP is running PHP 5.2.2 with register_globals:On and IIS6 is running PHP 5.2.3 with register_globals:Off. I don't really want to turn register_globals on for a live server but for some reason $_GET['id'] in the following code isn't working.

 

When I remove the offending code from the script it works fine, but then will not save anything to the database because of another $_GET['submit'].

 

I cannot figure this out, can anyone help please? My phpinfo(); is at http://www.bench-uk.co.uk/phpinfo.php

 

<?php
session_start();

    require("config.php");
    
    if(isset($_SESSION['USERNAME']) == FALSE) {
        header("Location:".$config_basedir);
    }
    
    $db = mysql_connect($dbhost, $dbuser, $dbpassword);
    mysql_select_db($dbdatabase);
    
    if(isset($_GET['id']) == TRUE) {
        if(is_numeric($id) == FALSE) {
            $error = 1;
        }
        
        if($error == 1) {
            header("Location:".$config_basedir);
        }
        else {
            $validentry = $_GET['id'];
        }
    }
    
    if($_POST['submit']) {
        $sql = "UPDATE entries SET cat_id = '".$_POST['cat']."', subject = '".$_POST['subject']."', body = '".$_POST['body']."' WHERE id = ".$validentry.";";
        mysql_query($sql);
        
        header("Location:".$caonfig_basedir."viewentry.php?id=".$validentry);
    }
    else {
        require("header.php");
        
        $fillsql = "SELECT * FROM entries WHERE id = ".$validentry.";";
        $fillres = mysql_query($fillsql);
        $fillrow = mysql_fetch_assoc($fillres);

?>

<h1>Update entry</h1>

<form action="<?php echo $_SERVER['SCRIPT_NAME']."?id=".$validentry; ?>" method="post">

<table>
    <tr>
        <td>Category</td>
        <td>
            <select name="cat">
                <?php
                    $catsql = "SELECT * FROM categories;";
                    $catres = mysql_query($catsql);
                    while($catrow = mysql_fetch_assoc($catres)) {
                        echo "<option value='".$catrow['id']."'";
                        
                        if($catrow['id'] == $fillrow['cat_id']) {
                            echo " selected";
                        }
                        
                        echo ">" .$catrow['cat']."</option>";
                    }
                ?>
            </select>
        </td>
    </tr>
    <tr>
        <td>Subject</td>
        <td><input type="text" name="subject" value="<?php echo $fillrow['subject']; ?>" /></td>
    </tr>
    <tr>
        <td>Body</td>
        <td><textarea name="body" rows="10" cols="50"><?php echo $fillrow['body']; ?></textarea></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" name="submit" value="Update entry!" /></td>
    </tr>
</table>
</form>

<?php

    }
    
require("footer.php");

?>
[/code

Cheers
Adam

Link to comment
Share on other sites

Found an issue in the the $_GET['var'] was trying to register a global in the $id variable. I altered that and it worked. I did change one GET to POST and it's sped things up which suprised me, thanks :D

 

Many hours googling and stuff before posting then I find the answer, typical.

 

Cheers

Boardy

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.