hi
i am doing shopping online, i will let user choose their prodcut in the first page and then when they click" order" button, they will be redirected to do_addcart.php. i will insert their orders into "orders" table and retrieve them back and ask user to select their respective quantity and size. i have used Javascript validation:
the code is below: - <script language="JavaScript">
-
-
<!--
-
-
function validate_form ( )
-
{
-
valid = true;
-
alert (document.Lform.quantity.selectedIndex);
-
if ( document.Lform.quantity.selectedIndex == 0 )
-
{
-
alert ( "Please select your quantity!" );
-
Lform.quantity.focus();
-
valid = false;
-
}
-
else if ( document.Lform.size.selectedIndex == 0 )
-
{
-
alert ( "Please select your size!" );
-
Lform.size.focus();
-
valid = false;
-
}
-
return valid;
-
}
-
//-->
-
</script>
However, i don;t know how to correspond respective product with their respective choosen quantity and size.
the following is my current coding, - <?php
-
foreach ($_POST as $key => $value) {
-
echo "key: ".$key.", value: ".$value."<br>";
-
$sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
-
mysql_query($sql);
-
}
-
-
echo "Please select your size and quantity for purchase:";
-
echo "<table border = '1'>";
-
echo "<tr>";
-
echo "<td>Title";
-
echo "<td>Brand";
-
echo "<td>Price";
-
echo "<td>Size";
-
echo "<td>Quantity";
-
echo "</tr>";
-
$sql2="SELECT imageid FROM orders";
-
$result=mysql_query($sql2);
-
while($row = mysql_fetch_array($result)) {
-
echo "<br>";
-
$sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
-
$ImageResult = mysql_query($sql3);
-
$ImageDetail = mysql_fetch_array($ImageResult);
-
echo "<tr>";
-
echo "<td>".$ImageDetail['title']."";
-
echo "<td>".$ImageDetail['brand']."";
-
echo "<td>".$ImageDetail['price']."";
-
echo"<td>";
-
-
echo"
-
<select id='size' name='size' tabindex='11'>
-
<option value='0'>---
-
<option value='1' >S
-
<option value='2'>M
-
<option value='3'>L
-
<option value='4'>XL
-
</select>
-
</td>";
-
//echo" ";
-
-
-
echo"
-
<td>
-
<select id='NO' name='quantity' tabindex='11'>
-
<option value='0'>---
-
<option value='1' >1
-
<option value='2'>2
-
<option value='3'>3
-
<option value='4'>4
-
<option value='5'>5
-
<option value='6'>6
-
<option value='7'>7
-
<option value='8'>8
-
<option value='9'>9
-
<option value='10'>10
-
</select>
-
</td>";
-
echo "</tr>";
-
}
-
echo "</table>";
-
echo "<input type = 'submit' value = 'order'>";
-
?>
anyone can help me with this, thank you very much. it is bit urgent as the project deadline is near.
Please enclose your coding with [code] tags [Please Find how!] 14 2095 ak1dnar 1,584
Recognized Expert Top Contributor ak1dnar 1,584
Recognized Expert Top Contributor
I can't imagine the way you have used to enter the records from your first page to this php Hope its working fine.
This is not the correct way to do the thing.First Let me know, is there any Relation ship between ORDERS table and LADIES (Strange ha :) )Table.
I can't imagine the way you have used to enter the records from your first page to this php Hope its working fine.
This is not the correct way to do the thing.First Let me know, is there any Relation ship between ORDERS table and LADIES (Strange ha :) )Table.
hi
Orders and Ladies table is interrelated, i will insert whatever users purchases into orders table and there is imageid ( which is foreign key to Ladies table) and userid, so i will know which user choosed which item from imageid. then i use this imageid to retrieve back the value in ladies table.
the code in the first page is like this
the code in do_addcart.php is in the following: - :
-
<?
-
ob_start();
-
session_start();
-
?>
-
<html>
-
<head>
-
<link rel="stylesheet" type="text/css" href="shop.css" /><div id="h">Ladies' Apparels</div>
-
<script language="JavaScript">
-
-
<!--
-
-
function validate_form ( )
-
{
-
valid = true;
-
alert (document.Lform.$quantity.selectedIndex);
-
if ( document.Lform.$quantity.selectedIndex == 0 )
-
{
-
alert ( "Please select your quantity!" );
-
Lform.$quantity.focus();
-
valid = false;
-
}
-
else if ( document.Lform.$size.selectedIndex == 0 )
-
{
-
alert ( "Please select your size!" );
-
Lform.$size.focus();
-
valid = false;
-
}
-
return valid;
-
}
-
//-->
-
</script>
-
</head>
-
<body>
-
<div id="maincol">
-
<form name = "Lform" method = "POST" action = "do_addcart.php" onSubmit = 'return validate_form ();'>
-
<?
-
ob_start();
-
session_start();
-
-
require("db.php");
-
-
mysql_connect(MACHINE, USER, '');
-
mysql_select_db(DBNAME);
-
-
-
$userid = $_SESSION['userid'];
-
-
$date=date("D j-M-Y G:i:s");
-
echo $date;
-
echo"<BR>";
-
-
foreach ($_POST as $key => $value) {
-
echo "key: ".$key.", value: ".$value."<br>";
-
$sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
-
mysql_query($sql);
-
}
-
-
echo "Please select your size and quantity for purchase:";
-
echo "<table border = '1'>";
-
echo "<tr>";
-
echo "<td><b>Title</b></td>";
-
echo "<td><b>Brand</b></td>";
-
echo "<td><b>Price</b></td>";
-
echo "<td><b>Size</b></td>";
-
echo "<td><b>Quantity</b></td>";
-
echo "</tr>";
-
$sql2="SELECT imageid FROM orders";
-
$result=mysql_query($sql2);
-
while($row = mysql_fetch_array($result)) {
-
echo "<br>";
-
$sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
-
$ImageResult = mysql_query($sql3);
-
$ImageDetail = mysql_fetch_array($ImageResult);
-
echo "<tr>";
-
echo "<td>".$ImageDetail['title']."</td>";
-
echo "<td>".$ImageDetail['brand']."</td>";
-
echo "<td>".$ImageDetail['price']."</td>";
-
echo"<td>";
-
echo"
-
<select id='size' name='$size' tabindex='11'>
-
<option value='0'>---</option>
-
<option value='1' >S</option>
-
<option value='2'>M</option>
-
<option value='3'>L</option>
-
<option value='4'>XL</option>
-
</select>
-
</td>";
-
//echo" ";
-
$quantity=0;
-
$quantity=$quantity+1;
-
-
echo"
-
<td>
-
<select id='NO' name='$quantity' tabindex='11'>
-
<option value='0'>---</option>
-
<option value='1' >1</option>
-
<option value='2'>2</option>
-
<option value='3'>3</option>
-
<option value='4'>4</option>
-
<option value='5'>5</option>
-
<option value='6'>6</option>
-
<option value='7'>7</option>
-
<option value='8'>8</option>
-
<option value='9'>9</option>
-
<option value='10'>10</option>
-
</select>
-
</td>";
-
echo "</tr>";
-
}
-
echo "</table>";
-
-
-
//header('Refresh: 3; url=cart.php');
-
//echo "<meta http-equiv='refresh' content='5;url=http://google.com'>";
-
echo "<input type = 'submit' value = 'order'>";
-
echo"<BR>";
-
echo "Your order is being processed, you will be directed to your shopping cart soon";
-
-
?>
-
</body>
-
</html>
-
-
i would like users to choose the items's respective quantity and size, but i don't know how to know which quantity and size is belong to which item. i think my naming may have problem since i all use "quantity" and "size" for every item. but i don't know how to sovle it. i have no clue of it. can help me with it. thanks in advance
ak1dnar 1,584
Recognized Expert Top Contributor
There are lots of Errors in your script. - You are trying to print $quantity, $size inside the HTML(Javascript ) code
Note that PHP is executing in server side,not in the client side.if you need to print server side php varibles inside html coding, you may replace -
document.Lform.$quantity.selectedIndex == 0
-
with this -
document.Lform.<?php $quantity ?>.selectedIndex == 0
-
And Under those list menus why is that name attribute is set to $quantity,$size . From where it is coming from?
are you planing to set the same size and quantity for all purchased item(what are those item really).
There are lots of Errors in your script. - You are trying to print $quantity, $size inside the HTML(Javascript ) code
Note that PHP is executing in server side,not in the client side.if you need to print server side php varibles inside html coding, you may replace -
document.Lform.$quantity.selectedIndex == 0
-
with this -
document.Lform.<?php $quantity ?>.selectedIndex == 0
-
And Under those list menus why is that name attribute is set to $quantity,$size . From where it is coming from?
are you planing to set the same size and quantity for all purchased item(what are those item really).
hi, in fact i was writiing a loop, but i think i delete it befoer i post, originally, i wrtie -
$quantity=0;
-
$quantity=$quantity+1; // do the same for $size;
-
i do in this is to let the drop down list of quantity and size have differe name, so that i may know which item user purchased according to which quantity and size name; something like quantity1=3, quantity2=5,etc .but finally i can not achieve it, i have only this kind of concept.is this concept correct?
in fact, i would like to know the quantity and size they choosed accorrding to the different items they buy and it is a must for them to select quantity and size from drop down list for every item they buy.
i don;t know how should i write the code so that i will know which quantity and size user selected is corresponding to which item they buy and there is also a validation so that user will not forget to select their item's quantity and size.
can help me with these part of the code, thank you very much. i am very frustrated as the project deadline is near. thank you very much for your kind help :)
ak1dnar 1,584
Recognized Expert Top Contributor
Can I see the Table structure first.Then I might be able to help.
Or else go for a re-structuring you tables and Apps by your self.
Example: - From Products table list all the products to page(s) with the unique product_id
EX: 1001,1002,1003, 1004,....,n - Insert the selected products to orders table by sending the product_id to the Orders table
Ex: user select the product 1001 and 1004, then insert them to orders table. - Once you came to this stage.(update shopping cart)
User can Insert Number of Items and size for 1001 and 1004
You can put those size and Quantity in side the while loop and display the corresponding list menus for both selected products.
Ex:
1001 - size_list_menu - qty_list_menu
1004 - size_list_menu - qty_list_menu
[You can display the product Image/Name instead of Product_id to the User]
Once user select the size and Qty update them to Orders Table again.
So now for all the purchased item(s) you have.
ProductNumber
Size
Qty
That's it, Then proceed with your Payment gateway.
Can I see the Table structure first.Then I might be able to help.
Or else go for a re-structuring you tables and Apps by your self.
Example:- From Products table list all the products to page(s) with the unique product_id
EX: 1001,1002,1003, 1004,....,n - Insert the selected products to orders table by sending the product_id to the Orders table
Ex: user select the product 1001 and 1004, then insert them to orders table. - Once you came to this stage.(update shopping cart)
User can Insert Number of Items and size for 1001 and 1004 You can put those size and Quantity in side the while loop and display the corresponding list menus for both selected products.
Ex:
1001 - size_list_menu - qty_list_menu
1004 - size_list_menu - qty_list_menu
[You can display the product Image/Name instead of Product_id to the User]
Once user select the size and Qty update them to Orders Table again.
So now for all the purchased item(s) you have.
ProductNumber
Size
Qty
That's it, Then proceed with your Payment gateway.
i think i have the same concept as you when i am doing this, but my problem is how should i validate user's selection of their selected item's size and quantity as users may forget to choose some of them. my validation now is -
<?
-
ob_start();
-
session_start();
-
?>
-
<html>
-
<head>
-
<link rel="stylesheet" type="text/css" href="shop.css" /><div id="h">Ladies' Apparels</div>
-
<script language="JavaScript">
-
-
<!--
-
-
function validate_form ( )
-
{
-
valid = true;
-
alert (document.Lform.quantity.selectedIndex);
-
if ( document.Lform.quantity.selectedIndex == 0 )
-
{
-
alert ( "Please select your quantity!" );
-
Lform.quantity.focus();
-
valid = false;
-
}
-
else if ( document.Lform.size.selectedIndex == 0 )
-
{
-
alert ( "Please select your size!" );
-
Lform.size.focus();
-
valid = false;
-
}
-
return valid;
-
}
-
-
</script>
-
</head>
-
<body>
-
<?
-
ob_start();
-
session_start();
-
-
require("db.php");
-
-
mysql_connect(MACHINE, USER, '');
-
mysql_select_db(DBNAME);
-
-
-
$userid = $_SESSION['userid'];
-
-
$date=date("D j-M-Y G:i:s");
-
echo $date;
-
echo"<BR>";
-
-
foreach ($_POST as $key => $value) {
-
echo "key: ".$key.", value: ".$value."<br>";
-
$sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
-
mysql_query($sql);
-
}
-
$sql2="SELECT imageid FROM orders";
-
$result=mysql_query($sql2);
-
while($row = mysql_fetch_array($result)) {
-
echo "<br>";
-
$id=$row['imageid'];
-
$_SESSION['id1']=$id;
-
$sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
-
$ImageResult = mysql_query($sql3);
-
$ImageDetail = mysql_fetch_array($ImageResult);
-
echo "<tr>";
-
echo "<td>".$ImageDetail['title']."</td>";
-
echo "<td>".$ImageDetail['brand']."</td>";
-
echo "<td>".$ImageDetail['price']."</td>";
-
echo"<td>";
-
echo"
-
<select id='size' name='size' tabindex='11'>
-
<option value='0'>---</option>
-
<option value='1' >S</option>
-
<option value='2'>M</option>
-
<option value='3'>L</option>
-
<option value='4'>XL</option>
-
</select>
-
</td>";
-
//echo" ";
-
-
-
echo"
-
<td>
-
<select id='NO' name='quantity' tabindex='11'>
-
<option value='0'>---</option>
-
<option value='1' >1</option>
-
<option value='2'>2</option>
-
<option value='3'>3</option>
-
<option value='4'>4</option>
-
<option value='5'>5</option>
-
<option value='6'>6</option>
-
<option value='7'>7</option>
-
<option value='8'>8</option>
-
<option value='9'>9</option>
-
<option value='10'>10</option>
-
</select>
-
</td>";
-
?>
-
</body>
-
</html>
-
however, it seems does not work at all, i think because of the naming problem. as every item is using the name of 'quantity' and 'size', so the program don;t know which quantity and size choosen is belong to which item. so how should i sovle this? this is the main problem. thanks :)
PS. my product id is atom increment, the other fields are brand, price,descripti on,etc. in my orders table, i got product id as foreign key, userid as foreign key. the rest of field is time, quantity, size.
thank you very much for your kind help. this is a bit urgent as my project's deadline is very near. if possible, please reply me ASAP. thanks:)
ak1dnar 1,584
Recognized Expert Top Contributor
Since this is a shopping cart you can set some default size and Quantity for a selected item always.
Ex:
Qty always set to 1
Size set to S
For a Customer do we need to display 0 s or blanks for products, I dnt think so.Then no need of validation at all.
Still if you expecting validation just give me some times.
Thanks!
-Ajaxrand
Since this is a shopping cart you can set some default size and Quantity for a selected item always.
Ex:
Qty always set to 1
Size set to S
For a Customer do we need to display 0 s or blanks for products, I dnt think so.Then no need of validation at all.
Still if you expecting validation just give me some times.
Thanks!
-Ajaxrand
the default is all 1, but my supervisor don;t think it is practical in real life to let everyone just buy one and they should be able to select the size they wear. that is why i have to do the validation of size and quantity for each item they buy.
i have to insert their size and quanity for the respective item in database, so i have to know which size and quantity is belong to which item.
sure, i will wait for your kind reply. thanks. :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Sonic |
last post by:
I have an MDE file that is growing exponentially (from 3,900 KB to over
132,000 KB today). I am not saving data in this MDE, although I use a
mix of offline and SQL tables for Read Only querying. I also have many
forms and some reports and queries. Many people use this DB on a daily
basis and there is constantly someone in it, virtually every minute.
The DB tends to crash every couple of weeks. I am wondering if the
size of this...
|
by: Norbert Heidbüchel |
last post by:
Hi all,
I have read a lot of postings and web pages about drag and drop
and treeviews, but could not find an answer to my problem. Sorry, if I
missed something.
I am trying to drag and drop treenodes defined by myself and
don't understand, how to get the nodes data in the dragdrop event.
I'm not very experienced in .NET and for sure there is a simple solution.
I've written a short sample program, based on well known examples,
|
by: Stephen |
last post by:
Could someone please help me with some validation. I have to write code which
checks to see whether a dropdown list is populated with a value or a checkbox
is checked. I want the code to run on the on-click of a button.
My page has 1 dropdown list and two checkboxes. So I either want the user
to choose an item from the dropdownlist OR tick a checkbox(it doesn't matter
if they tick both checkboxes). I can't allow the user to fill in the...
|
by: Moe Sizlak |
last post by:
Hi There,
I am trying to return the value of a listbox control that is included as a
user control, I can return the name of the control but I can't access the
integer value of the selected item, what do I need to do in order to return
the "option value" of the control?
Moe
!--- returned value of the control
|
by: Jimbo |
last post by:
Hello,
I have a user request to build a form in an Access database where the user
can check off specific fields to pull in a query. For example, let's say I
have 10 fields in a table. The user wants to be able to check off anywhere
between 1 and all 10 fields in a form and have it return a select query with
just the fields that were checked off. There are multiple users, so not all
users will be checking off the same fields. Some...
| |
by: tania |
last post by:
i have this table in my database:
CREATE TABLE FILM(
F_ID INT(5) NOT NULL AUTO_INCREMENT,
F_TITLE VARCHAR(40) NOT NULL,
DIRECTOR_FNAME VARCHAR(20) NOT NULL,
DIRECTOR_LNAME VARCHAR(20) NOT NULL,
TYPE VARCHAR(30) NOT NULL,
DURATION TIME ,
YEAR_RELEASE YEAR NOT NULL,
DESCRIPTION TEXT,
|
by: goutam12345 |
last post by:
Hello experts,
Please help....
My checkboxes are not passing respective textboxes values to another page
My checkboxes are moving in a loop
<input type="checkbox" name="chkID" id="chkID" value="<?=$rowSubjectsx?>">
My text boxes are also moving in a loop
<input type="text" name="quantity" id="quan" size="3"/>
I want to show respective check boxes subjects and quantity to another page
Please help.......
|
by: =?Utf-8?B?UGF1bA==?= |
last post by:
Hallo,
I have a radiobuttonlist control that is added on a custom Web User Control.
This control has a property that exposes the SelectedIndex property of the
embedded radiobuttonlist.
When running this in IE, behaviour is as I would expect it. If I select an
item and do a postback, the page remembers my selection when reloading, and
the SelectedIndex property of my control returns the correct value.
|
by: kurtzky |
last post by:
i created a form that should function as follows:
i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a different item no in it..then, these records will be saved in a temporary datatable (which i made in a separate class, the name is WBASKET)...The item nos of these records will be displayed in a combobox, say item1, item2, etc..
then,i have a datagrid...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |