Jump to content

wright67uk

Members
  • Posts

    454
  • Joined

  • Last visited

Everything posted by wright67uk

  1. I'm using one in my post, http://forums.phpfreaks.com/topic/282738-select-where-column-anything/
  2. Thanks for the input guys, as Josh suggests, yes I really do need to get in the swing of using parameterised queries. I do this for inserts, but I stumble when using this method for selects. I've had a look at the manual http://php.net/manual/en/mysqli-result.fetch-array.php , although i'm getting an error "Fatal error: Call to undefined method mysqli_stmt::get_result()" This is what i'm using; <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Wizard Log</title> <link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" /> <script type="text/javascript" src="jsDatePick.min.1.3.js"></script> <script type="text/javascript"> window.onload = function() { new JsDatePick({ useMode:2, target:"inputField", dateFormat:"%d-%m-%Y" }); new JsDatePick({ useMode:2, target:"inputField2", dateFormat:"%d-%m-%Y" }); }; </script> </head> <body> <form action="#" method="post"> <input type="checkbox" name="driver[]" value="Julia">Julia <input type="checkbox" name="driver[]" value="Pete">Pete From <input type="text" name="date1" size="12" id="inputField" /> To <input type="text" name="date2" size="12" id="inputField2" /> <input type="submit" value="Submit" name="submit"/> </form> <?php if(isset($_POST['submit']) && ($_POST['submit'] == "Submit")) { $date1 = $_POST['date1']; $date2 = $_POST['date2']; $date1 = date("Ymd", strtotime($date1)); $date2 = date("Ymd", strtotime($date2)); $drivers = "'".implode("','",$_POST['driver'])."'"; } $mysqli = new mysqli('connection'); if($mysqli->connect_error) { die("$mysqli->connect_errno: $mysqli->connect_error"); } $query = "SELECT * FROM wizardlog WHERE driver IN (?) AND date between ? and ? "; $stmt = $mysqli->stmt_init(); if(!$stmt->prepare($query)) { print "Failed to prepare statement\n"; } else { $stmt->bind_param("sss", $drivers, $date1, $date2); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_array(MYSQLI_ASSOC)) { foreach($rows as $row) { $id = $row['id']; $driver = $row['driver']; $date = date("d/m/y", strtotime($date)); $time = $row['time']; $time = substr($time, 0, 5); $fname = $row['fname']; $lname = $row['lname']; $town = $row['town']; if ($driver === Pete) {$bgcolor = '#ff2727'; } else {$bgcolor = '#fffd63';} echo '<div> <div id="detail" style="background-color:'.$bgcolor.'; color:'.$color.'">'.$driver." to collect ".$fname." ".$lname." from ".$town." at ".$time.'</div> <div id="info"><a href="journey_info.php?id='.$id.'"> I </a></div> <div style="clear:both;"></div> </div> '; } $stmt->close(); $mysqli->close(); }} ?> </body> </html>
  3. You could put the form processing on the same page as your I frame source file. Form here... <input type="submit" value="Submit" name="submit"/> </form> <?php if(isset($_POST['submit']) && ($_POST['submit'] == "Submit")) { Page here...
  4. Oops that didn't post right. My form: <form action="#" method="post"> <input type="radio" name="driver" value="Julia">Julia <input type="radio" name="driver" value="Pete">Pete <input type="radio" name="driver" value="?">Both<br> From <input type="text" name="date1" size="12" id="inputField" /> To <input type="text" name="date2" size="12" id="inputField2" /> <input type="submit" value="Submit" name="submit"/> </form>
  5. On my form below, I'm trying to figure a way of using my form to select, Pete, Julia or both Pete and Julia from my SQL database.What value should I put in place of ? In the below radio button values? WCW Summary window.onload = function() { new JsDatePick({ useMode:2, target:"inputField", dateFormat:"%d-%m-%Y" }); new JsDatePick({ useMode:2, target:"inputField2", dateFormat:"%d-%m-%Y" }); }; Julia Pete Both From To <?php if(isset($_POST['submit']) && ($_POST['submit'] == "Submit")) { echo $driver = $_POST['driver']; echo ""; echo $date1 = $_POST['date1']; echo ""; echo $date2 = $_POST['date2']; echo "Date 1 - "; echo $date1 = date("Ymd", strtotime($date1)); echo "Date 2 - "; echo $date2 = date("Ymd", strtotime($date2)); } $mysqli = new mysqli(connection); if ($mysqli->connect_error) { die('Connect Error: ' . $mysqli->connect_error); } $query = "SELECT * FROM wizardlog WHERE driver='$driver' AND date between '$date1' and '$date2' "; $result = $mysqli->query($query); while($row = $result->fetch_array()) { $rows[] = $row; } foreach($rows as $row) { $id = $row['id']; $driver = $row['driver']; $date = date("d/m/y", strtotime($date)); $time = $row['time']; $time = substr($time, 0, 5); $fname = $row['fname']; $lname = $row['lname']; $town = $row['town']; if ($driver === Pete) {$bgcolor = '#ff2727'; } else {$bgcolor = '#fffd63';} echo ' '.$driver." to collect ".$fname." ".$lname." from ".$town." at ".$time.' I '; } ?>
  6. I'm collecting tips on a website, and Im trying to make a 'send as email' feature, where all of the tips from today's date can be sent to users. As Im already displaying todays tips on my website, I would like to put the tips into a variable, ready for mailing. How do I do this? Do I just put $message = (before the while loop?) $query = "SELECT placed, win, id, date, horse, course, odds1, odds2, sp, place, time, tip, description, booky, date_added, time_added FROM toptips WHERE userid = 54 AND `date` ='".$curentDate."' order by date desc"; $result = $mysqli->query($query); while($row = $result->fetch_array()) { $rows[] = $row; } if(count($rows)>0){ foreach($rows as $row) { $date = $row['date']; $date = date("d/m/y", strtotime($date)); $id = $row['id']; $booky = $row['booky']; $sp = $row['sp']; $placed = $row['placed']; // if ($sp === 'yes') {$start = ' SP';} echo '<div style= "width:700px; font-family:verdana;"> <div style="float:left; width:700px; margin-bottom:10px; margin-top: 10px; padding:10px; border: solid 1px grey;"> <h5> ('.$date.") " . $row['time'] . " " . $row['course'] . " - " . $row['horse'] . " " . $row['odds1'] . "/" . $row['odds2'] . $row['sp'] . "-" . $row['place'] . '</h4><img src="' . $row['tip'] . '.png" alt=" '. $row['tip'] .' " height="42" width="42" style="float:right"><br>'. $row['description'] . '...
  7. I'm trying to do a FULL OUTER JOIN, and i'm coming across an error when I test the SQL in phpmyadmin. #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OUTER JOIN likes ON public_tips.id=likes.id ORDER BY public_tips.horse LIMIT 0,' at line 3 My full query is; SELECT * FROM public_tips FULL OUTER JOIN likes ON public_tips.id=likes.id My table structures are similar to: likes Field Type id int(255) user_id int(255) public_tips Field Type id int(255) time varchar(10) course varchar(255) horse varchar(255) Any ideas of where i'm going wrong?
  8. Then I just get a blank page. I've even assigned values manually to the variables, and I still get get the same error on that $stmt->bind_param Ive also just tested my connection and that seems fine too. Its just not making sense.
  9. Im getting " Parse error: syntax error, unexpected T_VARIABLE on line 17" (//stop here) after making a few changes to my file. I've checked the GET variables, and I've checked my database field Types. Ive echoed $placed, and $id. (all fine). Where am I going wrong? and what is causing the Parse error? <?php session_start(); $user_id = $_SESSION["user"]["user_id"]; $user_level = $_SESSION["user"]["user_level"]; include 'connect.php'; $outcome = $_GET['outcome']; $id = $_GET['id']; $blank = " "; $placed = $_GET['outcome']; if (isset($placed)) { $stmt = $mysqli->prepare("UPDATE toptips SET placed = ? WHERE id = ? "); $stmt->bind_param('si', $placed, $id); //stops here $stmt->execute(); $stmt->close(); } if ($outcome == "undo") { $stmt = $mysqli->prepare("UPDATE toptips SET placed = ?, win = ? WHERE id = ? "); $stmt->bind_param('ssi', $blank, $blank, $id); $stmt->execute(); $stmt->close(); }
  10. What is best practice when re-directing a user based on their session variables? Ok, so my below code gives me headers already sent error, as i'm using header location more than once, but it shows what i'm trying to do at least. <?php session_start(); $user_id = $_SESSION["user"]["user_id"]; $loc1 = header("Location: page1.php"); $loc2 = header("Location: page2.php"); if ($user_id === 1008) {$loc1;} if ($user_id === 2) {$loc2;} ?>
  11. This is an email I received today... PHP Freaks wright67uk, Vwzysgnky has just posted a reply to a topic that you have subscribed to titled "pow equation". i quali a lor volta si dividono in due brevi rami, URL DELETED HERE viagra sans ordonnance france vale a dire il tipo Cristularia. uberhaupt eiweisshaltiger URL DELETED HERE cialis generico CNH ist die Grundverbindung, The topic can be found here: http://forums.phpfreaks.com/topic/275112-pow-equation/?view=getnewpost If you have configured in your control panel to receive immediate topic reply notifications, you may receive an email for each reply made to this topic. Otherwise, only 1 email is sent per board visit for each subscribed topic. This is to limit the amount of mail that is sent to your inbox. You can unsubscribe at any time here:http://forums.phpfreaks.com/unsubscribe/Zm9ydW1zO3RvcGljczsyNzUxMTI7OTcwNTg7OTcwNTg7ZWR3YXJkX3Rfd3JpZ2h0QGhvdG1haWwuY28udWs,/ PHP Freaks
  12. Hi, im trying to echo mysqli results into my form fields, but nothing appears. Is this because my query is not returning any results (im expecting results), or I have I missed something here? $mysqli = new mysqli(''); if ($mysqli->connect_error) { die('Connect Error: ' . $mysqli->connect_error); } $query = "SELECT description, time, course, horse, odds1, odds2, place FROM toptips WHERE date='$newdate' AND horse='$horse'"; $result = $mysqli->query($query); while($row = mysqli_fetch_array($result)) { $description = $row['description']; $time = $row['time']; $course = $row['course']; $horse = $row['horse']; $odds1 = $row['odds1']; $odds2 = $row['odds2']; $place = $row['place']; } ?> <form action="edit_tip_action.php" method="post"><br/> <input type="hidden" value="<?php echo $id ?>" /> <div class="formtitle">Time<div/> <input name="time" type="text" value="<?php echo $time; ?>" /><br/> <div class="formtitle"><Br/>Course<div/><input name="course" type="text" value="<?php echo $course; ?>" /><br/> <div class="formtitle"><Br/>Horse<div/><input name="horse" type="text" value="<?php echo $horse ;?>" /><br/> <div class="formtitle"><br/>Odds<div/> <input name="odds1" type="text" size="1" value="<?php echo $odds1 ;?>" /> / <input name="odds2" type="text" size="1" value="<?php echo $odds2 ;?>" /><br/> <div class="formtitle"><br/>Place</div><input name="place" type="text" value="<?php echo $place ;?>" /><br/> Note: ew or Win (capital W)<br/><br/> Description<br/><textarea rows="4" cols="50"> <?php echo $description ?> </textarea> <input type="submit" value="Submit"> </form>
  13. I'm having the following error when running my code; Parse error: syntax error, unexpected '}' ..... line 188 my code is <?php if ($_attributeType["name"] === 'Windsor') {$pc ='SL4'}; //line 188 include 'file_weather.php' ; ?> My curly brace is clearly there, so can I put this down to something else?
  14. retire_process.php <?php session_start(); $horse = $_POST['horse']; $mysqli = new mysqli('','','',''); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } // $mysqli->query("DELETE FROM notes WHERE horse_name = '$horse'"); $stmt = $mysqli->prepare("DELETE FROM races WHERE name = ? "); $stmt->bind_param("s", $horse); if ($stmt->execute()) { echo "You have deleted " . $horse; } else { echo "Failed to delete {$horse}<br>\r\n"; echo "[{$stmt->errno}] {$stmt->error}<br>\r\n"; } echo '<br/><br/><a href="follow.php">Back</a><br/>'; ?> Thanks for the suggestions for my code (retire_process.php), i've shown some more code as requested. When I run the code you gave me, I'm still echoing "You have deleted A Bailer" (horse name) I have checked mysql tables and they are are all using utf8_unicode_ci 'name' is set as a varchar. extract of follow.php $search = isset($_GET['search']) ? strtolower(trim($_GET['search'])) : ''; if(!in_array($search,$links)){ // supplied search term is not an expected value $search = ''; } // use the search value if(empty($search)){ // nothing selected echo "Please select something to search for.<br>"; } else { // perform the search echo "<br><br>"; if($search == '0-9'){ // special handling for a 0-9 leading wild-card search $query = "SELECT * FROM `races` WHERE `name` REGEXP '^[0-9]' GROUP BY NAME"; $result = mysql_query($query); } else { $query ="SELECT name FROM `races` WHERE `name` LIKE '$search%' GROUP BY name UNION SELECT horse_name FROM `notes` WHERE `horse_name` LIKE '$search%' GROUP BY horse_name order by name"; $result = mysql_query($query); } while($row = mysql_fetch_array($result)) { echo '<div style="width:300px; float:left;">'; echo $row['name']; echo '</div><div style="width:"300px; float:left">' ; echo '<a href="action.php?name=' .$row['name']. '">NapTrack /</a>' ; echo '<a href="info.php?horse=' .$row['name']. '">NapNotes </a>' ; $user_level = $_SESSION["user"]["user_level"]; if ($user_level > 2) { echo '<form name="retire" action="retire.php" method="POST"> <input type="hidden" name="horse" value=" ' .$row['name']. '"> <input type="submit" value="Delete"></form>'; } echo "</div><br/>"; } } ?> retire.php <?php session_start() ; $horse = $_POST['horse']; ?> <html> <form method="post" action="retire_process.php"> Are you sure you want to delete <?php echo $horse ?> ? <input type="hidden" name="horse" value="<?php echo $horse ?>" /> <input type="submit" value="Yes" /> </form> </html>
  15. Thanks for your help, although I still can't get my head around why its not deleting? Usually when my sql isnt executed, I would expect $stmt to be a non object.
  16. Ok, thanks. How do I do that?
  17. That should have been 'From: ' .$emailFrom. "/r/n" .
  18. Try $headers = 'From: $emailFrom . "\r\n" . 'Reply-To: ' . $aDifferentEmailAddress . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $send = mail($emailTo, $subject, $body, $headers); } and see if that helps?
  19. I'm having trouble with the below code. It doesn't delete $horse, but at the same time still echo's "You have deleted " . $horse; $horse echo's out fine, and i've run the query in phpmyadmin; DELETE FROM races WHERE name = 'Abstract' (one of the $horse names in my db) and the query deletes ok How can I get the below query to delete, and how can I print out the statement below? <?php session_start(); $horse = $_POST['horse']; $mysqli = new mysqli('','','',''); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if ($stmt = $mysqli->prepare("DELETE FROM races WHERE name = ? ")); { $stmt->bind_param("s", $horse); $stmt->execute(); echo "You have deleted " . $horse; } echo '<br/><br/><a href="follow.php">Back</a><br/>'; print($mysqli->query); $mysqli->close(); ?>
  20. SELECT name FROM `races` WHERE `name` LIKE '$search%' GROUP BY NAME UNION SELECT horse_name FROM `notes` WHERE `horse_name` LIKE '$search%' GROUP BY horse_name"; Returns a single list of names that are sorted alphabetically per table ab - results of races ac - results of races ad - results of races ab - results of notes ac - results of notes ad - results of notes how can I change my query so that all of my results are sorted alphabetically as a whole? eg ab - results of races ab - results of notes ac - results of races ac - results of notes
  21. What would be the best way to make an alphabetical pagination list of MySQL results? eg. A | B | C | D | E would I simply need to assign GET variables to each letter, and then process the GET in a MySQL select? eg. <a href="page.php?letter=a>A | </a> <a href="page.php?letter=a>B | </a> <a href="page.php?letter=a>C | </a> <a href="page.php?letter=a>D | </a> <a href="page.php?letter=a>E | </a> I'm sure there is a more efficient way?
  22. I'm really not very experienced with sql, I was trying to read up on aliases , in the hope I could do a select, followed by a select distinct on that result set.
  23. Hi thanks for the reply, I'm pasting my code, using my cell phone, so i hope it looks ok. <?php include 'connect.php'; $date = date('Ymd'); $query= "SELECT phpbb_users.user_email, races.date, races.name, races.odds, races.race, actions.action, actions.user_id FROM races RIGHT JOIN actions ON races.name = actions.name RIGHT JOIN phpbb_users ON actions.user_id = phpbb_users.user_id WHERE races.date = $date" ; if(!$result = $mysqli->query($query)){ die('There was an error running the query [' . $mysqli->error . ']'); } while($row = $result->fetch_assoc()) { $horse_name = $row['name']; $user_id = $row['user_id']; $race = $row['race']; $user_email = $row['user_email']; echo $info_msg = "just to let you know a horse you are following is racing soon! <br><b> " . $horse_name . " </b> will be racing in the " . $race; $to = $user_email; $subject = 'A reminder from TNT'; $message = $info_msg; $headers = 'From: reminder@reminder.com' . "\r\n" . 'Reply-To: reminder@reminder.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } ?> As you can see, I'm emailing a reminder, when a horse is due to run. I don't want to send an email if the horse name appears twice in my database.
  24. races has 3000 records and contains the column 'race', 'odds', 'name' php_users has many records and contains 'user_id', 'user_email' actions has only a few records at the moment and contains 'action', 'user_id', 'name' in total races has 4 columns, php_users has 84 columns, and actions has 4 columns I would like to have a result where 'Hedy' only appears once. (Not fussed which of the two records remains)
  25. In the below query, how can I only select distinct values for races.name? ie. obviously this won't work, but to get my point across... SELECT phpbb_users.user_email, races.date, DISTINCT races.name my sql as it stands... SELECT phpbb_users.user_email, races.date, races.name, races.odds, races.race, actions.action, actions.user_id FROM races RIGHT JOIN actions ON races.name = actions.name RIGHT JOIN phpbb_users ON actions.user_id = phpbb_users.user_id WHERE races.date = $date" ;
×
×
  • 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.