PHP help please

Shadow121

Member
Messages
901
Reaction score
0
Points
16
I have an error on line 90 in an admin panel of mine and was wondering if someone could be of any help:::
PHP:
<?
    $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:

Tomballa

New Member
Messages
30
Reaction score
0
Points
0
Try this:

PHP:
<?
    $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");
    }
?>
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
If that doesnt work try this

PHP:
 <?
    $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);
    }
?>
 

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
if you still have the error? what is the error you are getting
 

Shadow121

Member
Messages
901
Reaction score
0
Points
16
Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\server\www\adsmin.php on line 88
PHP:
<?
    $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:

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
I think oi found the prob

PHP:
<?
    $_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

 

Shadow121

Member
Messages
901
Reaction score
0
Points
16
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:
<?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

  
?>
 

jaint

Member
Messages
174
Reaction score
0
Points
16
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.
 

Simplez

New Member
Messages
1
Reaction score
0
Points
0
Im sorry.
I dont kow php very well. otherwise i would be glad to help.
 

Shadow121

Member
Messages
901
Reaction score
0
Points
16
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
 

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
its where the mysql is erroring. if the query was spread over many lines it would be like blah at like 5 if was spread over 5 lines and the error was on the 5th line.

Give me a few and i will look into it and edit this post


ok i think the code is having a problem around here

PHP:
<?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
    $order = mysql_query("SELECT * FROM blocks") 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";
    $blocks = mysql_query("SELECT * FROM `blocks` ORDER BY position") or die(mysql_error());
    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 = mysql_query("DELETE FROM site.blocks where `bid` = '$bid'") or die(mysql_error());
          
        echo "block deleted successfully";
    }
    break;
    case 'editblock':
    if (!$_POST['update']) {//the form hasn't been submitted
        
        
    $_GET['id'] = $bid;
    $getinfo = mysql_query("SELECT * FROM `blocks` WHERE `bid` = '$bid'") or die(mysql_error());
        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

  
?>
there you go, if there are still errors, please post
 
Last edited:
Top