Jump to content

need drastic help with my code please.


redarrow

Recommended Posts

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.
Link to comment
Share on other sites

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

[code]<?
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>
<?
}
?>[/code]

Maybe a better way but works for me

Ray
Link to comment
Share on other sites

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

[code]// 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';
}[/code]

Ray
Link to comment
Share on other sites

[code]<form metod="GET" action="<?=$_SERVER['PHP_SELF']?>">[/code]
Should be as follows:
[code]<form method="GET" action="<?=$_SERVER['PHP_SELF']?>">[/code]
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:

[code]
// Make database connection below

$id = $_GET['id'];

$date1 = $_GET['date1']; // retrieve data from $_GET array
$date2 ... etc
// Insert query
[/code]
Link to comment
Share on other sites

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.

[code]
<?
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>
<?
}
?>
[/code]
Link to comment
Share on other sites

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
[code]<?
$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>[/code]

Here is the query page called query.php
[code]<?
$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';
}[/code]

Think that is what you are looking for

Ray
Link to comment
Share on other sites

Just a quick note. You ask how to modify something for when register_globals is ON. The answer is [b]DON'T[/b]. 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.
Link to comment
Share on other sites

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






[code]
<?
$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>";
?>
[/code]
Link to comment
Share on other sites

[!--quoteo(post=370662:date=May 2 2006, 06:56 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ May 2 2006, 06:56 PM) [snapback]370662[/snapback][/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--]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.