NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page question about setting a variable in php

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 10-23-2006, 06:10 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
TwiztedFake's Avatar
Join Date: Apr 2004
Location: IL
Posts: 348
TwiztedFake is on a distinguished road
 



question about setting a variable in php


I'm working on a comments script for my site. The script uses one table to store all the data for every comment. In that table I have a column that is named cid which tells the script what it belongs too. So here is my problem.
????: NamePros.com http://www.namepros.com/programming/250239-question-about-setting-a-variable-php.html

I start by getting the id of what the comment is left for

$id = $_GET['id']

then I want it to add another letter to it that will be used for pulling the data out when a page is loaded

$cid = b + $id

the b is a letter i'm using for a specific area of the site for example right now the b means its a blog comment. I am also going to have a p$id which will be a photo comment id. So how do I write the variable to add the corresponding letter to it based on what the form is telling it.
__________________
-TwiztedFake-
RTard Tutorials
Digital-Dummy to Total-Techie
TwiztedFake is offline  
Old 10-23-2006, 07:05 PM   #2 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




PHP Code:
$cib 'b'.$id
Barrucadu is offline  
Old 10-23-2006, 07:49 PM THREAD STARTER               #3 (permalink)
NamePros Regular
 
TwiztedFake's Avatar
Join Date: Apr 2004
Location: IL
Posts: 348
TwiztedFake is on a distinguished road
 



Got the insert $cid problem fixed but now having an issue with mysql I've built a function for the adminCP to delete blogs and their comments. The function is giving the following error when it is ran.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/t/w/i/twiztedfake/html/admincp.php on line 441

What is weird is that the function is doing everything it is suppose to be doing. Which is delete the blog from the blogs table and delete all comments from the comments table that goes with the blog. I checked the database and they have all been deleted!

The function:
PHP Code:
function delete()
    {
        
$ID $_GET['id'];
        
$table $_GET['table'];
        
$table 'ct_'.$table;
    
        if (
$table == 'ct_blog')
            {
                
$type "b";
                
$cid $type.$ID;
                
$sql "SELECT * FROM ct_comments WHERE cid = '$cid'  ORDER BY ID DESC";
                
$result mysql_query($sql);
                
$num_rows mysql_num_rows($result);
                while (
$row mysql_fetch_array($result)) // This is line 441 in my file
                    

                        
$sql "DELETE FROM ct_comments WHERE cid = '$cid'";
                        
$result mysql_query($sql);
                            if (!
$result)
                                {
                                    
stop('Failed to delete comments for entry from database. Error returned is '.mysql_error());
????: NamePros.com http://www.namepros.com/showthread.php?t=250239
????: NamePros.com http://www.namepros.com/showthread.php?t=250239
                                }
                        echo 
'Comments sucessfully deleted.';
                    }
            }
            
        
$sql "DELETE FROM $table WHERE ID = '$ID' LIMIT 1";
        
$result mysql_query($sql);
        if (!
$result)
            {
                
stop('Failed to delete entry from Database. Error returned is '.mysql_error());
            }
        echo 
'Entry sucessfully deleted.';
    } 
__________________
-TwiztedFake-
RTard Tutorials
Digital-Dummy to Total-Techie
TwiztedFake is offline  
Old 10-23-2006, 08:24 PM   #4 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




In your first mysql_query, change it to this:

PHP Code:
$result mysql_query($sql)or die('SQL Error:<ul><li>'.$sql.'</li><li>'.mysql_error().'</li></ul>'); 
????: NamePros.com http://www.namepros.com/showthread.php?t=250239
That should show the error message.
Barrucadu is offline  
Old 10-23-2006, 08:52 PM   #5 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
Change
Code:
                while ($row = mysql_fetch_array($result)) // This is line 441 in my file
To
Code:
                while ($row = mysql_fetch_assoc($result)) // This is line 441 in my file
Dan is offline  
Old 10-24-2006, 03:10 PM THREAD STARTER               #6 (permalink)
NamePros Regular
 
TwiztedFake's Avatar
Join Date: Apr 2004
Location: IL
Posts: 348
TwiztedFake is on a distinguished road
 



Mikor - I get the same error I'm already getting.

Dan - Same thing, code still works like it should be gives me that error. I'm going to try a different way of writing it later on. Right now I got some other things to work on.

Thanks for the help guys
__________________
-TwiztedFake-
RTard Tutorials
Digital-Dummy to Total-Techie
TwiztedFake is offline  
Old 10-24-2006, 05:43 PM THREAD STARTER               #7 (permalink)
NamePros Regular
 
TwiztedFake's Avatar
Join Date: Apr 2004
Location: IL
Posts: 348
TwiztedFake is on a distinguished road
 



After looking at I realised where my mistake was. Basically I over coded it. No need for the while statement since I want to delete every entry that has the same id based on what was passed on to the function. So I removed all the first query and it works fine and no errors.

I just left it alone for awhile and it came to me what I needed to do. In the original function it selected * from the table then had a while statement but in that statement it was deleting all the entries on the first round. So when it looped back it had conflicting info. One said it still had more entries when really they were already gone. Here is my edited function that now works with no errors.

PHP Code:
function delete()
    {
        
$ID $_GET['id'];
        
$table $_GET['table'];
        
$table 'ct_'.$table;
    
        if (
$table == 'ct_blog')
            {
                
$type "b";
                
$cid $type.$ID;
????: NamePros.com http://www.namepros.com/showthread.php?t=250239
                
$sql "DELETE FROM ct_comments WHERE cid = '$cid'";
                
$result mysql_query($sql)or die('SQL Error:<ul><li>'.$sql.'</li><li>'.mysql_error().'</li></ul>');
                    if (!
$result)
                        {
                            
stop('Failed to delete comments for entry from database. Error returned is '.mysql_error());
                        }
                    echo 
'Comments sucessfully deleted.<br />';
            }
            
        
$sql "DELETE FROM $table WHERE ID = '$ID' LIMIT 1";
        
$result mysql_query($sql);
        if (!
$result)
????: NamePros.com http://www.namepros.com/showthread.php?t=250239
            {
                
stop('Failed to delete entry from Database. Error returned is '.mysql_error());
            }
        echo 
'Entry sucessfully deleted.';
    } 
__________________
-TwiztedFake-
RTard Tutorials
Digital-Dummy to Total-Techie
TwiztedFake is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:04 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger