Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Coder Need Help with PERL DBI (MySQL)

Status
Not open for further replies.

webdude12

Programmer
Oct 15, 2008
1
US
I am a long time php coder, that needs to convert a script to Perl.

Here is the code in PHP
[tab]$store_list_name = $prod[10];
[tab]$category = $prod[11];
[tab]$sub_category = $prod[12];

[tab]$searchfor = $store_list_name . "->" . $category . "->" . $sub_category;
[tab]$getcat = mysql_query("SELECT * FROM categories WHERE (overstock_id LIKE '%|".addslashes($searchfor)."|%');",$link);
[tab]while ($p_row =mysql_fetch_array ($getcat) ) {
[tab]$cat_name = stripslashes($p_row[cat_name]);
[tab]$cat_id = $p_row[cat_id];
[tab]$sub_of = $p_row[sub_of];
[tab]}

Here is what I have in PERL:
[tab]my $searchfor = $store_list_name . "->" . $category . "->" . $sub_category;
[tab]my $search_by = $dbh->quote($searchfor);
[tab]my $query = "SELECT * FROM categories WHERE overstock_id %|".$searchfor."|%";
[tab]my $dth = $dbh->prepare($query);
[tab]$dth->execute();
[tab]my $ref;
[tab]while ($ref = $dth->fetchrow_hashref())
[tab]{
[tab]my $master_cat = $ref->{cat_id};
[tab]my $sub_cat = $ref->{sub_of};
[tab]}

The problem I am running into is, I get this error:
DBD::mysql::st execute failed: 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 '|Tools->Professional Grade Tools->Tool Sets|%' at line 1 at ./test.pl line 57, <CSV> line 585.

My first % is going bye bye.... Can some one help?
 
change the double quotes to single quotes anytime you don't have a variable.

so
"SELECT * FROM categories WHERE overstock_id %|"
becomes
'SELECT * FROM categories WHERE overstock_id %|'
That should you help you out some :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top