[PHP] Re: question about M. Lemos's HTML forms generation and validation
It's a simple algorythem, use a loop to enter the names from the database into an array, and compare each to the value in the array. or some hybred thereof. ?php function Compare($UserInput) { $db=mysql_connect($ServerAddress,$LoginName,$LoginPassword)); mysql_select_db($userDB,$db); $result = mysql_query('Select * from ' . $TableWithNames, $db); $rowIndex =;/*right here enter the column in the row that your user names are stored in */ while ($row = mysql_fetch_row($result)) { if ($row[$rowIndex] == $UserInput) { return true; } return false; } mysql_close; }/*This is the end of the function.. next you will have to rip the user input from the post.. in this example I'll call it $_POST[Name] and use the function to return the value if the function returns true then the name exists in the database if false then it obviously don't*/ $Name = $_POST[name]; $bolNames = Compare($Name); if (bolNames == true) { echo('The name exists'); } if (bolNames == false) { echo('The name don't exist') } ? regardless of what performance freaks say.. this won't make a big dif in performance unless you are like yahoo with several hundred million names to compare to.. any intrensic functions basically do this same thing. This gives you more power though. and if you have a HUGE user base you will prolly be running mysql on a stand alone machine away from the web server so that the traffic don't affect db interaction. FYI the syntax may be somewhat rough, I'm somewhat new to the syntax.. I have been coding software for quite some time and this works for me. Good luck. Dr. Zoidberg [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Manuel Lemos wrote: Hello, On 03/25/2004 10:19 PM, Dr. Zoidberg wrote: I'm creating registration service with this great form script for creating forms within Smarty. Question is how can I validate 'username' against allready registered users in MySQL so that someone cannot register him self if there is another user with that username. You can always use the ValidateServerFunction parameter to specify the name of a callback function that will make a database query to see if ise there any user name with the value passed to that function. If there is a record with that user name return 0 and the class will set the respective input field as invalid. I'm trying to create that for a few hours. Can you PLS give me an example? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: question about M. Lemos's HTML forms generation and validation
I just looked over the code I recently submitted.. the last if statement needs a semi-colon at the end of the echo(The name don't exist) part... sory if you copy/pasted and got an error.. ;) Gimic [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] It's a simple algorythem, use a loop to enter the names from the database into an array, and compare each to the value in the array. or some hybred thereof. ?php function Compare($UserInput) { $db=mysql_connect($ServerAddress,$LoginName,$LoginPassword)); mysql_select_db($userDB,$db); $result = mysql_query('Select * from ' . $TableWithNames, $db); $rowIndex =;/*right here enter the column in the row that your user names are stored in */ while ($row = mysql_fetch_row($result)) { if ($row[$rowIndex] == $UserInput) { return true; } return false; } mysql_close; }/*This is the end of the function.. next you will have to rip the user input from the post.. in this example I'll call it $_POST[Name] and use the function to return the value if the function returns true then the name exists in the database if false then it obviously don't*/ $Name = $_POST[name]; $bolNames = Compare($Name); if (bolNames == true) { echo('The name exists'); } if (bolNames == false) { echo('The name don't exist') } ? regardless of what performance freaks say.. this won't make a big dif in performance unless you are like yahoo with several hundred million names to compare to.. any intrensic functions basically do this same thing. This gives you more power though. and if you have a HUGE user base you will prolly be running mysql on a stand alone machine away from the web server so that the traffic don't affect db interaction. FYI the syntax may be somewhat rough, I'm somewhat new to the syntax.. I have been coding software for quite some time and this works for me. Good luck. Dr. Zoidberg [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Manuel Lemos wrote: Hello, On 03/25/2004 10:19 PM, Dr. Zoidberg wrote: I'm creating registration service with this great form script for creating forms within Smarty. Question is how can I validate 'username' against allready registered users in MySQL so that someone cannot register him self if there is another user with that username. You can always use the ValidateServerFunction parameter to specify the name of a callback function that will make a database query to see if ise there any user name with the value passed to that function. If there is a record with that user name return 0 and the class will set the respective input field as invalid. I'm trying to create that for a few hours. Can you PLS give me an example? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] REsource Identifier( PHP_MYSQL)
Hey y'all, I'm having problems trying to get the MySql_Query() function to return the resource ID when using a $string as the argument to pass to it. It returns when I hard code the argument but not the string. Any ideas? here is what the function looks like: function GetVals() { $db = mysql_connect(localhost, root); $str_Query=(Select * from . $subject); mysql_select_db(books,$db); $result = mysql_query($str_Query); echo $result; } but when I use the query: $result=mysql_query(Select * from math) it works. Am I setting my string up wrong? Because it's not running into any errors when I do this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: REsource Identifier( PHP_MYSQL)
The entire script looks like this: ?php if ($_POST[Subject] != NULL) { echo results for . $_POST[Subject]; $subject = $_POST[Subject]; $qry = (select * from . $subject); $sqlQry = (string) $qry; GetVals(); } function GetVals() { $db = mysql_connect(localhost, root); mysql_select_db(books,$db); $result = mysql_query($sqlQry,$db); echo mysql_errno($db); echo mysql_error($db); echo $result; } ? Where the name of the table is stored in the $_POST varible. The string isn't empty, yet it is empty. It may be a bug... Or do any of you see any problem with my varible scope? because I don't. Gimic [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hey y'all, I'm having problems trying to get the MySql_Query() function to return the resource ID when using a $string as the argument to pass to it. It returns when I hard code the argument but not the string. Any ideas? here is what the function looks like: function GetVals() { $db = mysql_connect(localhost, root); $str_Query=(Select * from . $subject); mysql_select_db(books,$db); $result = mysql_query($str_Query); echo $result; } but when I use the query: $result=mysql_query(Select * from math) it works. Am I setting my string up wrong? Because it's not running into any errors when I do this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php