Jump to content

leetstar

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

leetstar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [code] <?php //function dbAdd function dbAdd($home,$m,$d,$y){ $query = "INSERT INTO year_$y (house, date, month) VALUES('$home', '$d', '$m')"; mysql_query($query) or die(mysql_error()); echo "Operation successfull! "; } ?> [/code] I was clsoing the SQL connection, thanks.
  2. Here's the code for add.php: [code] <?php //includes include("config.php"); //uses addional vars grabbed from the form, such as and $date $month = $_POST['select_month']; $year = $_POST['select_year']; $villa = $_POST['select_villa']; //converts date $day = date("z", mktime(0, 0, 0, $month, $date1, $year)) + 1; $day2 = date("z", mktime(0, 0, 0, $month, $date2, $year)) + 1; echo $day; echo ' and '; echo $day2; echo '</p>'; //if statement, check dates $difference = $day2 - $day; if ($difference == 0){ echo "Difference is one, difference is : "; echo $difference; die; } elseif ($difference > 10){ echo "Difference is greater then 10, difference is : "; echo $difference; die; } elseif ($difference < 1){ echo "Difference is smaller then 1, difference is : "; echo $difference; die; } else { echo "Here are your days : "; echo "</p>"; } $dayum = range($day, $day2); for($i = $day; $i < $day2; ++$i) { ${'d' . $i } = $dayum[$i]; } if ($dayum[0] != '') { dbAdd($villa,$month,$dayum[0],$year); echo "Day 1 contains the value : "; echo $dayum[0]; echo "</p>"; } else { echo "Day 1 is empty."; echo "</p>"; } if ($dayum[1] != '') { dbAdd($villa,$month,$dayum[1],$year); echo "Day 2 contains the value : "; echo $dayum[1]; echo "</p>"; } else { echo "Day 2 is empty."; echo "</p>"; }   if ($dayum[2] != '') { dbAdd($villa,$month,$dayum[2],$year); echo "Day 3 contains the value : "; echo $dayum[2]; echo "</p>"; } else { echo "Day 3 is empty."; echo "</p>"; }    if ($dayum[3] != '') { dbAdd($villa,$month,$dayum[3],$year); echo "Day 4 contains the value : "; echo $dayum[3]; echo "</p>"; } else { echo "Day 4 is empty."; echo "</p>"; }     if ($dayum[4] != '') { dbAdd($villa,$month,$dayum[4],$year); echo "Day 5 contains the value : "; echo $dayum[4]; echo "</p>"; } else { echo "Day 5 is empty."; echo "</p>"; } if ($dayum[5] != '') { dbAdd($villa,$month,$dayum[5],$year); echo "Day 6 contains the value : "; echo $dayum[5]; echo "</p>"; } else { echo "Day 6 is empty."; echo "</p>"; }   if ($dayum[6] != '') { dbAdd($villa,$month,$dayum[6],$year); echo "Day 7 contains the value : "; echo $dayum[6]; echo "</p>"; } else { echo "Day 7 is empty."; echo "</p>"; }    if ($dayum[7] != '') { dbAdd($villa,$month,$dayum[7],$year); echo "Day 8 contains the value : "; echo $dayum[7]; echo "</p>"; } else { echo "Day 8 is empty."; echo "</p>"; }     if ($dayum[8] != '') { dbAdd($villa,$month,$dayum[8],$year); echo "Day 9 contains the value : "; echo $dayum[8]; echo "</p>"; } else { echo "Day 9 is empty."; echo "</p>"; } if ($dayum[9] != '') { dbAdd($villa,$month,$dayum[9],$year); echo "Day 10 contains the value : "; echo $dayum[9]; echo "</p>"; } else { echo "Day 10 is empty."; echo "</p>"; } ?> [/code] Here's the code for config.php: [code] <?php //configuration file, modify variables accordingly $dbhost = "xxx";                            //database host, possibly 'localhost' $dbname = "xxx";                           //the name of the database to write to $dbuser = "xxx";                             //the username to login to the database $dbpass = "xxx";                            //the password to login to the database //--------------------------------do not edit below this line------------------------------------// //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); //function dateCheck function dateCheck($month,$date,$year){ $day = date("z", mktime(0, 0, 0, $month, $date, $year)) + 1; $checkdate = mysql_query("SELECT date FROM year_$year WHERE date='$day'"); $date_exist = mysql_num_rows($checkdate); if($date_exist > 0){     echo "<font color='#FF0000'>$date</font>"; } else { echo $date; } } //******************************************************************************************************** //*                                                                                                      * //* Be sure to modify this function so that it checks if the date is in the database before writting it. * //*                                                                                                      * //******************************************************************************************************** //function dbAdd function dbAdd($home,$m,$d,$y){ $query = "INSERT INTO year_$y (house, date, month) VALUES('$home', '$d', '$m')"; mysql_query($query) or die(mysql_error()); mysql_close(); echo "Operation successfull! "; } ?> [/code] This is what the script returned when I put day as 2 and day2 as 5 : [code] 2 and 5 Here are your days : Operation successfull! Day 1 contains the value : 2 Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/.bafftub/jeffdunn/destroi.com/tanamera/config.php on line 30 Warning: mysql_query(): A link to the server could not be established in /home/.bafftub/jeffdunn/destroi.com/tanamera/config.php on line 30 Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) [/code] The function in question in 'function dbAdd' What's happening is it's only parsing through the first if statement. I've tested the script without the dbAdd function and it works perfectly, but when I incorporate the function, it only does the first line. I wish I knew why. Some of the comments are directed towards me as reminders, ignore them. Please help, Jeff
  3. no luck :( I moved around the code abit, I decided to post the entire code so you guys can have a better look: [code] <? //includes include("config.php"); //uses addional vars grabbed from the form, such as and $date $month = $_POST['select_month']; $year = $_POST['select_year']; $villa = $_POST['select_villa']; //converts date $day = date("z", mktime(0, 0, 0, $month, $date, $year)) + 1; $day2 = date("z", mktime(0, 0, 0, $month, $date2, $year)) + 1; //add date to db $difference = $day2 - day; if ($difference = 1){ dbAdd($villa,$month,$day,$year); } elseif ($difference > 10){ echo "Sorry, you can only book off 10 days at a time."; exit; } elseif ($difference < 10){ echo "Sorry, the 'date to' field must be bigger then the 'date' filed."; exit; }elseif ($difference > 1){ $dayum = range($day, $day2); for($i = $day; $i < $day2; ++$i) { ${'d' . $i } = $dayum[$i]; for ($i=0;$i<10;$i++)     if ($dayum[$i] != '') dbAdd($villa,$month,$dayum[$i],$year);     else echo '$dayum[' . $i . '] is empty<br>'; } } else { echo "wtf"; } //echo success echo "Successful!"; ?> [/code]
  4. [code] $dayum = range($day, $day2); for($i = $day; $i < $day2; ++$i) { ${'d' . $i } = $dayum[$i]; } if ($dayum[0] != '') { dbAdd($villa,$month,$dayum[0],$year); } //day 1 if ($dayum[1] != '') { dbAdd($villa,$month,$dayum[1],$year); } //day 2 if ($dayum[2] != '') { dbAdd($villa,$month,$dayum[2],$year); } //day 3 if ($dayum[3] != '') { dbAdd($villa,$month,$dayum[3],$year); } //day 4 if ($dayum[4] != '') { dbAdd($villa,$month,$dayum[4],$year); } //day 5 if ($dayum[5] != '') { dbAdd($villa,$month,$dayum[5],$year); } //day 6 if ($dayum[6] != '') { dbAdd($villa,$month,$dayum[6],$year); } //day 7 if ($dayum[7] != '') { dbAdd($villa,$month,$dayum[7],$year); } //day 8 if ($dayum[8] != '') { dbAdd($villa,$month,$dayum[8],$year); } //day 9 if ($dayum[9] != '') { dbAdd($villa,$month,$dayum[9],$year); } //day 10 } [/code] Still, the code only writes the value assigned at position 0 of dayum. :( Jeff.
  5. It was originaly set to an if, but I`ll try again and post back. Thanks.
  6. [code] $dayum = range($day, $day2); for($i = $day; $i < $day2; ++$i) { ${'d' . $i } = $dayum[$i]; } if ($dayum[0] != '') { dbAdd($villa,$month,$dayum[0],$year); }     //day 1 elseif ($dayum[1] != '') { dbAdd($villa,$month,$dayum[1],$year); } //day 2 elseif ($dayum[2] != '') { dbAdd($villa,$month,$dayum[2],$year); } //day 3 elseif ($dayum[3] != '') { dbAdd($villa,$month,$dayum[3],$year); } //day 4 elseif ($dayum[4] != '') { dbAdd($villa,$month,$dayum[4],$year); } //day 5 elseif ($dayum[5] != '') { dbAdd($villa,$month,$dayum[5],$year); } //day 6 elseif ($dayum[6] != '') { dbAdd($villa,$month,$dayum[6],$year); } //day 7 elseif ($dayum[7] != '') { dbAdd($villa,$month,$dayum[7],$year); } //day 8 elseif ($dayum[8] != '') { dbAdd($villa,$month,$dayum[8],$year); } //day 9 elseif ($dayum[9] != '') { dbAdd($villa,$month,$dayum[9],$year); } //day 10 else { echo "Unknown error."; }} [/code] I`m using the following code to input data from an array into a SQL database. The code should work as follows: If position 1 of the array dayum has something in it, then call the function dbAdd, and write it to the database. For some reason, it`s only writting the first position, and ignoring the others. Thanks, jeff
×
×
  • 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.