Web Design Forum: can you update a sql table continuously? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

can you update a sql table continuously? Rate Topic: -----

#1 User is offline   dan... 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 28-January 10
  • Reputation: 0

Posted 12 March 2010 - 11:35 AM

Hi is it possible to update a sql table on a continues basis?

i.e. choose a selection on a drop down menu, then choose another selection from another drop down menu on another page and add it to the same line, so that after the user goes through all the options, the sql database will have one single id number with all the required information for me to call upon later at the checkout?

i can then use that id number as an order number keeping track of everything, i'm sure this is not the correct way of doing thing but i'm learning and it seems to do the job so far.

Sorry, here is the code i am using

<?php

error_reporting (0) ;

$connect = mysql_connect ("*****","*******","**************") or die(mysql_error());
mysql_select_db("test") or die (mysql_error());
mysql_query("INSERT INTO dk VALUES ('','$_POST[frame_type]','$_POST[style]')");

echo $_POST['name'];
echo $_POST['dob'];
echo $_POST['gender'];
echo $_POST['style'];



?>
0

#2 User is offline   Milli05 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 64
  • Joined: 12-April 09
  • Reputation: 3
  • Gender:Female
  • Location:London
  • Experience:Beginner
  • Area of Expertise:Web Designer

Posted 12 March 2010 - 12:48 PM

View Postdan..., on 12 March 2010 - 11:35 AM, said:

Hi is it possible to update a sql table on a continues basis?

i.e. choose a selection on a drop down menu, then choose another selection from another drop down menu on another page and add it to the same line, so that after the user goes through all the options, the sql database will have one single id number with all the required information for me to call upon later at the checkout?

i can then use that id number as an order number keeping track of everything, i'm sure this is not the correct way of doing thing but i'm learning and it seems to do the job so far.

Sorry, here is the code i am using

<?php

error_reporting (0) ;

$connect = mysql_connect ("*****","*******","**************") or die(mysql_error());
mysql_select_db("test") or die (mysql_error());
mysql_query("INSERT INTO dk VALUES ('','$_POST[frame_type]','$_POST[style]')");

echo $_POST['name'];
echo $_POST['dob'];
echo $_POST['gender'];
echo $_POST['style'];



?>


I am not sure if I have got it right: so you would like to add pieces of data to your "id" field in the sql table.

