SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validating IDs in php using intval ()?

    Hi Everyone,

    I'm trying to figure out the correct syntax when trying to validate this line of code using intval ().

    PHP Code:
    $id ereg_replace("[^0-9]"""$_GET['id']); // filter everything but numbers for security
    if ($id == "") {
        echo 
    "Missing Data to Run";
        exit();

    Below is what I think is the correct syntax but I''m getting an error message and I'm not sure what I'm doing wrong.
    http://whatsmyowncarworth.com/more-p...file.php?id=10
    Error message "Missing Data to Run"

    (I think this is the correct way but my syntax is wrong. What's the correct syntax?)

    PHP Code:
    $id $_GET['id'] = 1;
    if (
    filter_var($idFILTER_VALIDATE_INT) !== false)
    {
      echo 
    "Missing Data to Run";
      exit();

    Any help would be appreciated! Thanks everyone!

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Did you try to echo $id and see what it contains?

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for the reply.

    I echo'ed out the $id and I got the 1.

    http://whatsmyowncarworth.com/more-p...file.php?id=10
    "Missing Data to Run1"

    >>>>>>>>>>>>

    then I deleted the ! infront of the == false and now I'm getting this error

    PHP Code:
    $id $_GET['id'] = 1;
    if (
    filter_var($idFILTER_VALIDATE_INT) == false)
    {
      echo 
    "Missing Data to Run"
      echo 
    $id;
      exit();

    Warning: Cannot modify header information - headers already sent by (output started at /home/scm22ri/public_html/whatsmyowncarworth.com/more-practice/member_profile.php:18) in whatsmyowncarworth.com/more-practice/login-from-page.php on line 30

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    I must admit. I'm lost here and not sure what to do next. Any pointers?

    PHP Syntax on member_profile.php page

    PHP Code:
    <?php
    session_start
    (); // Must start session first thing

    // See if they are a logged in member by checking Session data
    $toplinks "";
    if (isset(
    $_SESSION['id'])) {
        
    // Put stored session variables into local php variable
        
    $userid $_SESSION['id'];
        
    $username $_SESSION['username'];
        
    $toplinks '<a href="member_profile.php?id=' $userid '">' $username '</a> &bull; 
        <a href="member_account.php">Account</a> &bull; 
        <a href="logout.php">Log Out</a>'
    ;
    } else  {
        
    $toplinks '<a href="join_form.php">Register</a> &bull; <a href="login.php">Login</a>';
    }
    ?>

    <?php
    // Use the URL 'id' variable to set who we want to query info about
    /* $id = ereg_replace("[^0-9]", "", $_GET['id']); // filter everything but numbers for security
    if ($id == "") {
        echo "Missing Data to Run";
        exit();
    } */

    $id $_GET['id'] = 1;
    if (
    filter_var($idFILTER_VALIDATE_INT) == false)
    {
      echo 
    "Missing Data to Run"
      echo 
    $id;
      exit();


    //Connect to the database through our include 
    include_once "connect_to_mysql.php";
    // Query member data from the database and ready it for display
    $sql mysql_query("SELECT * FROM members WHERE id='$id' LIMIT 1");
    $count mysql_num_rows($sql);
    if (
    $count 1) {
        echo 
    "There is no user with that id here.";
        exit();    
    }
    while(
    $row mysql_fetch_array($sql)){
    $username $row["username"];
    $country $row["country"];
    $state $row["state"];
    $city $row["city"];
    $accounttype $row["accounttype"];
    $bio $row["bio"];
    // Convert the sign up date to be more readable by humans
    $signupdate strftime("%b %d, %Y"strtotime($row['signupdate']));
    }
    ?>

    <?php include('login-from-page.php'); ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •