Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 20th, 2001, 06:00 PM
sjbates sjbates is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: England, UK
Posts: 41 sjbates User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Help with removing %20 needed

Hi

I have a mySQL database and some perl code with i'm using from a tutorial. The database contains information abouts such as the type of plan they have e.g. Bronze Unix Hosting.

The problem i have is when i try to edit the database the script only brings up Bronze so i was wondering is there anyway to automaticly add %20 or any other way of getting this to work.

Thanks for any help!

Reply With Quote
  #2  
Old July 21st, 2001, 11:45 AM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
I'm not really clear on what you are asking.

If you are asking for help using strictly MySQL, you'd probably be better of posting in the MySQL forum. If you are trying to do it from a Perl script, then using DBI.pm you could use regular SQL along with a DBI statement handle to get data, modify it, and update the database.

If the case is the latter, try something like this:
Code:
#!/usr/bin/perl

use DBI;
use strict;

my $var;
my $add;
my $dbh = DBI->connect("DBI:mysql:database:hostname", "user", "pass") or die "Connect Err: $DBI::errstr";

my $sth0 = $dbh->prepare("SELECT whatever FROM wherever WHERE foo = 'bar'");
my $sth1 = $dbh->prepare("UPDATE wherever SET whatever=? WHERE foo = 'bar'");

$sth0->execute();
$sth0->bind_columns(\$var);
$sth0->fetch();

$add = $var * .2;
$var += $add;

$sth1->execute($var) or die "UPDATE Err: $DBI::errstr";

If this makes no sense to you then you need to either pick up Oreilly's PerlDBI book, or read the perl documentation for DBI.pm. But pretty much whats going on here is that you are connecting to a MySQL database, fetching data($sth0), modifying it, and updating($sth1). Some might say this code is inefficient(and it is for a single update), but I wanted to demonstrate the 4 steps to fetching data:
1. Prepare the SQL query
2. Execute the query
3. Bind the data to a variable
4. Fetch the data
There is another DBI function(DBI::do()) that will do all this for you with one line of code, but when looping through multiple records, that function becomes inefficient.
__________________
- dsb -
Perl Guy

Reply With Quote
  #3  
Old July 21st, 2001, 12:42 PM
sjbates sjbates is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: England, UK
Posts: 41 sjbates User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hi

What it is, is that we have so many hosting plans all with names such as 'Bronze Unix Hosting'.

When i insert a record into the mySQL database it inserts is as 'Bronze Unix Hosting' but when i use modify script in the text box it brings up 'Bronze'.

So what i am asking is there anyway of replacing the spaces with %20 as that stands for a space or is there anyway of showing it up.

Not tried the bit you gave me but will have ago in a bit when i get time.

Thanks.

Reply With Quote
  #4  
Old July 21st, 2001, 01:08 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
Ahhhh.

I see. Okay ignore the code I already gave you. I thought you wanted to add 20 percent to a numeric value. But, I see what you want to do.

Referring to you actual question, if you are trying to use %20 to replace spaces, then I am assuming you are calling this script from a web-form or something like that. If that's the case, then most browsers will convert spaces to an appropriate replacement automatically(%20 or '+').

Post the code you are having trouble with and I'll see if I can give you some better help.

Reply With Quote
  #5  
Old July 21st, 2001, 01:18 PM
sjbates sjbates is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: England, UK
Posts: 41 sjbates User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hi

I uploaded my code in a text file so it dont fill the page out.

The text 'Bronze Unix Hosting' is not inserted with %20, the problem comes when i try to view it, it only shows as 'Bronze' so what i was thinking is there anyway to add %20 when i add the record then convert it to a space when the page is viewed.

I uploaded it to http://billing.sthost.com/modify.txt

There is another perl page part of this script but this is the one i'm having the problem with.

Thanks.

Reply With Quote
  #6  
Old July 21st, 2001, 02:18 PM
sjbates sjbates is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: England, UK
Posts: 41 sjbates User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hi

I'm not sure but it may be me as i'm working on a customer information script now which stores all their info in a mySQL database and in there i have got 2 text boxes to show up with spaces in so it might just be something i'm doing wrong - i'll check over everything.

Thanks.

Reply With Quote
  #7  
Old July 21st, 2001, 04:44 PM
yhcmarc's Avatar
yhcmarc yhcmarc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Heemskerk, The Netherlands
Posts: 254 yhcmarc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 49 sec
Reputation Power: 8
ok, put 'Bronze unix hosting' into a variable line $BUH

then $BHU =~ s/\s/\%20/g;

this replaces all the spaces in $BUH into %20

Reply With Quote
  #8  
Old July 21st, 2001, 04:50 PM
yhcmarc's Avatar
yhcmarc yhcmarc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Heemskerk, The Netherlands
Posts: 254 yhcmarc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 49 sec
Reputation Power: 8
oh, I didn't pay enough attention, it's only needed in the html page, if you'd run your script from the command line it will probably show the Bronze unix hosting complete. But anyway, in the output just before you start to build the page you should use the command I used in my former reply.

So for the variables you have to use in the addressbar of the browser use

$variable =~ s/\s/\%20/g;

I think this would help a lot, now you don't have to change any of the input into your database, you just change the output a bit so you can work with it.

Reply With Quote
  #9  
Old July 21st, 2001, 04:58 PM
sjbates sjbates is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: England, UK
Posts: 41 sjbates User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hi

Ok thanks i'll try it out in a sec.

Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Help with mySQL needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT