Jump to content


Photo

need drastic help with my code please.


  • Please log in to reply
12 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 May 2006 - 06:27 PM

Can you please help me.

What is the best way to get a user to give there information on dates they can not do somethink.

I need four select date boxs or insert boxs but how lol advance thank you.


example

please select a date to tell us what date you can not work but i need it four times for the users do i use select boxs i tried no luck,so do i use a input box what going mad.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 01 May 2006 - 07:18 PM

i used what you had in last post but here is what I cam up with

<?
if(isset($_GET['submit'])){
$months = array();
$days = array();
$years = array();
foreach($_GET as $key => $value){
if (substr($key, 0, 5) == 'month'){
$months[]=$value;
}
if (substr($key, 0, 3) == 'day'){
$days[].=$value;
}
if (substr($key, 0, 4) == 'year'){
$years[]=$value;
}
}
$date1 = ''.$years[0].'-'.$months[0].'-'.$days[0].'';
$date2 = ''.$years[1].'-'.$months[1].'-'.$days[1].'';
$date3 = ''.$years[2].'-'.$months[2].'-'.$days[2].'';
$date4 = ''.$years[3].'-'.$months[3].'-'.$days[3].'';
echo "$date1<br>";
echo "$date2<br>";
echo "$date3<br>";
echo "$date4<br>";

} else {
$day=date("d");
$month=date("m");
$year=date("Y");
?>

<form metod="GET" action="<?=$_SERVER['PHP_SELF']?>">
<?
for ($i=1;$i<5;$i++){
?>
Day<?=$i?>:
<select name="day<?=$i?>">
<?
for($days=01;$days<32;$days++){
?>
<option value="<?=$days?>">Day <?=$days?></option>';
<?
}
?>
</select>
<select name="month<?=$i?>">
<?
for ($months=1;$months<13;$months++){
?>
<option value="<?=$months?>" <? if($months == $month){ echo "selected";} ?>>Month <?=$months?></option>';
<?
}
?>
</select>
<select name="year<?=$i?>">
<?
for($years=2006; $years<2010;$years++){
?>
<option value="<?=$years?>" <? if($years == $year){ echo "selected";}?>>Year <?=$years?></option>
<?
}
?>
</select>
<br />
<?
}
?>
<br>
<input type="submit" name="submit" value="Submit Date">
</form>
<?
}
?>

Maybe a better way but works for me

Ray

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 May 2006 - 07:29 PM

That well nice bit of codding, know how do i post all them dates into the database thank you so much.

I use 4 filed colums

date1
date2
date3
date4

Hope you can help cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 01 May 2006 - 07:35 PM

Is there anything else you want to insert at the same time, like id ect If you give me the field names and table name I will take care of it.

here is one example. I am assuming you are inserting this along with an id to identify who these dates belong to

// Make database connection below

$id = $_GET['id'];
// Insert query
$sql = "INSERT INTO table SET
        id = '".$id."',
        date1 = '".$date1."',
        date2 = '".$date2."',
        date3 = '".$date3."',
        date4 = '".$date4."'";
// Run query
$res = mysql_query($sql);
// Check if errors in query and echo out results
if(!$res){
print MySql ERROR:'.die(mysql_error()).'';
} else {
print 'Date\'s entered into table';
}

Ray

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 May 2006 - 02:58 PM

Ray if i try to echo out the dates with:

$date1;
$date2;
$date3;
$date4;


Onto a page to cheek the data is in the varable i get nothink any idears please cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 02 May 2006 - 03:39 PM

<form metod="GET" action="<?=$_SERVER['PHP_SELF']?>">
Should be as follows:
<form method="GET" action="<?=$_SERVER['PHP_SELF']?>">
That'll work if php short tags are enabled, otherwise change <?= to <?php echo

Then how are the form values retrieved? Code as if register_globals are OFF and get them thus:

// Make database connection below

$id = $_GET['id'];

$date1 = $_GET['date1']; // retrieve data from $_GET array
$date2 ... etc
// Insert query

Legend has it that reading the manual never killed anyone.
My site

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 May 2006 - 05:30 PM

How to do the same andy, with register_globals are on and using post not $_GET ok cheers.

I need to convert the below code to work via post so it can post the date varables to a test page to print the date varables out.

once this has be done, I then need to add the code to a form that is in use but need to add the date feature of this code to insert dates to the database.

On the form i got to add this code below but i am using post can you help please cheers.

ps. the code below does not need the form part or the if isset part as its going to be added to an existing form.

I got to get it to work with post or have a diffrent example to get 4 pull down boxs of dates by post, And also have the abilty to add to an existing form.

If there is another way easer to get four pull down box's for dates using post and not get, then please show me cheers.

