Jump to content

farban6

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

farban6's Achievements

Member

Member (2/5)

0

Reputation

  1. The problem is that I need to do this on a date that the person has posted. Say on the 21/11/2011, then match agiasnt the times.
  2. Here we go, I need to use a query where it uses a posted time value to compare if there are the same times on the posted date value. I want it so the user cant book the same time on the same day as someone before bascially. My input so far is this <?php ob_start();?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Conforming XHTML 1.0 Strict Template</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link type="text/css" href="ui-lightness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" /> <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script> </head> <body> <form name="input" action="input.php" method="post"> Subject: <input type="text" name="subject" /> First Name: <input type="text" name="firstname" /> Surname: <input type="text" name="surname" /> Trainer: <input type="text" name="trainer" /> Email: <input type="text" name="email" /> Date: <input type="text" name="event_date" id="date" /> Time: <input type="text" name="event_time" id="time" /> <input type="submit" value="Submit" name="submit" /> </form> <script type="text/javascript"> $('#date').datepicker(); $('#time').timepicker({}); </script> <?php include_once("functions/database.php"); include_once("functions/number.php"); if (isset($_POST["submit"])) { echo $_POST['event_date']; echo mdy2mysql($_POST['event_date']); echo $_POST['event_time']; echo time2mysql($_POST['event_time']); $queryselect = "SELECT * FROM events LIKE '".$_POST['event_time']."'"; if ($queryselect == true) { echo "sorry this time is already booked"; } else { $query = "INSERT INTO events (subject, firstname, surname, trainer, email, event_date, event_time, status) VALUES('".$_POST["subject"]."', '".$_POST["firstname"]."', '".$_POST["surname"]."','".$_POST["trainer"]."','".$_POST["email"]."' ,'".mdy2mysql($_POST['event_date'])."','".time2mysql($_POST['event_time'])."', 'pending' ) "; $result = mysql_query($query, $db_link) or die(mysql_error().'cannot get results!'); header("Location: input.php"); } ?> can anyone help me ? very much appreciated.
  3. this is on amensharma.co.uk/testing <?php $db_link = mysql_connect("amensharma.co.uk","amenshar_admin","amen001"); if (!$db_link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('amenshar_calender', $db_link); if (!$db_selected) { die ('Can\'t use database : ' . mysql_error()); } ?> this is the error it returns Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'amenshar_admin'@'neptune.servers.rbl-mer.misp.co.uk' (using password: YES) in /home/amenshar/public_html/testing/functions/database.php on line 4 Could not connect: Access denied for user 'amenshar_admin'@'neptune.servers.rbl-mer.misp.co.uk' (using password: YES) bit stumped here any help would be great all the details are correct, just confused why im having these errors
  4. Okay thanks i'm going to get in touch with the host then and try and sort this out. Thanks for everyones help!
  5. Good spot, just noticed the site technically isnt on www2.erban.co.uk as its on www.erban.co.uk. Is there a way of making it so the server reads www rather then www2, any explanations on why this is happening? Thanks for any additional information
  6. Sorry my mistake. Warning: mysql_connect(): Access denied for user 'amenshar_admin'@'www2' (using password: YES) in d:\Domains\erban.co.uk\wwwroot\functions\database.php on line 4 Could not connect: Access denied for user 'amenshar_admin'@'www2' (using password: YES) Yeah its still in the middle of testing Is there anything details needed to help solve this problem?
  7. Having a major problem connecting to a live site. I have set up the user and database on Cpanel like normal. Then proceeded to insert those details into my mysql connection script <?php $db_link = mysql_connect("***","****","***"); if (!$db_link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('amenshar_calender', $db_link); if (!$db_selected) { die ('Can\'t use database : ' . mysql_error()); } ?> I am connecting to domain erban.co.uk, yet looking at the cpanel the master domain is amensharma.co.uk. Is this what the problem could be. This is the error messege it is throwing up Warning: mysql_connect(): Access denied for user '_admin'@'localhost' (using password: YES) in d:\Domains\erban.co.uk\wwwroot\functions\database.php on line 4 Could not connect: Access denied for user '_admin'@'localhost' (using password: YES)
  8. Javascript isnt my strong point, and im trying to embed js into a php echo which is proving very differcult. So I have two links that open up popup pages. The first opens up a normal page, the second opens up a page which passes get varibles. The second link I am having problems with, so far this works <script type="text/javascript"> function open_win_input() { window.open("input.php",'_blank', "width=800,height=300"); } </script> <a href="javascript:void(0);" onclick="open_win_input();">Insert Appointment</a> But when I try to make a second link for edit, none of the javascript functionaly works for either links <script type="text/javascript"> function open_win_input() { window.open("input.php",'_blank', "width=800,height=300"); } function open_win_edit(d,s) { window.open("edit.php?date_id=" + d"&status="+ s,'_blank', "width=800,height=300"); } </script> <?php echo "<a href='javascript:void(0);' onclick=\"open_win_edit('".$result['date_id'].','.$result['status']."')\">Edit</a>"; ?> Any help would be very appreciated
  9. Yeah i tried to use a for loop but i couldnt get the number to increment once, I want a single number to count to 3 if there are 3 instances of the date 10-10-2011, rather than 1,1,1. Plus i cant get the number to fit into the div despite the fact the varible is inside the div calender.php <script type="text/javascript"> function popup(v) { window.open('dayview.php?event_date='+ v,'_blank','width=800,height=600'); } </script> <?php /* draws a calendar */ function draw_calendar($month,$year,$events = array()){ /* draw table */ $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">'; /* table headings */ $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>'; /* days and weeks vars now ... */ $running_day = date('w',mktime(0,0,0,$month,1,$year)); $days_in_month = date('t',mktime(0,0,0,$month,1,$year)); $days_in_this_week = 1; $day_counter = 0; $dates_array = array(); /* row for week one */ $calendar.= '<tr class="calendar-row">'; /* print "blank" days until the first of the current week */ for($x = 0; $x < $running_day; $x++): $calendar.= '<td class="calendar-day-np"> </td>'; $days_in_this_week++; endfor; /* keep going with days.... */ for($list_day = 1; $list_day <= $days_in_month; $list_day++): $count = array(); $count = $calendar.= "<td class='calendar-day'><div style='position:relative;height:100px;' onclick=\"popup('".$year.'-'.$month.'-'.$list_day."')\">"; /* add in the day number */ $calendar.= '<div class="day-number">'.$list_day.'</div>'; if ($month <= 9){ if ($list_day <= 9){ $event_day = $year.'-'."0".$month.'-'."0".$list_day; if(isset($events[$event_day])) { foreach($events[$event_day] as $event) { $calendar.= '<div class="event">'.$event['event_date'].'</div>'; } } } if ($list_day >= 10) { $event_day = $year.'-'."0".$month.'-'.$list_day; if(isset($events[$event_day])) { foreach($events[$event_day] as $event) { $calendar.= '<div class="event">'.$event['event_date'].'</div>'; } } } } if ($month >= 10){ if ($list_day <= 9){ $event_day = $year.'-'.$month.'-'."0".$list_day; if(isset($events[$event_day])) { foreach($events[$event_day] as $event) { $count =+ 1; echo $count; $calendar.= '<div class="event">'.$event['event_date'].'</div>'; } } } if ($list_day >= 10) { $event_day = $year.'-'.$month.'-'.$list_day; if(isset($events[$event_day])) { foreach($events[$event_day] as $event) { $calendar.= '<div class="event">'.$event['event_date'].'</div>'; } } } } else { $calendar.= str_repeat('<p> </p>',2); } $calendar.= '</div></td>'; if($running_day == 6): $calendar.= '</tr>'; if(($day_counter+1) != $days_in_month): $calendar.= '<tr class="calendar-row">'; endif; $running_day = -1; $days_in_this_week = 0; endif; $days_in_this_week++; $running_day++; $day_counter++; endfor; /* finish the rest of the days in the week */ if($days_in_this_week < : for($x = 1; $x <= (8 - $days_in_this_week); $x++): $calendar.= '<td class="calendar-day-np"> </td>'; endfor; endif; /* final row */ $calendar.= '</tr>'; /* end the table */ $calendar.= '</table>'; /** DEBUG **/ $calendar = str_replace('</td>','</td>'."\n",$calendar); $calendar = str_replace('</tr>','</tr>'."\n",$calendar); /* all done, return result */ return $calendar; } ?> index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Conforming XHTML 1.0 Strict Template</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link type="text/css" href="ui-lightness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" /> <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script> </head> <body> <script type="text/javascript"> $('#date').datepicker(); $('#time').timepicker({}); </script> <?php include_once("functions/database.php"); include_once("functions/calender.php"); include_once("functions/number.php"); include_once("pending.php"); /* date settings */ $month = (int) ($_GET['month'] ? $_GET['month'] : date('m')); $year = (int) ($_GET['year'] ? $_GET['year'] : date('Y')); /* select month control */ $select_month_control = '<select name="month" id="month">'; for($x = 1; $x <= 12; $x++) { $select_month_control.= '<option value="'.$x.'"'.($x != $month ? '' : ' selected="selected"').'>'.date('F',mktime(0,0,0,$x,1,$year)).'</option>'; } $select_month_control.= '</select>'; /* select year control */ $year_range = 7; $select_year_control = '<select name="year" id="year">'; for($x = ($year-floor($year_range/2)); $x <= ($year+floor($year_range/2)); $x++) { $select_year_control.= '<option value="'.$x.'"'.($x != $year ? '' : ' selected="selected"').'>'.$x.'</option>'; } $select_year_control.= '</select>'; /* "next month" control */ $next_month_link = '<a href="?month='.($month != 12 ? $month + 1 : 1).'&year='.($month != 12 ? $year : $year + 1).'" class="control">Next Month >></a>'; /* "previous month" control */ $previous_month_link = '<a href="?month='.($month != 1 ? $month - 1 : 12).'&year='.($month != 1 ? $year : $year - 1).'" class="control"><< Previous Month</a>'; /* bringing the controls together */ $controls = '<form method="get">'.$select_month_control.$select_year_control.' <input type="submit" name="submit" value="Go" /> '.$previous_month_link.' '.$next_month_link.' </form>'; /* get all events for the given month */ $events = array(); $query = "SELECT * FROM events WHERE status ='approved' ORDER BY event_time" or die (mysql_error()); $result = mysql_query($query, $db_link) or die('cannot get results!'); while($row = mysql_fetch_assoc($result)) { $events[$row['event_date']][] = $row; } echo '<h2 style="float:left; padding-right:30px;">'.date('F',mktime(0,0,0,$month,1,$year)).' '.$year.'</h2>'; echo '<div style="float:left;">'.$controls.'</div>'; echo '<div style="clear:both;"></div>'; echo draw_calendar($month,$year,$events); echo '<br /><br />'; ?> </body> </html>
  10. if ($month <= 9){ if ($list_day <= 9){ $event_day = $year.'-'."0".$month.'-'."0".$list_day; if(isset($events[$event_day])) { foreach($events[$event_day] as $event) { $calendar.= '<div class="event">'.$event['event_date'].'</div>'; } } } Right, using a mysql query the value from $event['event_Date'] prints out in a div. I need a number count of the amount of times this value is printed. any help?
  11. Cant get it to work!! here is the code , how do i fix this? <script type="text/javascript"> function popup(var) { alert(var); } </script> <?php $calendar.= "<td class='calendar-day'><div style='position:relative;height:100px;' onclick='popup('hello')'>"; ?>
  12. I am experimenting around with PDO, I have a DB handle class and instancing it in a function. The problem is when I want to bind elements in a query, for example I bind a parameter but I can only do it using a varible outside of the object. <?php $database = new Database("localhost", "fry", "root", ""); $database->set_table("usertest"); $database->set_query("SELECT * FROM usertest WHERE user_name = :user_name"); $value = "matt"; $database->prepare_query(); $database->bind("parameter", ":user_name", $value ,PDO::PARAM_STR, 5); $database->execute(); while($result = $database->fetch()) { echo $result['user_name'].'<br />'; } ?> Is this bad OOP practice? I wanted to put $value = "matt"; into the Database class somehow here is the Database class <?php class Database{ public $hostname; public $database; public $username; public $password; public $connection; public $prepare; public $query; public $table; public $fetch; public $bind_var; public $bind_val; function __construct($hostname, $database, $username, $password) { $this->hostname = $hostname; $this->database = $database; $this->username = $username; $this->password = $password; $this->Database_connection(); } public function Database_connection() { try { $this->connection = new PDO('mysql:host='.$this->hostname.';dbname='.$this->database, $this->username, $this->password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } } public function set_query($query) { $this->query = $query; } public function get_query() { return $this->query; } public function set_table($table) { $this->table = $table; } public function get_table() { return $this->table; } public function set_bind_var($var) { $bind_var = $var; } public function set_bind_val($val) { $bind_val = $val; } public function get_bind_var() { return $this->bind_var; } public function get_bind_val() { return $this->bind_val; } public function bind($bindtype, $val, $var, $pdo, $num) { if ($bindtype == "parameter") { $result = $this->prepare->bindParam($val,$var,$pdo); } return $result; } public function prepare_query() { $this->prepare = $this->connection->prepare($this->get_query()); } public function execute() { $this->prepare->execute(); } public function fetch() { return $this->prepare->fetch(); } } ?> Yet agian sorry for the sloppy code, this is mainly an experiment, would be very appriciated if someone could help me out with this problem.
  13. $meta = $stmt->result_metadata(); while ( $field = $meta->fetch_field() ) { $parameters[] = &$field->name; } var_dump($parameters); var dump outputs the last fetched values array(3) { [0]=> string(7) "user_id" [1]=> string(9) "user_name" [2]=> string(13) "user_password" } Warning: Parameter 1 to mysqli_stmt::bind_result() expected to be a reference, value given in C:\xampp\htdocs\xampp\testing\index.php on line 21 No references just values, maybe its because $field is set as a method? I am shooting in the dark a bit here
  14. The code i have simply copied from the tutorial on the link I provided earlier on in the thread. http://net.tutsplus.com/tutorials/php/the-problem-with-phps-prepared-statements/ function read() { $parameters = array(); $results = array(); $mysql = new mysqli('localhost', 'root', '', 'fry') or die('There was a problem connecting to the database'); $stmt = $mysql->prepare('SELECT * FROM usertest') or die('Problem preparing query'); $stmt->execute(); $meta = $stmt->result_metadata(); while ( $field = $meta->fetch_field() ) { $parameters[] = &$field->name; } print_r($parameters); call_user_func_array(array($stmt, 'bind_result'), $parameters); while ( $stmt->fetch() ) { $x = array(); foreach( $row as $key => $val ) { $x[$key] = $val; } $results[] = $x; } return $results; } $results = read(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>untitled</title> </head> <body> <?php foreach ($results as $row) : ?> <p> <?php echo $row['user_password']; ?> </p> <?php endforeach; ?> </body> </html> I have learnt a fair bit from all the advice and debate on this thread. The only think that i just cant understand is this code while ( $field = $meta->fetch_field() ) { $parameters[] = &$row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $parameters); If i simply replaced the $parameters values with this while ( $field = $meta->fetch_field() ) { $parameters[] = &$field->name; } surely this makes the parameters passed by reference yet this outputs Warning: Parameter 1 to mysqli_stmt::bind_result() expected to be a reference, value given in C:\xampp\htdocs\xampp\testing\index.php on line 19 so how is this being passed by value? and how is row getting values assigned to the key?
×
×
  • 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.