Page 1 of 1

Several validation and text manipulation questions for PHP.

Posted: Sun Dec 07, 2008 8:25 pm
by FacJoe
Hi. I'm fairly new to PHP (1 week) and I've been tasked to do some enhancement work for an already existing website. I don't know anything about PHP but upon reading some references and the code itself, it's a bit akin to C#, that's why for the first few days, I can do some stuff I need to do but I'm stuck right now and I need a bit of help.

1. I have a text box and the user needs to enter a number of strings that will be delimited by a comma. I need to check if each of the string values entered are unique (regardless of the casing). Is there a way to do this 'easier' (something akin to an AJAX component) or there's no way to go around this than to do it programmatically?

2. I have this code

Code: Select all

echo "<a href=sydney.php?cityname=", strtoupper($row["name"]), ">", $row["name"], " SALES + EVENTS <br></a>";
but for some reason, the value of the variable "$row["name"]" does not show up in all upper case letters. What could I be doing wrong?

3. We have a table and we have <a href> links whose jobs are to view, edit and copy the data for each row. For the "view" and "edit" functions, there is no problem since we just pass the variables and get them via the $_POST/$_GET function to the other page. But for the 'copy' function, it's just a straightforward MySQL (we're using MySQL as backend, BTW) function that should copy the row information to a specific table in the database and it should not really redirect to another page. The very least I could do is to pop up a javascript message box/alert/prompt asking the user if he really wants to copy the info and then, call the function that copies the row info after he clicks "OK" but my main problem is, I don't know how to call the function w/o using a button's "POST" action/method.

Don't ask me why we're not using buttons for this, because I did not really come up with the UI, so I have to make do with what's on my table.

I hope I made sense. Thank you in advance.

Re: Several validation and text manipulation questions for PHP.

Posted: Sun Dec 07, 2008 9:43 pm
by requinix
1. Either you do it in JavaScript or you do it in PHP. The latter solution could look like

Code: Select all

$parts = preg_split('/\s*,\s*/', $_GET["data"]);
$is_unique = (count($parts) == count(array_unique($parts)));
2. strtoupper doesn't modify the string, it returns a different version of it. If you want it in uppercase then use that function. Again.

3. You can do AJAX on the main page, or you can popup a "dialog", have the confirmation form submit to a PHP page, do the update, and close the window.