<?
if(isset($_GET['submit'])){
$months = array();
$days = array();
$years = array();
foreach($_GET as $key => $value){
if (substr($key, 0, 5) == 'month'){
$months[]=$value;
}
if (substr($key, 0, 3) == 'day'){
$days[].=$value;
}
if (substr($key, 0, 4) == 'year'){
$years[]=$value;
}
}
$date1 = ''.$years[0].'-'.$months[0].'-'.$days[0].'';
$date2 = ''.$years[1].'-'.$months[1].'-'.$days[1].'';
$date3 = ''.$years[2].'-'.$months[2].'-'.$days[2].'';
$date4 = ''.$years[3].'-'.$months[3].'-'.$days[3].'';
echo "$date1<br>";
echo "$date2<br>";
echo "$date3<br>";
echo "$date4<br>";

} else {
$day=date("d");
$month=date("m");
$year=date("Y");
?>

<form metod="GET" action="<?=$_SERVER['PHP_SELF']?>">
<?
for ($i=1;$i<5;$i++){
?>
Day<?=$i?>:
<select name="day<?=$i?>">
<?
for($days=01;$days<32;$days++){
?>
<option value="<?=$days?>">Day <?=$days?></option>';
<?
}
?>
</select>
<select name="month<?=$i?>">
<?
for ($months=1;$months<13;$months++){
?>
<option value="<?=$months?>" <? if($months == $month){ echo "selected";} ?>>Month <?=$months?></option>';
<?
}
?>
</select>
<select name="year<?=$i?>">
<?
for($years=2006; $years<2010;$years++){
?>
<option value="<?=$years?>" <? if($years == $year){ echo "selected";}?>>Year <?=$years?></option>
<?
}
?>
</select>
<br />
<?
}
?>
<br>
<input type="submit" name="submit" value="Submit Date">
</form>
<?
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 02 May 2006 - 06:13 PM

Well I went with the assumption you would use the same page for the insert query. If you are using a new page here is the code seperated.

here is the form page called form.php
<?
$day=date("d");
$month=date("m");
$year=date("Y");
?>

<form metod="POST" action="query.php">
<?
for ($i=1;$i<5;$i++){
?>
Day<?=$i?>:
<select name="day<?=$i?>">
<?
for($days=01;$days<32;$days++){
?>
<option value="<?=$days?>">Day <?=$days?></option>';
<?
}
?>
</select>
<select name="month<?=$i?>">
<?
for ($months=1;$months<13;$months++){
?>
<option value="<?=$months?>" <? if($months == $month){ echo "selected";} ?>>Month <?=$months?></option>';
<?
}
?>
</select>
<select name="year<?=$i?>">
<?
for($years=2006; $years<2010;$years++){
?>
<option value="<?=$years?>" <? if($years == $year){ echo "selected";}?>>Year <?=$years?></option>
<?
}
?>
</select>
<br />
<?
}
?>
<br>
<input type="submit" name="submit" value="Submit Date">
</form>

Here is the query page called query.php
<?
$months = array();
$days = array();
$years = array();
foreach($_POST as $key => $value){
if (substr($key, 0, 5) == 'month'){
$months[]=$value;
}
if (substr($key, 0, 3) == 'day'){
$days[].=$value;
}
if (substr($key, 0, 4) == 'year'){
$years[]=$value;
}
}
$dates1 = ''.$years[0].'-'.$months[0].'-'.$days[0].'';
$dates2 = ''.$years[1].'-'.$months[1].'-'.$days[1].'';
$dates3 = ''.$years[2].'-'.$months[2].'-'.$days[2].'';
$dates4 = ''.$years[3].'-'.$months[3].'-'.$days[3].'';
echo "$dates1<br>";
echo "$dates2<br>";
echo "$dates3<br>";
echo "$dates4<br>";
require('config.php');
include('includes/mysql.php');
$sql = "INSERT INTO table SET
        name_id = '$id',
        date1 = '".$dates1."',
        date2 = '".$dates2."',
        date3 = '".$dates3."',
        date4 = '".$dates4."'";
$res = mysql_query($sql);
if(!$res){
print 'Error with mysql ERROR:'.die(mysql_error()).'';
} else {
print 'date entered into table';
}

Think that is what you are looking for

Ray

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 02 May 2006 - 06:23 PM

Just a quick note. You ask how to modify something for when register_globals is ON. The answer is DON'T. If you code as if register_globals is set to OFF it'll work regardless of the setting; if you code as if register_globals is set to ON and it isn't, you'll have failures whenever that isn't how it's set. Code safely - assume register_globals is OFF.
Legend has it that reading the manual never killed anyone.
My site

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 May 2006 - 06:29 PM

Thanks ray i put this below code on a test.php page but i get no echoed results is there any reason for that.






<?
$months = array();
$days = array();
$years = array();
foreach($_POST as $key => $value){
if (substr($key, 0, 5) == 'month'){
$months[]=$value;
}
if (substr($key, 0, 3) == 'day'){
$days[].=$value;
}
if (substr($key, 0, 4) == 'year'){
$years[]=$value;
}
}
$dates1 = ''.$years[0].'-'.$months[0].'-'.$days[0].'';
$dates2 = ''.$years[1].'-'.$months[1].'-'.$days[1].'';
$dates3 = ''.$years[2].'-'.$months[2].'-'.$days[2].'';
$dates4 = ''.$years[3].'-'.$months[3].'-'.$days[3].'';
echo "$date1<br>";
echo "$date2<br>";
echo "$date3<br>";
echo "$date4<br>";
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 02 May 2006 - 06:33 PM

The page itself will not work without the form before it.
I have modified my post above and gave names to the pages.

Try it

Ray

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 May 2006 - 06:56 PM

ray i am using two form posts in the code one for my form varables and another for your date varables and one submit button for all it all works but is that correct.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 May 2006 - 12:16 PM

[!--quoteo(post=370662:date=May 2 2006, 06:56 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ May 2 2006, 06:56 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
ray i am using two form posts in the code one for my form varables and another for your date varables and one submit button for all it all works but is that correct.
[/quote]


[!--sizeo:6--][span style=\"font-size:24pt;line-height:100%\"][!--/sizeo--]solved[!--sizec--][/span][!--/sizec--]
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users