[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 02-16-2007, 05:08 PM   #1 (permalink)
NamePros Member
 
Join Date: Jan 2007
Posts: 68
0.00 NP$ (Donate)

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], ".");
    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;
        }
    }
    
$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, 05:13 PM   #2 (permalink)
NamePros Regular
 
Join Date: Jan 2007
Posts: 241
30.50 NP$ (Donate)

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, 05:20 PM   #3 (permalink)
NamePros Member
 
Join Date: Jan 2007
Posts: 68
0.00 NP$ (Donate)

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."')";
    print
$query;
    
mysql_query($query);
    exit();
}
baris22 is offline  
Old 02-16-2007, 07:22 PM   #4 (permalink)
NamePros Member
 
Join Date: Feb 2007
Location: Surabaya - Indonesia
Posts: 27
0.00 NP$ (Donate)

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."')";
silentwind is offline  
Old 02-17-2007, 01:57 AM   #5 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

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.
__________________
My NamePros Tools
(firefox plugin, google gadget etc)

Last edited by Matthew.; 02-17-2007 at 02:02 AM.
Matthew. is offline  
Old 02-17-2007, 02:26 AM   #6 (permalink)
tm
Senior Member
 
tm's Avatar
 
Join Date: Nov 2005
Location: on a oil rig just off Ireland
Posts: 1,409
374.65 NP$ (Donate)

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());
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, 05:29 AM   #7 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

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, 05:51 AM   #8 (permalink)
Domains my Dominion
 
sdsinc's Avatar
 
Join Date: Aug 2005
Location: Web 1.0
Posts: 6,285
1,095.94 NP$ (Donate)

sdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond repute

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
Quote:
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.

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).
__________________
Buy now - MassDeveloper.com $500
sdsinc is offline  
Old 02-17-2007, 05:51 AM   #9 (permalink)
Barru.
 
Barrucadu's Avatar
 
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,731
78.50 NP$ (Donate)

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


Quote:
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 online now  
Old 02-17-2007, 06:04 AM   #10 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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, 10:26 AM   #11 (permalink)
NamePros Regular
 
DylanButler's Avatar
 
Join Date: Jan 2006
Location: San Diego, CA
Posts: 704
0.00 NP$ (Donate)

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 behold


Quote:
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?
__________________
:great: -Dylan Butler

EXAMP - San Diego Web Design
DylanButler is offline  
Old 02-17-2007, 11:58 AM   #12 (permalink)
NamePros Member
 
Join Date: Jan 2007
Posts: 68
0.00 NP$ (Donate)

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], ".");
    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;
        }
    }
    
$link = implode("<br>", $arrayOflinks);
baris22 is offline  
Old 02-17-2007, 05:03 PM   #13 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

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);
to this

PHP Code:
$link = mysql_real_escape_string(implode("<br>", $arrayOflinks));
cef is offline  
Old 02-17-2007, 07:16 PM   #14 (permalink)
NamePros Member
 
Join Date: Jan 2007
Posts: 68
0.00 NP$ (Donate)

baris22 is an unknown quantity at this point


Quote:
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));



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, 08:41 AM   #15 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice


Quote:
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 09:12 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85