Jump to content
Larry Ullman's Book Forums

margaux

Members
  • Posts

    453
  • Joined

  • Last visited

  • Days Won

    52

Everything posted by margaux

  1. mysqli_stmt_bind_param( $stmt, 'isdsss', $designer, $dn, $op, $rp, $c, $d,$i); In the above statement you have 6 type definitions - 'isdsss' - and 7 variables. I suspect you need to add another d after the first one. mysqli_stmt_bind_param( $stmt, 'isddsss', $designer, $dn, $op, $rp, $c, $d,$i);
  2. Have you run your query in something like phpmyadmin or the mysql client with actual values? There is something about your query statement that is causing the error and if you run it directly, you'll get a more meaningful error message. Also you might want to look at the debugging chapter - it offers some useful debugging tips which will save you hours.
  3. Have you tested the query statement on its own in phpmyadmin or equivalent? You've misspelt original_price - check that it matches what you have in your table.
  4. Everytime you call mysql_fetch_array, it returns the current row and moves its internal pointer to the next row. So the second time you use it, it will be starting at the second row. For your requirements, you could either repeat the d/b query or store the query results in an array which you can access as you need to e.g. $names = array(); // create a variable to hold the query results $query = "SELECT name FROM users ORDER BY name ASC"; $r = mysql_query($query, $dbc); while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { $names[] = $row; // add the row in to the results array } Then you can loop through $names for your various dropdown menu options.
  5. You could insert print_r($r); after your if statement which is a quick way to show how many rows are returned by your query.
  6. There could be an issue with your html. I ran your code on one of my local databases and all records were returned. Presumably you've used print_r to see if all 32 rows are being returned?
  7. Have you tried running this query directly through something like phpmyadmin to ensure that it is not one of your d/b records causing the problem?
  8. Here's what my goto 'techie' expert said "the MySQL server has to be configured to accept external connections, that is bind to the correct network interface. The firewall may also need to be configured to accept incoming connections on the appropriate port". I only had to use the GRANT ALL PRIVILEGES command before issuing the mysqli_connect so I wouldn't know what to do with the above but maybe it will be of some help to you?
  9. I'm pretty certain you will have to compromise and add some extra markup to style your radio buttons. Radio buttons and checkboxes are difficult form elements to style. It will help if you put the label tags before the input tags and you may want to use the name attribute so that they are part of the same group, otherwise both buttons could be checked. <label for="male">Male</label> <input type="radio" name="gender" id="male"> <label for="female">Female</label><input type="radio" name="gender" id="female">
  10. I don't have this book so I'm not sure the context in which you are using preg_match. I'm guessing that you are using it to validate some form fields. You can use preg_match without the 3rd optional parameter. if (!preg_match($pattern, $string)) { $problem=TRUE; $message .='<p>Please enter a valid name.</p>'; }
  11. What error are you getting? Have you tried GRANT ALL PRIVILEGES ON dbName.* TO dbUser @'%' IDENTIFIED BY 'dbPassword';
  12. To prevent anyone inserting dicey code into your MySQL statements, you should probably validate your variable in some way - e.g. check its type with the filter extension and if appropriate, is it within a specific range. Use the mysqli_real_escape_string() function which escapes any special characters in your query. Or you can use a prepared statement which sends the query and specific values separately to MySQL $view = 1; $done = filter_var($_GET['Ref2'], FILTER_VALIDATE_INT, array('min_range' => 1)); //ensure variable is an integer > 0 $done1 = "UPDATE errors SET Viewed = ? WHERE Ref = ?"; // insert placeholders to your query $stmt = mysqli_prepare($dbc, $done1); // send the statement to MySQL and assign result to a variable mysqli_stmt_bind_param($stmt, 'ii', $view, $done); // bind variables to the placeholders, the middle parameter tells sql what type of variables to expect, in this instance two integers mysqli_stmt_execute($done1); // execute the sql statement check the result mysqli_stmt_close($stmt);// clears $stmt variable
  13. Look up JOINs as that will achieve what you're after. However, you will need values in the foreign keys columns, otherwise how will you cross-reference the records in the corresponding tables.
  14. My approach is to use the HTML5 tags with the HTML5 shiv because it gives you the best of all worlds and will get you into the HTML5 habit which I think will be adopted quite quickly as more and more websites are accessed via mobile devices.
  15. Regarding your second question, your system probably has magic quotes turned on. You can look up magic quotes in the php manual - even though it is deprecated, a lot of hosts keep it enabled. To override it you can check for it and then use stripslashes() e.g. $comments = (get_magic_quotes_gpc() ? stripslashes($_REQUEST['comments']) : $_REQUEST['comments']);
  16. You need to ensure your localhost is configured properly to send emails. If you search online you will find what changes you need to make.
  17. I copied and pasted your code and it worked correctly - displaying the appropriate error messages and updating the d/b when correct data was input. You might want to check that your action file is pointed to the correct file/folder and all your changes have been saved. Also try clearing the cache. Sorry if this sounds basic but sometimes its the obvious that catches us up.
  18. Put in some echo or var_dump statements after some of your conditions to see what the variables are and if your script is following the logic as you expect it to. Also look at the source code as that can sometimes highlight an error. Then post your code.
  19. I'm not Larry but I have done this a few times, so hope you don't mind if I add a reply. There are a number of php functions that allow you to manipulate a file and they are well documented on the web. Start with fopen, fwrite and fclose.
  20. Run your query in phpmyadmin to see if the timezones are installed. If you get a column full of zeros, they aren't, this post might help.
  21. Since $rating is defined, your update statement is not changing any values therefore mysql will return zero rows but has not encountered an error. Try changing $rating.
  22. This is a bit confusing. What is the tablename? Your select statement should be in the format of SELECT columnname FROM tablename WHERE columnname = '$variable' Assuming your table is named discount_codes and the column is named vouchercode... SELECT discount_amount FROM discount_codes WHERE vouchercode = '$vouchercode' Run your mysql statements in something like phpmyadmin and if it doesn't work it will give you a message to indicate where the error is. Then in your posts you can be more specific rather than just stating it doesn't work, which doesn't actually give any information. I would recommend reading chap 5 and chap 8.
  23. You can use the variable you created from $_GET, although you might want to do some validation on it first. SELECT discount_amount FROM discount_codes WHERE discount_code = '$vouchercode';
  24. You could get the column from the d/b that you need and use in_array to check against your designation array.
  25. My approach is to get all the booked dates from the d/b and store them in an array. Then I display the calendar with forward and backward arrows to allow the visitor to page through the months. Using some for and while loops, I check if each calendar date is in the booked_dates array and set a css class accordingly. The basic functionality is working so I will look at how I set the booking price but for now I wonder if you would comment on my code. I'm not sure how efficient it is - I've had to do alot of date/variable formatting and wonder if there are better solutions. I know its alot of code so if you don't want to go through it, I Many thanks for any comments. $r = mysqli_query($dbc, "SELECT start_date, num_days FROM bookings ORDER BY start_date"); $days_booked=array(); while (list($start, $num_days) = mysqli_fetch_array($r, MYSQLI_NUM)){ //use number of days for loop count for ($i=0; $i<$num_days; $i++) { if ($i==0){ $days_booked[] = $start; } else { // separate date into year, month and day to add $i days to day $date_parts = explode('-',$start); $days_booked[] = date("Y-m-d",mktime(0,0,0, ($date_parts[1]), $date_parts[2] + $i, ($date_parts[0]))); } } //end for loop } //end while loop // check if month and year have been passed in url i.e. forward or backward arrow on calendar date has been clicked $mOptions = array('min_range' => 1, 'max_range' => 12); $yOptions = array('min_range' => 2012, 'max_range' => 2020); if (isset($_GET['m']) && isset($_GET['y']) ) { settype($_GET['m'],"integer"); $month = filter_var($_GET['m'], FILTER_VALIDATE_INT, $mOptions); $year = filter_var($_GET['y'], FILTER_VALIDATE_INT, $yOptions); //forward arrow clicked if (isset($_GET['a']) && ($_GET['a'] == 'f') ){ $year= ($month == 12 ? $year + 1: $year); $month = ($month == 12 ? 01 : $month + 1); } //backward arrow clicked if (isset($_GET['a']) && ($_GET['a'] == 'b') ){ $year= ($month == 1 ? $year - 1: $year); $month = ($month == 01 ? 12 : $month - 1); } $month =($month < 10 ? str_pad($month, 2, "0", STR_PAD_LEFT) : $month); } else { //else first time on page, get today's date to start display on current month $date = time (); //assign day, month, and year to separate variables $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); } // DISPLAY CALENDAR // //generate the first day of the month $first_day = mktime(0,0,0,$month, 1, $year) ; //get the month name $title = date('F', $first_day) ; //determine how many blank squares to display at start of month $day_of_week = date('D', $first_day); switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } //get num of days in the current month $days_in_month = cal_days_in_month(0, $month, $year); //display the table header echo "<table border=1 width=594 height=394>"; echo "<thead><tr><th colspan=7> <a href=\"calendar.php?m=$month&y=$year&a=b\"><span class=\"bArrow\"><</span></a>$title $year <a href=\"calendar.php?m=$month&y=$year&a=f\"><span class=\"fArrow\">></span></a></th></tr></thead>"; echo "<tr><td width=42 align=\"center\">Sun</td><td width=42 align=\"center\">Mon</td><td width=42 align=\"center\">Tue</td><td width=42 align=\"center\">Wed</td><td width=42 align=\"center\">Thu</td><td width=42 align=\"center\">Fri</td><td width=42 align=\"center\">Sat</td></tr>"; //keep count of the days in the week, up to 7 $day_count = 1; echo "<tr>"; //display blank days while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } //set the first day of the month to 1 $day_num = 1; //count up the days in the month while ($day_num <= $days_in_month ) { //format calendar day to be same format as date in days_booked array $day_num = str_pad($day_num, 2, "0", STR_PAD_LEFT); //concatenate year, month, day for comparison $compare_date = "$year-$month-$day_num"; //set css class variable $avail = (in_array($compare_date,$days_booked) ? 'unavail' : 'avail'); //display calendar day with appropriate css class echo "<td class=\"$avail\">$day_num</td>"; $day_num++; $day_count++; //start a new row every week if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } //finish the table with some blank squares if needed while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } echo "</tr></table>";
×
×
  • Create New...