If the field is the primary key and it is set to auto increment, you will not be able to change that. I recommend to set up another "id" field (eg.the primary can be called "ID" the new "id" or something like that.

Then you enter info into it for the first time.
When you want to add info to it for the second time, you get the info that is already there , attach the new info and insert it in the table.

Here is a code:(i have not tested it)
//when you enter info for the first time
$connect = mysql_connect ("*****","*******","**************") or die(mysql_error());
mysql_select_db("test") or die (mysql_error());
mysql_query("INSERT INTO dk VALUES ('',".$_POST['id']."'".$_POST['frame_type']."','".$_POST['style']."')"); 

//adding info to the id field

$query="select * from dk where id=".$_POST['id'];
$result=mysql_query($query,$connect);
$id=mysql_fetch_assoc($result);

$new_id="$id['id']".$_POST['id'];
//then you enter the $new_id into the table

$update_query="update dk set id='$new_id' where id=".$id['id'];
$mysql_query($update_query,$connect);



Also be careful with the $_POST['frame_type'] data in the qsl query like here:('','$_POST[frame_type]','$_POST[style]')")
Type ('','".$_POST['frame_type']."' if the data is a string
type ('',".$_POST['frame_type']." if the data numeric.

I hope it helped.
0

#3 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 12 March 2010 - 12:54 PM

Hi Dan,

Is it absolutely necessary to post to the DB each time, can you not rather pass the values across the pages and at the final page post all the values at once, a very important part of optimizing your site is to minimize calls to the DB.

scenario 1 = sensitive data want to post and dispose ASAP,
- you can post to the DB on each page and pass the ID across to each page.

scenario 2 = sensitive data don't mind posting after the last selection
- use session variables to store the variables and only after the last page update the DB

scenario 3 = insensitive data
- pass the options along with the URL and update the DB after the last page, this is nice if it is something like a car dealership because after selecting Ford I can bookmark the page with all fords or I can create a link to www.mypage.com/cars.php?model=ford
0

#4 User is offline   dan... 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 28-January 10
  • Reputation: 0

Posted 12 March 2010 - 01:27 PM

View PostGeeks, on 12 March 2010 - 12:54 PM, said:

Hi Dan,

Is it absolutely necessary to post to the DB each time, can you not rather pass the values across the pages and at the final page post all the values at once, a very important part of optimizing your site is to minimize calls to the DB.

scenario 1 = sensitive data want to post and dispose ASAP,
- you can post to the DB on each page and pass the ID across to each page.

scenario 2 = sensitive data don't mind posting after the last selection
- use session variables to store the variables and only after the last page update the DB

scenario 3 = insensitive data
- pass the options along with the URL and update the DB after the last page, this is nice if it is something like a car dealership because after selecting Ford I can bookmark the page with all fords or I can create a link to www.mypage.com/cars.php?model=ford


Scenario 3 would be perfect but i would not know where to start, can you help me out at all?

oh and to milli05, i want to add it to the line so that when the first box add the frame type is assigns an id on a line, i would like to add to the line apposed to creating a new line and new id?
0

#5 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 12 March 2010 - 02:08 PM

can you send a link to the page in question?

the basic idea would be to use a form with method set to get (not post) and on each page set the action to the current url that way you will keep the passed variables.

something like :

<?php 
//get current url 
$page = $_SERVER["REQUEST_URI"];
?>
<form method="get" action="<?php echo $page; ?>">
 <select name="unique_name_here">
	<option value="value_1">text</option>
	<option value="value_2">text</option>
	<option value="value_3">text</option>
 </select>
</form>


If the select name ("unique_name") is different on each page then at the last page you should see all your variables in the URL.

then use $_GET["unique_name"]; in your update to get each variable.

this has not been tested but it should all work (I Hope :()
0

#6 User is offline   dan... 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 28-January 10
  • Reputation: 0

Posted 12 March 2010 - 02:39 PM

View PostGeeks, on 12 March 2010 - 02:08 PM, said:

can you send a link to the page in question?

the basic idea would be to use a form with method set to get (not post) and on each page set the action to the current url that way you will keep the passed variables.

something like :

<?php 
//get current url 
$page = $_SERVER["REQUEST_URI"];
?>
<form method="get" action="<?php echo $page; ?>">
 <select name="unique_name_here">
	<option value="value_1">text</option>
	<option value="value_2">text</option>
	<option value="value_3">text</option>
 </select>
</form>


If the select name ("unique_name") is different on each page then at the last page you should see all your variables in the URL.

then use $_GET["unique_name"]; in your update to get each variable.

this has not been tested but it should all work (I Hope :()


I'm new and i still don't get the code, i'm trying to upload the page to a domain for you to look at but it keeps downloading the php when you select it, any ideas?
0

#7 User is offline   dan... 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 28-January 10
  • Reputation: 0

Posted 12 March 2010 - 03:14 PM

View Postdan..., on 12 March 2010 - 02:39 PM, said:

I'm new and i still don't get the code, i'm trying to upload the page to a domain for you to look at but it keeps downloading the php when you select it, any ideas?


I've put it on another domain and now it works, try www.digitalkandi.com but when you click the submit button below the drop down list, it doesn't take you to the next page, just the php file?

it should be taking you to: style.html
0

#8 User is offline   dan... 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 28-January 10
  • Reputation: 0

Posted 12 March 2010 - 08:07 PM

View Postdan..., on 12 March 2010 - 03:14 PM, said:

I've put it on another domain and now it works, try www.digitalkandi.com but when you click the submit button below the drop down list, it doesn't take you to the next page, just the php file?

it should be taking you to: style.html


ok, i've managed to get the code working and it takes me to another page but after 2 selections, the first variable disappears from the url, is that normal?

here is the code:

<?php
//get current url
$page = $_SERVER["REQUEST_URI"];
?>
<form method="get" action='acrylic_image_styles_new.php'>
<select name="frame">
<option value="Acrylic">Acrylic</option>
<option value="Block Mounted">Block Mounted</option>
<option value="Canvas">Canvas</option>
<option value="Clipped">Clipped</option>
<option value="Framed">Framed</option>
</select><br /> <br />
<form method="link" action="http://www.paypal.com"><input type="submit" class="submit_next" onclick="MM_validateForm('email','','RisEmail');return document.MM_returnValue" value="" /></form>
</form>


************************************************************
Also, i have a script that allows me to change the image on selection, but when i add it i can't get both working together, here's the code: pay particular attention to
<select id="selection" name="selection" method='post' action='dk.php'>


<script type="text/javascript">
window.onload=function()
{
var caption=['Default Image Caption',
'Our one piece frame selection comes in all sizes and frame styles, and ideal choice for any picture, please beaware that image cropping may occure',
'This lovely 3 piece is a fine choice to break up that wide image, the dimensions are 40" x 30", please beaware that image cropping may occure ',
'Caption3',
'Caption4',
'Caption5',
'Caption6',
'Caption7',], // This will be your images caption
bp='my images/Thumbnails/', //base url of your images
imgnum=14, //Number of your images. This should match on your comboboxes options.
thumb=document.getElementById('thumb'), //id of your image that will be changing
description=document.getElementById('caption'), //id of your caption
combobox=document.getElementById('selection'); // id of your combobox.

combobox.onchange=function()
{
thumb.src=bp+'supports'+this.value+'.jpg';
description.innerHTML=caption[this.value];
}
}
</script>
</head>
<div id="customise_wrapper">
<div id="customise"><br />
<div id="customise_stage1"><img src="my images/Thumbnails/lets1_2.jpg" width="120" height="70" /></div>
<div id="customise_stage2"><img src="my images/Thumbnails/lets2_3.jpg" width="120" height="70" /></div>
<div id="customise_stage3"></div>
<div id="customise_stage4"></div>
<div id="customise_stage5"></div>
<div id="customise_text"><br />
Please select the type of frame that you would like your image placed onto</div>
<div id="customise_content">
<div id="customise_menu1">Frame Types<br/>
<br/>
<?php
//get current url
$page = $_SERVER["REQUEST_URI"];
?>
<select id="selection" name="selection" method='post' action='dk.php'>
<select name="frame">
<option value="1">Acrylic</option>
<option value="2">Block Mounted</option>
<option value="3">Canvas</option>
<option value="4">Clipped</option>
<option value="5">Framed</option>
</select><br /> <br />
<form method="link" action="http://www.paypal.com"><input type="submit" class="submit_next" onclick="MM_validateForm('email','','RisEmail');return document.MM_returnValue" value="" /></form>
</form>
0

#9 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 13 March 2010 - 11:37 AM

start with a separate page completely just to get the concept
Tested, it works better with hidden form fields
------------------------------------------------------------------------------

PAGE_1.php
----------------
<html><head></head><body>
<form method="get" action="PAGE_2.php">
 <select name="material">
 <option value="Acrylic">Acrylic</option> 
 <option value="Block Mounted">Block Mounted</option> 
 <option value="Canvas">Canvas</option> 
 <option value="Clipped">Clipped</option> 
 <option value="Framed">Framed</option> 
 </select>
 <input type="submit" value="next page" />
</form>
</body></html>


PAGE_2.php
----------------
<html><head></head><body>
<html><head></head><body>
<form method="get" action="PAGE_3.php?">
<input type="hidden" name="material" value="<?php echo $_GET['material']; ?>">
 <select name="color">
 	<option value="blue">blue</option>
 	<option value="red">red</option>
 	<option value="yellow">yellow</option>
 </select>
 <input type="submit" value="next page" />
</form>
</body></html>


PAGE_3.php
----------------
 <html><head></head><body>
 <?php 
echo "material = " . $_GET['material'];
echo "<br /><br />color = " . $_GET['color'];
?>
 </body></html>

1

#10 User is offline   dan... 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 28-January 10
  • Reputation: 0

Posted 13 March 2010 - 01:07 PM

View PostGeeks, on 13 March 2010 - 11:37 AM, said:

start with a separate page completely just to get the concept
Tested, it works better with hidden form fields
------------------------------------------------------------------------------

PAGE_1.php
----------------
<html><head></head><body>
<form method="get" action="PAGE_2.php">
 <select name="material">
 <option value="Acrylic">Acrylic</option> 
 <option value="Block Mounted">Block Mounted</option> 
 <option value="Canvas">Canvas</option> 
 <option value="Clipped">Clipped</option> 
 <option value="Framed">Framed</option> 
 </select>
 <input type="submit" value="next page" />
</form>
</body></html>


PAGE_2.php
----------------
<html><head></head><body>
<html><head></head><body>
<form method="get" action="PAGE_3.php?">
<input type="hidden" name="material" value="<?php echo $_GET['material']; ?>">
 <select name="color">
 	<option value="blue">blue</option>
 	<option value="red">red</option>
 	<option value="yellow">yellow</option>
 </select>
 <input type="submit" value="next page" />
</form>
</body></html>


PAGE_3.php
----------------
 <html><head></head><body>
 <?php 
echo "material = " . $_GET['material'];
echo "<br /><br />color = " . $_GET['color'];
?>
 </body></html>



Thats quality, thanks, how do i now adjust it so that if i click acrylic, it will only take me to acrylic options, i.e. if i click acrylic, it only brings up yellow?
0

#11 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 13 March 2010 - 06:31 PM

try something like :
not tested
<html><head></head><body>
<html><head></head><body>
<form method="get" action="PAGE_3.php?">
<input type="hidden" name="material" value="<?php if(isset($_GET["category"])) echo $_GET['material']; ?>">
<?php
if(isset($_GET["category"]))
{
 if ($_GET["category"] == "accrylic")
 {
	echo '<option value="yellow">yellow</option>';
 }
 else if ($_GET["category"] == "canvas")
 {
	echo '<option value="blue" />'blue</option>;
 }
}
?>
</select>
 <input type="submit" value="next page" />
</form>
</body></html>

0

#12 User is offline   dan... 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 54
  • Joined: 28-January 10
  • Reputation: 0

Posted 13 March 2010 - 08:59 PM

View PostGeeks, on 13 March 2010 - 06:31 PM, said:

try something like :
not tested
<html><head></head><body>
<html><head></head><body>
<form method="get" action="PAGE_3.php?">
<input type="hidden" name="material" value="<?php if(isset($_GET["category"])) echo $_GET['material']; ?>">
<?php
if(isset($_GET["category"]))
{
 if ($_GET["category"] == "accrylic")
 {
	echo '<option value="yellow">yellow</option>';
 }
 else if ($_GET["category"] == "canvas")
 {
	echo '<option value="blue" />'blue</option>;
 }
}
?>
</select>
 <input type="submit" value="next page" />
</form>
</body></html>



Looks good but i can't get the code to work, i'll have a play about with it and see if i can, in the meantime, if you can figure it out before me, i'll keep checking back as it takes me ages todo stuff like this.
0

#13 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 14 March 2010 - 11:29 AM

PAGE_1.php
<html><head></head><body>
<form method="get" action="PAGE_2.php">
 <select name="material">
 	<option value="Acrylic">Acrylic</option>
 	<option value="Block Mounted">Block Mounted</option>
 	<option value="Canvas">Canvas</option>
 	<option value="Clipped">Clipped</option>
 	<option value="Framed">Framed</option>
 </select>
 <input type="submit" value="next page" />
</form>
</body></html>

PAGE_2.php
<?php if(!isset($_GET['material'])){ header( 'Location: PAGE_1.php' ) ; }?>
<html><head></head><body>
<form method="get" action="PAGE_3.php?">
<input type="hidden" name="material" value="<?php echo $_GET['material']; ?>">
 <select name="color">
	<?php
 	if($_GET['material'] == "Acrylic")
 	{
 	echo '<option value="blue">blue</option>
 	<option value="red">red</option>';
 	}
 	else if($_GET['material'] == "Block Mounted")
 	{
 	echo '<option value="green">green</option>
 	<option value="orange">orange</option>
 	<option value="red">red</option>';
 	}
 	else if($_GET['material'] == "Canvas")
 	{
 	echo '<option value="voilet">violet</option>
 	<option value="red">red</option>
 	<option value="pink">pink</option>
 	<option value="orange">orange</option>';
 	} 
 	else if($_GET['material'] == "Clipped")
 	{
 	echo '<option value="purple">purple</option>
 	<option value="indigo">indigo</option>
 	<option value="red">red</option>
 	<option value="black">black</option>
 	<option value="brown">brown</option>
 	<option value="orange">orange</option>';
 	} 	
 	else if($_GET['material'] == "Framed")
 	{
 	echo '<option value="brown">brown</option>
 	<option value="black">black</option>';
 	}
	?>
 </select>
 <input type="submit" value="next page" />
</form>
</body></html>

PAGE_3.php
<html><head></head><body>
<?php
if(isset($_GET['material']))
{
 echo "material = " . $_GET['material'];
}
if(isset($_GET['color']))
{
 echo "<br /><br />color = " . $_GET['color'];
}
?>
</body></html>

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users