Search
Left Quote    I think there is a world market for maybe five computers.
- Thomas Watson, Chairman of IBM 1943    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Regiter.php STR replace ???
  This user is offline  access
  Subject: "Regiter.php STR replace ???" Posted: @ 11:42 pm on Feb 12 2007   

Member #: 275
Rank: User - (6)
Since: 02/12/07
Posts: 6
From: Kamloops, BC

ok so I've just created the DB table and I have created the connect.php and register.php I am getting this error when I try to register myself
Code:
Wrong parameter count for str_replace() in /home/access/pu blic_html/regis ter.php on line 23

here is line 20 to 24 in the reg php page.
Code:

20. $len = strlen($_POST[' username']);
21
22. //replace invalid characters
23. $_POST['usernam e'] = str_replace('', $_POST['usernam e']);
24. $test = $_POST['usernam e'];

I thought it might have to do with the '' in line 23 but I don't think so.


    Viewed: 6,478 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Regiter.php STR replace ???" Posted: @ 1:01 am on Feb 13 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

It does and it doesnt. You have simply left out a parameter of the function. This funtion requires 3 parameters:

str_replace( -search- , -replace- , -subject-);

-search- = What you are looking for (to replace). In this case, you forgot the $junk array. You are looking to replace invalid characters.

-replace- = what you want to replace the -search- with. In your case, if it found an invalid character, you want it to remove it, or ''.

-subject- = Variable name to which the function applies. In your case, $_POST['userna me'].

In the register.php script, we take the length of the username the visitor has selected. Then, we strip out any unwanted characters (via the str_replace(); function). Then check if the lengths are different. If they are, then the function found an invalid character, so at that point we would error out and tell them to remove invalid characters. If not, it is safe to proceed through the rest of the script.

Hope that helps




-bs0d | AllSyntax.com

    Viewed: 6,472 Times | Reply to This | To top
  This user is offline  access
  Subject: "re: Regiter.php STR replace ???" Posted: @ 4:27 pm on Feb 13 2007    

Member #: 275
Rank: User - (6)
Since: 02/12/07
Posts: 6
From: Kamloops, BC

It helped a lot, thank you.
Took array out because it was causing errors then I remembered that I need to put the slash before all my \'code in php\' so that stopped the array from erroring and you telling me what str_replace tells me I did delete too much: opps my bad.




    Viewed: 6,459 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank