+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: PHP help please

  1. #1
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    PHP help please

    I have an error on line 90 in an admin panel of mine and was wondering if someone could be of any help:::
    PHP Code:
    <?
        $bid 
    $_GET['id'];
        
    $sql "SELECT * FROM blocks WHERE bid='$bid'";
        
    $getinfo mysql_query($sql)
                    or die(
    mysql_error());//get the info from the database
        
    if (mysql_num_rows($getinfo == "0")) {//no results
            
    exit("sorry, we couldn't find a block with the id of $bid");
        }
    ?>
    that is line 86-92
    Last edited by Shadow121; 08-30-2006 at 06:59 PM.

  2. #2
    Tomballa is offline x10Hosting Member Tomballa is an unknown quantity at this point
    Join Date
    Jun 2006
    Posts
    15

    Re: PHP help please

    Try this:

    PHP Code:
    <?
        $bid 
    $_GET['id'];
        
    $sql "SELECT * FROM blocks WHERE bid=".$bid;
        
    $getinfo mysql_query($sql)
                    or die(
    mysql_error());//get the info from the database
        
    if (mysql_num_rows($getinfo == "0")) {//no results
            
    exit("sorry, we couldn't find a block with the id of $bid");
        }
    ?>

  3. #3
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: PHP help please

    If that doesnt work try this

    PHP Code:
     <?
        $bid 
    $_GET['id'];
        
    $sql "SELECT * FROM blocks WHERE bid=".$bid;
        
    $getinfo mysql_query($sql)
                    or die(
    mysql_error());//get the info from the database
        
    if (mysql_num_rows($getinfo == "0")) {//no results
            
    exit("sorry, we couldn't find a block with the id of " .$bid);
        }
    ?>
    Thanks,
    Brandon Long

  4. #4
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: PHP help please

    if you still have the error? what is the error you are getting

    I would love to change the world, but they won't give me the source code

  5. #5
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    Re: PHP help please

    Code:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\server\www\adsmin.php on line 88
    PHP Code:
    <?
        $bid 
    $_GET['id'];
        
    $sql "SELECT * FROM blocks WHERE bid=".$bid;
        
    $getinfo mysql_query($sql)
                    or die(
    mysql_error());//get the info from the database
        
    if (mysql_num_rows($getinfo == "0")) {//no results
            
    exit("sorry, we couldn't find a block with the id of $bid");
        }
    ?>
    thats the coding i got O.o;
    Last edited by Shadow121; 08-31-2006 at 04:02 PM.

  6. #6
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: PHP help please

    I think oi found the prob

    PHP Code:
    <?
        $_GET
    ['id'] = $bid;
        
    $sql "SELECT * FROM blocks WHERE bid=".$bid;
        
    $getinfo mysql_query($sql)
                    or die(
    mysql_error());//get the info from the database
        
    if (mysql_num_rows($getinfo == "0")) {//no results
            
    exit("sorry, we couldn't find a block with the id of $bid");
        }
    ?>


    I think the $_GET and the $bid were backwards

    Thanks,
    Brandon Long

  7. #7
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    Re: PHP help please

    Error
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    My Full Code
    PHP Code:
    <?php
      ob_start
    ();
      include 
    "config.php";

    switch (
    $_GET['frame']){
                case 
    'addblock':
                if (!
    $_POST['addblock']) {
            echo (
    "You can add new blocks here, HTML <strong>IS</strong> allowed");
            echo (
    "<form method=post>\n
                    Block Title: <input type=text name=title maxlength=50><br />\n
                    Content:<br /> <textarea class=\"inputarea\" rows=20 cols=70 name=content></textarea><br />\n
                    Hidden: <select name=hidden>\n 
                    <option>No</option>\n 
                    <option>Yes</option>
                    </select>\n <br /> 
                    <input type=submit name=addblock value=\"Add Block\">\n 
                    </form>"
    );
                    
    //if the form hasn't been submitted, present it
        
    }else{
        
    //we put the values from the form into variables
        
    $title strip_tags($_POST['title']);
        
    $block nl2br($_POST['content']);
        
    $hidden $_POST['hidden'];
        
    //becaues this is a new block, we make it the last one to be displayed, order
        //will be changed in the block manager, cause I'm too lazy to write something to
        //find and update orders whenever blocks are added
        
    $osql "SELECT * FROM blocks";
        
    $order mysql_query($osql)
                    or die(
    mysql_error());
                    
    //we see how many blocks there are and set the order to 1 above
                    
        
    $numblocks mysql_num_rows($order);
        
        
    $order_value = ($numblocks 1) * 10;
        
    //add 1 to the number of rows, making the block displayed last
        
    mysql_query("INSERT INTO blocks (name,content,hidden,position) VALUES('$title','$block','$hidden','$order_value')")
            or die(
    mysql_error());
        echo 
    "Block added successfully, If you would like to reorder your blocks, please visted the block manager";
        }
        break;
        case 
    'blockman':
        echo 
    "Welcome to the block manager<br />\n";
        
    $sql "SELECT * FROM blocks ORDER BY position";
        
    $blocks mysql_query($sql);
        echo 
    "<form method=post action=?frame=updateblocks>";
        
    $countrows mysql_num_rows($blocks);
        
    $i "1";
        while(
    $row mysql_fetch_array($blocks)){
        
    $title $row['name'];
        
    $bid $row['bid'];
        
    $position $row['position'];
        
        echo (
    "       <a href=\"?frame=editblock&id=$bid\">$title</a>     \n
        <a href=\"?frame=delblock&id=
    $bid\">Delete?</a><br /><br />\n");    
        
    $i++;
        } 
    // while
        
    echo "<center><input type=submit name=update value=Reorder></form></center>";
        break;
        
        case 
    'delblock':
        if (!
    $_POST['confirm']) {//check to see if the form is submitted
            
    $nid $_GET['id'];
            echo (
    "Are you sure you want to delete this block?\n 
            Block deletion is permenent and cannot be undone, there will be no other warning message\n
            <br /><form method=post action=\"?frame=delblock&id=
    $bid\">\n
            <div align=center><input type=submit name=confirm value=yes>\n
                  \n
            <input type=submit name=confirm value=no></div></form>"
    );
        }elseif(
    $_POST['confirm'] == "no"){
        echo 
    "This block will no longer be deleted, please continue your browsing";
        }elseif(
    $_POST['confirm'] == "yes"){
        
    $bid $_GET['id'];
        
    $sql "DELETE FROM site.blocks where bid='$bid'";
        
    mysql_query($sql)
            or die(
    mysql_error());
            
            echo 
    "block deleted successfully";
        }
        break;
        case 
    'editblock':
        if (!
    $_POST['update']) {//the form hasn't been submitted
            
            
        
    $_GET['id'] = $bid;
        
    $sql "SELECT * FROM blocks WHERE bid=".$bid;
        
    $getinfo mysql_query($sql)
                    or die(
    mysql_error());//get the info from the database
        
    if (mysql_num_rows($getinfo == "0")) {//no results
            
    exit("sorry, we couldn't find a block with the id of $bid");
        }
        
        while(
    $row mysql_fetch_array($getinfo)){
        
        
    $name $row['name'];
        
    $data $row['content'];
        
    $hidden $row['hidden'];
        
    $order $row['position'];
        
    //put our variables into smaller variables without quotes to avoid encapped white space error
        
        
    echo ("<form method=post>\n 
                Block Title: <input type=text name=name value=
    $name><br /> 
                Block data:<br />\n 
                <textarea rows=20 cols=65 name=data>
    $data</textarea><br />\n 
                Hidden: <select name=hidden>\n 
                    <option>No</option>\n 
                    <option>Yes</option>
                    </select>\n <br /> 
                Position: <input type=text name=position  maxlength=10 size=2 value=
    $order><br />\n 
                <input type=submit name=update value=\"Update Block\">\n 
                </form>"
    );
                }
        }else{
        
    $name $_POST['name'];
        
    $data $_POST['data'];
        
    $hidden $_POST['hidden'];
        
    $position $_POST['position'];
        
    $bid $_GET['id'];
        
    $update mysql_query("Update blocks set name = '$name', content = '$data', hidden = '$hidden', position = '$position' WHERE bid = '$bid'")
            or die(
    mysql_error());
            echo 
    "Block updated successfully";
            }
        break;
        
                 default:
                echo 
    "Welcome to the adminCP please select an option to the left";
                     ;
             } 
    // switch

      
    ?>

  8. #8
    jaint is offline x10 Sophmore jaint is an unknown quantity at this point
    Join Date
    Jul 2006
    Posts
    174

    Re: PHP help please

    make it this instead:
    $sql = "SELECT * FROM blocks WHERE bid=$bid";
    You don't need to add the . because in php anything withing double quotations gets converted, when executed it will fill in variables with the value itself, so

    $sql="SELECT * FROM blocks WHERE bid=5"

    to optimize your code replace "s with 's, it speeds up execution time.

  9. #9
    Simplez is offline x10Hosting Member Simplez is an unknown quantity at this point
    Join Date
    Aug 2006
    Posts
    1

    Re: PHP help please

    Im sorry.
    I dont kow php very well. otherwise i would be glad to help.

  10. #10
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    Re: PHP help please

    that works but when i go to edit my block i get: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  4. [PHP] PHP For Starters
    By Complex in forum Tutorials
    Replies: 24
    Last Post: 06-14-2008, 11:40 PM
  5. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers