Hi all,
I have one webpage in which people can order books online.
i have one array - book , in which i have stored all different types of books.
Now, I dont want the user to order any garbage ( just numerical entry and not alphabetics ) .
How can I do so ??
I have used following code , but dint work proper -
if(isset($_POST['books']) ) {
-
$input = $_POST['books'];
-
foreach($input as $input1)
-
{
-
if(!(ereg("^[0-9]+$",$input1))) die ('Please enter numeric values ') ;
-
}
-
}
-
in Above , I want to check for all the entries of books , whether the value entered is numeric or not....
But I guess I am not populating array properly , So how can I do so ??
15 3282
Check your $_POST variable.[php]echo "<pre>";
print_r($_POST);
echo "</pre>";[/php]
And use is_int.[php]if (!is_int($input1)) die ('error.... .. ');[/php]
Check your $_POST variable.[php]echo "<pre>";
print_r($_POST);
echo "</pre>";[/php]
And use is_int.[php]if (!is_int($input1)) die ('error.... .. ');[/php]
Hey Hsriat,
When i code echo "<pre>" ........echo "</pre>"
i got following O/P -
<pre>Array
-
(
-
[customername] =>
-
[email] =>
-
[books] => Array
-
(
-
[book1] => 22
-
[book2] =>
-
)
-
-
[enroll] => Array
-
(
-
[s1] =>
-
[s2] =>
-
)
-
[comments] =>
-
but , e'time it goes to die portion only even if i have provided numeric values...( also in the code that you have given )
Thanks for your help Hsriat
I see that $_POST[books][book2] is empty. Perhaps, this is causing the problem.
There might be something wrong with your form HTML.
Post the HTML part of the form being used.
I see that $_POST[books][book2] is empty. Perhaps, this is causing the problem.
There might be something wrong with your form HTML.
Post the HTML part of the form being used.
Hi Hsriat ,
book2 field is empty as I have not provided ( i have not ordered that book)..I just want to order book1 .....So the numeric value is number of orders made...And i have to check that numbers only whether they are numerical or not , as no one can write some alphabetics in that field..
Thanks,
Ok, for that, we can add some code to the PHP side, but I would suggest you to make a change in the form HTML, so that only that book id is posted which is selected, not the unselected ones.
How are you selecting the books?. Checkbox or what?
Ok, for that, we can add some code to the PHP side, but I would suggest you to make a change in the form HTML, so that only that book id is posted which is selected, not the unselected ones.
How are you selecting the books?. Checkbox or what?
Hi hsriat, -
Small book, Volume I</td>
-
<td align="center">$70x <input type="text" name="books[book1]"
-
size="2" /></td>
-
user can enter the quantity of book1 in books[book1] text box..or they can leave it empty if they dont wnat book1 and want book2 ...book3....and so on
hope I made it clear.
and ya , the only book selected are shown in the final order-made page.
the array i just show you to have an Idea.
Thnaks
Remove book1 etc from withing the square braces. Let it be books[] in each input, and try again.
Hey hsriat,
I think the way I am approaching the array book is not valid ,
As -
foreach($_POST['books'] as $input1)
-
{
-
echo $input1 ;
-
/* if(!(ereg("^[0-9]+$",$input1)))
-
{
-
// die ('Please enter numeric values in the Quantity fields') ;
-
} */
-
}
-
i have just commented out the if statement n just checked the values of input1 , its just an variable seems(not array) as i have selected two books 11 ,22 quntity each,
input1 shows me 1122 as the value..Is it causing some problem,
because when i used above code for all the single entry i.e -
if(isset($_POST['books']['book1']) ) { $input = $_POST['books']['book1'];
-
if(!(ereg("^[0-9]+$",$input)))
-
{ die ('Please enter numeric values in the Quantity fields') ; }}
-
it gives me perfect desire answer..
So may be some problem with array manipulation ...what you suggest??
Hi Hsriat,
Removing the book1 and ... options may not be proper ,as we have huge number of coding after that..so is there any other way ?
[php]$selected_books = array();
foreach ($_POST['books'] as $input)
{
if (is_int($input))
array_push($input, $selected_books);
elseif ($input != "")
die ('...error...');
}
//$selected_books contains the array of your required books.[/php]
Try this...
[php]$selected_books = array();
foreach ($_POST['books'] as $input)
{
if (is_int($input))
array_push($input, $selected_books);
elseif ($input != "")
die ('...error...');
}
//$selected_books contains the array of your required books.[/php]
Try this...
Hi hsriat,
Thanks for the help...But i want to discard the whole order if one has entered any alphabetics in that text box
The above code does not give me any answer.
Thanks,
hey Hsriate,
The problem is solved now..
Thanks ..
But i want to discard the whole order if one has entered any alphabetics in that text box
That's what it is doing!
Didn't you try it?
hey Hsriat,
The problem is solved now..
Thanks ..
You are welcome.
That's what it is doing!
Didn't you try it?
Yeah , I do try that, but IT dint give me any answer..
But i have taken two dimensional array and compared it.n it worked !!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michelle |
last post by:
hi,
i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)
which i have sorted in alphabetical order, but i need to
identify duplicates...
|
by: John MacIntyre |
last post by:
Hi,
Can anybody give me a hint as to how to convert a javascript array into a
vbscript array?
BTW-it only needs to work in IE5 & 6
Thanks in advance,
John MacIntyre
VC++ / VB / ASP /...
|
by: Federico G. Babelis |
last post by:
Hi All:
I have this line of code, but the syntax check in VB.NET 2003 and also in
VB.NET 2005 Beta 2 shows as unknown:
Dim local4 As Byte
Fixed(local4 = AddressOf dest(offset))
...
|
by: Bob P. |
last post by:
Hello,
I have a page with:
* two side-by-side asp:listboxes and two arrow asp:buttons allowing
users to add/remove email addresses between them -- very much like
Outlook, where you have the...
|
by: Sheldon |
last post by:
Hi,
I have two arrays that are of the same dimension but having 3 different
values: 255, 1 or 2.
I would like to set all the positions in both arrays having 255 to be
equal, i.e., where one...
|
by: Reny |
last post by:
can any one tell how can i restrict my user to type just numeric character
in the textbox.I am using VS.NET 2003 (VB.NET)
|
by: lukemack |
last post by:
Hi,
I have an array in the following format :
Array
(
=Array
(
=Array
(
|
by: OliveOyl3471 |
last post by:
In Visual Basic.NET 2003, how do you populate a two dimensional array from a text file? I know how to check file existence, open the file for read, etc. I just can't get it to read more than one...
|
by: Daniel Klein |
last post by:
I have a class constructor that accepts an array as the only argument. The
catch is that the array MUST be an 'integer-indexed' array, not an
'associative' array, because the index position has...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |