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 Where is the mistake in here?

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 02-16-2007, 06:08 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Jan 2007
Posts: 98
baris22 is an unknown quantity at this point
 



Where is the mistake in here?


Hello all,

I could not solve this problem. There is a mistake in here but i do not know where.

Please help

PHP Code:

{
    
$desc str_replace("[""\r\n"$_REQUEST['description']);
    
$arrayOflinks explode(";"$_REQUEST['links']);

    
// Get Extension of first extry
    
$extPos strrpos($arrayOflinks[0], ".");
????: NamePros.com http://www.namepros.com/programming/295130-where-is-the-mistake-in-here.html
    if (
$extPos !== false)
    {
        
$ext substr($arrayOflinks[0], $extPos+1);
        
$extL strtolower($ext);
        if (!
strcasecmp($extL"bmp") || !strcasecmp($extL"jpg") || !strcasecmp($extL"gif"))
        {
            
$imageTag "<img src='".$arrayOflinks[0]."' border='0'>";
            
$arrayOflinks[0]=$imageTag;
        }
    }
????: NamePros.com http://www.namepros.com/showthread.php?t=295130
    
$link implode("<br>"$arrayOflinks);


    
$query "insert into articles (`id`, `type`, `title`, `description`, `links`) values('0', '".$_REQUEST['type']."','".$_REQUEST['title']."','".$desc."','".$link."')";
    print 
$query;
    
mysql_query($query);
    exit();

baris22 is offline  
Old 02-16-2007, 06:13 PM   #2 (permalink)
NamePros Regular
Join Date: Jan 2007
Posts: 239
NewYorkBum has a spectacular aura aboutNewYorkBum has a spectacular aura about
 



could you post the error you getting as well ?
NewYorkBum is offline  
Old 02-16-2007, 06:20 PM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Jan 2007
Posts: 98
baris22 is an unknown quantity at this point
 



There is no error. it is just not recording to the database.

If I do like this it works

PHP Code:


    
$desc str_replace("[""\r\n"$_REQUEST['description']); 
    
$link str_replace(";""<br>"$_REQUEST['links']);

   
    
$query "insert into articles (`id`, `type`, `title`, `description`, `links`) values('0', '".$_REQUEST['type']."','".$_REQUEST['title']."','".$desc."','".$link."')"
????: NamePros.com http://www.namepros.com/showthread.php?t=295130
    print 
$query
    
mysql_query($query); 
    exit(); 

baris22 is offline  
Old 02-16-2007, 08:22 PM   #4 (permalink)
NamePros Member
Join Date: Feb 2007
Location: Surabaya - Indonesia
Posts: 27
silentwind is an unknown quantity at this point
 



Did you use auto-increment and primary key or unique on `id` field? if yes, that would be the problem.
Try using these :
PHP Code:
$query "insert into articles (`type`, `title`, `description`, `links`) values('".$_REQUEST['type']."','".$_REQUEST['title']."','".$desc."','".$link."')"
????: NamePros.com http://www.namepros.com/showthread.php?t=295130
silentwind is offline  
Old 02-17-2007, 02:57 AM   #5 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
edit: Nevermind, re-read OP.
Last edited by Matthew.; 02-17-2007 at 03:02 AM.
Matthew. is offline  
Old 02-17-2007, 03:26 AM   #6 (permalink)
tm
Senior Member
 
tm's Avatar
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,408
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
 



change
PHP Code:
 mysql_query($query); 
to
PHP Code:
 mysql_query($query) or die(mysql_error()); 
????: NamePros.com http://www.namepros.com/showthread.php?t=295130
So we can see the error if there is one.
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline  
Old 02-17-2007, 06:29 AM   #7 (permalink)
Account Closed
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



Im sure mysql is case sensitive try changing "insert into" to "INSERT INTO"
NetworkTown.Net is offline  
Old 02-17-2007, 06:51 AM   #8 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,552
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
Originally Posted by NetworkTown.Net
Im sure mysql is case sensitive try changing "insert into" to "INSERT INTO"
The SQL commands are not case-sensitive

Also the INTO keyword is not needed here, remove it:
Code:
$query = "insert articles (`id`, `type`, `title`, `description`, `links`) values('0', '".$_REQUEST['type']."','".$_REQUEST['title']."','".$desc."','".$link."')";
SELECT INTO is used when you want to perform a multiple insert based on another table or query.

Is ID an auto-incremented field or primary key ? If it's an auto-incremented value remove it from your insert statement.

Finally you are performing inserts based on $_REQUEST variables which is dangerous.

1. You need to check the input values, otherwise people can manipulate them and enter anything, including values that will crash your script.
2. You need to check if there are any single quotes (') that need escaping. Have a look at mysql_real_escape_string: http://php.net/mysql_real_escape_string. Again your script could crash if special characters are not properly handled.
????: NamePros.com http://www.namepros.com/showthread.php?t=295130

My advice would be: at the beginning of your script check the $_REQUEST values and assign them to variables. Then check if they are not empty, have the expected format etc (regular expressions are very helpful for this).
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline  
Old 02-17-2007, 06:51 AM   #9 (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
 




Originally Posted by NetworkTown.Net
Im sure mysql is case sensitive try changing "insert into" to "INSERT INTO"
The case of the commands dosn't matter, its more of a standard to use upper case commands though.

Yes, do as tm said and get the error with mysql_error(); and tell us what it is.
Barrucadu is offline  
Old 02-17-2007, 07:04 AM   #10 (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
Quote:
Code:
    $query = "insert into articles (`id`, `type`, `title`, `description`, `links`) values('0', '".$_REQUEST['type']."','".$_REQUEST['title']."','".$desc."','".$link."')";
    print $query;
Just run the query in phpMyAdmin and it should tell you exactly what the problem is.
Dan is offline  
Old 02-17-2007, 11:26 AM   #11 (permalink)
NamePros Regular
 
DylanButler's Avatar
Join Date: Jan 2006
Location: San Diego, CA
Posts: 735
DylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to beholdDylanButler is a splendid one to behold
 



Originally Posted by NetworkTown.Net
Im sure mysql is case sensitive try changing "insert into" to "INSERT INTO"
Can I put this in my sig?
DylanButler is offline  
Old 02-17-2007, 12:58 PM THREAD STARTER               #12 (permalink)
NamePros Member
Join Date: Jan 2007
Posts: 98
baris22 is an unknown quantity at this point
 



Thanks for help. But the problem is in here. If i do not write this, it works fine but if i write this it does not work.

I do not have a chance to check what is wrong. It is not possible. This page is getting called by a windows application. If the code is wrong , I do not get any error message. If the code is right, it is recording to the database.

Thanks all

PHP Code:

$arrayOflinks 
explode(";"$_REQUEST['links']); 

    
// Get Extension of first extry 
    
$extPos strrpos($arrayOflinks[0], "."); 
????: NamePros.com http://www.namepros.com/showthread.php?t=295130
    if (
$extPos !== false
    { 
        
$ext substr($arrayOflinks[0], $extPos+1); 
        
$extL strtolower($ext); 
        if (!
strcasecmp($extL"bmp") || !strcasecmp($extL"jpg") || !strcasecmp($extL"gif")) 
        { 
            
$imageTag "<img src='".$arrayOflinks[0]."' border='0'>"
            
$arrayOflinks[0]=$imageTag
        } 
????: NamePros.com http://www.namepros.com/showthread.php?t=295130
    } 
    
$link implode("<br>"$arrayOflinks); 
baris22 is offline  
Old 02-17-2007, 06:03 PM   #13 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
try changing this

PHP Code:
$link implode("<br>"$arrayOflinks); 
????: NamePros.com http://www.namepros.com/showthread.php?t=295130
to this

PHP Code:
$link mysql_real_escape_string(implode("<br>"$arrayOflinks)); 
cef is offline  
Old 02-17-2007, 08:16 PM THREAD STARTER               #14 (permalink)
NamePros Member
Join Date: Jan 2007
Posts: 98
baris22 is an unknown quantity at this point
 



Originally Posted by cef
try changing this

PHP Code:
$link implode("<br>"$arrayOflinks); 
to this

PHP Code:
$link mysql_real_escape_string(implode("<br>"$arrayOflinks)); 
????: NamePros.com http://www.namepros.com/showthread.php?t=295130



Wawwwwww. Thank you very much man. It worked.
I was trying to sort this out for 3 days.

Thanks again.
baris22 is offline  
Old 02-18-2007, 09:41 AM   #15 (permalink)
Account Closed
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



Originally Posted by DylanButler
Can I put this in my sig?
:@ Ok i made a mistake no need to take it that far.
NetworkTown.Net 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 03:53 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