Jump to content

wright67uk

Members
  • Posts

    454
  • Joined

  • Last visited

Everything posted by wright67uk

  1. You can submit the form to the current page. action="<?php echo $_SERVER['PHP_SELF']; ?>" Any form action will reload a page
  2. Thankyou for the reply. $info_msg is already in a while loop. User_id changes in each row, wouldn't this have to be a while loop to work?
  3. I'm having a few troubles. When I run the first query below in phpmyadmin, i receive six results. However when I run the code below $info_msg is only echoed once, whereas I was expecting it to be echoed once for every result. (six times) Where am I going wrong and what should I change? <?php include 'connect.php'; $date = date('Ymd'); $query= "SELECT races.date, races.name, races.odds, races.race, actions.action, actions.user_id FROM races RIGHT JOIN actions ON races.name = actions.name 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']; $query = "SELECT user_email FROM phpbb_users WHERE user_id = $user_id" ; } if(!$result = $mysqli->query($query)) { die('There was an error running the query [' . $mysqli->error . ']'); } while($row = $result->fetch_assoc()){ $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); } ?>
  4. Thankyou so... if (mail($to, $subject, $message, $headers)) {do this}; and how in-depth would it be to test for returned messages ie. undeliverable?
  5. What is the best way to test an email has been sent when using php mail? I need to add a mysql update, but I need to test that the email has definitely been sent. Is it good enough to put the below code into an IF block? $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); // if mail sent then do this...
  6. In your form you are using a post method, but are you recalling it with a get? Also where are you assigning the values for the variables used within your mysql query?
  7. I've 3 varchar columns - name, race, and odds. with a primary key on name. I want only one record for each name. If the name exists, then I want the odds and race to be updated.
  8. For some reason my code is creating duplicate entries within my database. Am I using row count in the wrong way? Line 32 <html><body> <?php ob_start(); $mysqli = new mysqli('', '', '', ''); $url = "http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=2&marketSort=--&filterBIR=N"; $root = @simplexml_load_file($url); if ($root) { $data = get_object_vars($root); $response = $data['response']; $class = $response->williamhill->class; $attClass = $class->attributes(); $types = $class->type; foreach ($types as $_type) { $_attributeType = $_type->attributes(); $markets = $_type->market; $html = ''; foreach ($markets as $_market) {$_attributeMarket = $_market->attributes(); $participants = $_market->participant; foreach ($participants as $_participants) {$_attributeParticipant = $_participants->attributes(); $name = $_attributeParticipant["name"]; $odds = $_attributeParticipant["odds"]; $race = $_attributeMarket["name"]; echo $name . " - " . $odds . " - " . $race ?><br/> <?php if ($mysqli->connect_error) {die('Connect Error: ' . $mysqli->connect_error);} if ($stmt = $mysqli->query("SELECT * FROM races WHERE name = '$name' and race = '$race' ")) { $row_cnt = $stmt->num_rows; $stmt->close(); } if ($row_cnt > 0) { $stmt = $mysqli->prepare("UPDATE races SET odds = ?, race = ? WHERE name = ?"); $stmt->bind_param('sss', $odds, $race, $name); $stmt->execute(); $stmt->close(); } else if (($name !="2nd Favourite") AND ($name !="Favourite")) { $stmt = $mysqli->prepare("INSERT INTO races VALUES (?, ?, ?)"); $stmt->bind_param('sss', $name, $odds, $race); $stmt->execute(); $stmt->close(); } } } } } ?> <?php ob_flush(); ?> </body></html>
  9. Wo! My code went a bit bonkers when i edited my forum text from my mobile.
  10. Ah thanks Jessica. I think somthing else is wrong aswell. It let's in 2nd Favourite and adds it many many times. I'm trying to put the feed into mysql. If the feed is unavailable, then I want the script to try again, hence the refresh. I wasn't expecting 2nd Favourite to be added at all, let alone over and over again. <html><body> <?php ob_start(); $mysqli = new mysqli('', '', '' ); $url = "http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=2&marketSort=--&filterBIR=N"; $root = @simplexml_load_file($url); if ($root) { $data = get_object_vars($root); $response = $data['response']; $class = $response->williamhill->class; $attClass = $class->attributes(); $types = $class->type; foreach ($types as $_type) { $_attributeType = $_type->attributes(); $markets = $_type->market; $html = ''; foreach ($markets as $_market) {$_attributeMarket = $_market->attributes(); $participants = $_market->participant; foreach ($participants as $_participants) {$_attributeParticipant = $_participants->attributes(); $name = $_attributeParticipant["name"]; $odds = $_attributeParticipant["odds"]; $race = $_attributeMarket["name"]; echo $name . " - " . $odds . " - " . $race ?><br/> <?php if ($mysqli->connect_error) {die('Connect Error: ' . $mysqli->connect_error);} if ($stmt = $mysqli->query("SELECT * FROM races WHERE name = '$name' and race = '$race' ")) { $row_cnt = $stmt->num_rows; $stmt->close();} if ($row_cnt > 0) { $stmt = $mysqli->prepare("UPDATE races SET odds = ?, race = ? WHERE name = ?"); $stmt->bind_param('sss', $odds, $race, $name); $stmt->execute(); $stmt->close(); } else if ($name !=="2nd Favourite") { $stmt = $mysqli->prepare("INSERT INTO races VALUES (?, ?, ?)"); $stmt->bind_param('sss', $name, $odds, $race); $stmt->execute(); $stmt->close(); } } } } } else { ?> <meta http-equiv="refresh" content="3 ;url=<?php echo $_SERVER['PHP_SELF']; ?>"><?php } ob_flush(); ?></body></html>
  11. Just what I was looking for. Thankyou.
  12. Hi, I'm trying to prevent strings that read "Favourite" or" 2nd Favourite" from being inserted into my database. I've looked at the manual and I think that i'm using == correctly. Perhaps i'm going wrong elsewhere? <?php if ($mysqli->connect_error) {die('Connect Error: ' . $mysqli->connect_error);} if ($stmt = $mysqli->query("SELECT * FROM races WHERE name = '$name' and race = '$race' ")) { $row_cnt = $stmt->num_rows; $stmt->close();} if ($row_cnt > 0) { $stmt = $mysqli->prepare("UPDATE races SET odds = ?, race = ? WHERE name = ?"); $stmt->bind_param('sss', $odds, $race, $name); $stmt->execute(); $stmt->close(); } else if (($name !== "Favourite") OR ($name !== "2nd Favourite")) { $stmt = $mysqli->prepare("INSERT INTO races VALUES (?, ?, ?)"); $stmt->bind_param('sss', $name, $odds, $race); $stmt->execute(); $stmt->close(); } } } } } else { ?>
  13. I have an xml feed; http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=2&marketSort=--&filterBIR=N It's really quite unreliable and this is what I would like to do... read the xml file at 5 minute intervals. If the xml is available then save the data to an sql table (MySql) If the xml is not available then keep trying to read MySql table if the data already exists. Whilst I appreciate this is something I need to read up on, is there anybody experienced with XML and PHP skills, that could give me a few pointers please?
  14. Have you started the session?
  15. For some reason i'm not passing any get parameters. Is my syntax out? (line 33) I'm using dreamweaver's syntax highlighter and it isn't showing any errors. The form takes me to: URL/update_win.php? (note no 'id= ? ' Any help would be great. <?php //connection if ($mysqli->connect_error) { die('Connect Error: ' . $mysqli->connect_error); } $query = "SELECT id, date, horse, course, odds, time, tip, description FROM toptips order by date desc"; $result = $mysqli->query($query); while($row = $result->fetch_array()) { $rows[] = $row; } foreach($rows as $row) { $date = $row['date']; $date = date("d/m/y", strtotime($date)); $id = $row['id']; echo '<div style= "width:600px;"> <div style="float:left; width:400px; margin-bottom:10px; margin-top10px;"> ('.$date.") " . $row['time'] . " " . $row['course'] . " - " . $row['horse'] . " " . $row['odds'] . " " . '<img src="' . $row['tip'] . '.png" alt=" '. $row['tip'] .' " height="42" width="42" style="float:right"><br>'. $row['description'] . '</div> <div style= "float:right; width: 50px; margin-left:150px;"> <form method="get" action="update_win.php?id='.$id.'"> <input type="submit" value="add win"/> </form> </div> </div> <div style="clear:both"/> <hr/>' ; } $result->close(); $mysqli->close(); ?>
  16. What is the right way of binding results when you select * in a mysqli query? Do I have to list every table field, when binding, regardless of wether I need them? $stmt = $mysqli->stmt_init(); if ($stmt->prepare("SELECT * FROM toptips")) { $stmt->execute(); $stmt->bind_result($description); //causes error $stmt->fetch(); $stmt->close(); } $mysqli->close(); echo $description;
  17. I'm using a jquery datepicker, that outputs dates in the following format 04/30/2013 I've set the date column in mysql table as a date type, however when I submit the above date to the table all I get is 0000-00-00 Do I need to replace the forward slashes with dashes, for this to work? also am I right to think that, as the submitted date contains slashes, I should be binding the date as a string? <?php //an extract from my code $stmt = $mysqli->prepare("INSERT INTO toptips VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param('isssssssss', $id, $time, $date, $course, $horse, $place, $odds, $description, $win, $tip); //end of extract ?>
  18. Is there a work around for when I want to use construct keywords within my code? Eg. return $array_name[quantity]="$_POST[quantity]"; $array_name[invoice]="$_POST[invoice]"; $array_name[custom]="$_POST[custom]"; // $array_name[return] = http://workaround.how
  19. You should use form method post, or you will display these parameters within the URL and the users will be able to see the longitude and latitude anyway. If you want to use the form to pass information that you do not want to display then you can use input type = hidden.
  20. You could read up on header and isset
  21. Thankyou, i'm open to any suggestions, i'm new to the whole preparing statements and using placeholders!
  22. The below updates records for the month of jan, feb, mar ect although I'm expecting only records that have the month of feb to be updated. Is my update syntax wrong somhow? Also how can I echo the update statement whilst using mysqli? Many thanks for any help. $id = ''; $name = 'the novice tipster'; $year = 2013; $month = 'feb'; $wins = 12; if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error());exit();} if ($stmt = $mysqli->query("SELECT * FROM compare WHERE name = '$name' and month = '$month' and year = '$year' ")) { $row_cnt = $stmt->num_rows; printf("Result set has %d rows.\n", $row_cnt); $stmt->close();} if ($row_cnt > 0) { $stmt = $mysqli->prepare("UPDATE compare SET wins = ? WHERE name = ? AND month = ? AND year = ? "); $stmt->bind_param('isii', $wins, $name, $month, $year); $stmt->execute(); $stmt->close(); }
  23. Thank you for the reply. I now have: Affected rows (SELECT): 0 However in my database I have duplicate rows with the data -> $name = "ed"; $year = 2013; $month = "may"; $wins = 48; Im expecting affected rows to read : 4
×
×
  • 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.