|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||
|
||||
|
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 |
|
#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. |
|
#9
|
|||
|
|||
|
Hi
Ok thanks i'll try it out in a sec. Thanks! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Help with mySQL needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|