Jump to content

eMonk

Members
  • Posts

    223
  • Joined

  • Last visited

Everything posted by eMonk

  1. I'm trying this now but still getting an error: Fatal error: Call to undefined method mysqli_stmt::get_result() $result_1 = $qry1->get_result(); I'm new to mysqli prepared statements been reading about it online and in my php book but can't seem to figure this part out?
  2. What am I doing wrong in the code below? $qry1 = $db->prepare("SELECT id FROM user WHERE username = ? AND password = ?"); $qry1->bind_param('ss', $_GET['username'], sha1($_GET['password'])); $qry1->execute(); $db->bind_result($result_1); Fatal error: Call to undefined method mysqli::bind_result()
  3. Ah, I believe I understand it now. The use of bind_param is for the values stored within a table. Thanks!
  4. I want to switch to mysqli_prepared statements but have a question before I start. example 1 $query = $mysqli->prepare('SELECT * FROM users WHERE username = ?'); $query->bind_param('s', $_GET['username']); $query->execute(); example 2 $query = $mysqli->prepare("SELECT * FROM users WHERE username = 'Rick' "); $query->execute(); Is bind_param always necessary and why, for security reasons?
  5. The emails being sent out are notifications that their accounts have been approved along with their login and password. I don't want the people in the BCC recipients list to see all addresses in the list. So, emailing users separating in the foreach loop would be best for this?
  6. Would it be better not to mail and loop or to create a BCC list by imploding the recipients list and send them out in one single blast?
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Control Panel</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../style.css" rel="stylesheet" type="text/css"> </head> <body class="text"> <h1>Pending Ads</h1> <form action="" method="post"> <?php include("../includes/connect.php"); $query_1 = "SELECT id, name, last_updated FROM model WHERE status = 'Pending' ORDER BY last_updated DESC"; $result_1 = $db->query($query_1); $num_results = $result_1->num_rows; echo "<p>Number of results found: ".$num_results."</p>"; for ($i=0; $i <$num_results; $i++) { $row = $result_1->fetch_assoc(); $id = $row['id']; $name = $row['name']; $date = $row['last_updated']; echo "<hr>"; echo "<table width=\"450\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr>"; echo "<td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"".$id."\"></td>"; echo "<td>"; echo "<b>id:</b> $id<br>"; echo "<b>name:</b> $name<br>"; echo "<b>date:</b> $date<br>"; echo "<a href=\"update.php?id=$id\" target=\"_blank\">Edit</a>"; echo "</td>"; echo "</tr>"; echo "</table>"; } ?> <p><hr><input type="submit" name="approve" value="Approve"> <input type="submit" name="delete" value="Delete"></p> <?php include('../pear/Mail-1.2.0b1/Mail.php'); $error = 0; if (isset($_POST['approve']) && $num_results > 0) { foreach ($_POST['checkbox'] as $index => $val) { $query_2 = "SELECT account_id, name, email, DATE_FORMAT(expiry_date, '%b %e, %Y') AS expiry_date_formatted FROM model WHERE id = $val AND status = 'Pending' "; $result_2 = $db->query($query_2); $list = $result_2->fetch_assoc(); $account_id = $list['account_id']; $query_3 = "UPDATE model SET status = 'Active' WHERE id = $val AND status = 'Pending' "; $result_3 = $db->query($query_3); $password = substr(md5(uniqid(rand(),1)),rand(0,21),; $query_4 = "UPDATE member SET password = sha1('$password') WHERE model_id = $val AND account_id = $account_id "; $result_4 = $db->query($query_4); // This part isn't sending out emails $recipients = "".$list['email'].""; $headers['From'] = "someone@somewhere.com"; $headers['To'] = "".$list['email'].""; $headers['Subject'] = "Hello Hello Hello!"; $body = "Hi ".$list['name'].",\n\n" . "Account Number: ".$list['account_id']."\n\n" . "Password: ".$password."\n\n" . "Expiry Date: ".$list['expiry_date_formatted']."\n\n" . "Regards,\n" . "Admin"; $params['sendmail_path'] = "/usr/lib/sendmail"; // Create the mail object using the Mail::factory method $mail_object =& Mail::factory('sendmail', $params); $mail_object->send($recipients, $headers, $body); } } if ($result_1 && $result_2 && $result_3 && $result_4 && $error == 0) { echo "<meta http-equiv=\"refresh\" content=\"0;URL=pending-ads.php\">"; } ?> </form> </body> </html> Everything seems to be working except the email portion. Any ideas?
  8. I switched the following and it seems to be working correctly now.. WHERE CURDATE() > expiry_date
  9. What am I doing wrong in the following query? $query = "SELECT id, expiry_date FROM pets WHERE expiry_date > CURDATE() AND status = 'Active' "; $result = $db->query($query); It's fetching all rows when it should be none. The CURDATE echo is "2012-02-11" And here's some of my expiry_date data: 2012-02-13 2012-02-14 2012-02-19 What am I doing wrong? I'm just trying to select rows where expiry_date is greater then the current date.
  10. eMonk

    Inserting dates

    Ah I see... Thanks PFMaBiSmAd it's working now!
  11. eMonk

    Inserting dates

    How would I get matches between 5 days after the current date? i tried BETWEEN CURDATE() + INTERVAL 5 DAY AND CURDATE() but still no results.
  12. I'm trying to perform the following query but it's fetching 0 results. $query = "SELECT expiry_date FROM pets WHERE expiry_date BETWEEN CURDATE() - INTERVAL 5 DAY AND CURDATE() AND status = 'Active' AND reminder_sent = 0"; $result = $db->query($query); $num_results = $result->num_rows; if ($num_results == 0) { echo "No results found."; exit; } I have a expiry_date column with the data "2012-02-13" so it should be displayed in the results. The column is varchar(10) and I'm entering in the data manually YYYY-MM-DD format. What am I doing wrong?
  13. Update: That worked DavidAM. I couldn't sleep so had to try it lol. Thanks again!
  14. That logic makes sense DavidAM. I'll try it in a few hours when I wakeup and report back. Thanks!
  15. I can't use mysqli_insert_id because I have 2 tables to have auto increment so I'm trying to update the pets table with the updated account id data. How can this be done? $query_1 = "INSERT INTO pets VALUES ('', '', dog)"; $result_1 = $db->query($query_1); The second value is left blank because it's auto incremented in the member table and where account_id goes.
  16. <?php include("../includes/connect.php"); $query_1 = "INSERT INTO pets VALUES ('', '', dog)"; $result_1 = $db->query($query_1); $id = mysqli_insert_id($db); // Here's where I'm having problems fetching the data that was just inserted. $query_2 = "SELECT MAX(id) FROM pets"; $result_2 = $db->query($query_2); $row = $result_2->fetch_assoc(); $pet_id = $row['MAX(id)']; $query_3 = "SELECT account_id FROM member WHERE pet_id = $id"; $result_3 = $db->query($query_3); $row_2 = $result_3->fetch_assoc(); $account_id = $row_2['account_id']; $query_4 = "UPDATE pets SET account_id = $account_id WHERE id = $id"; $result_4 = $db->query($query_4); ?> Any ideas?
  17. It's working now. Weird, the code I had wasn't the same as the one you posted. I probably need more sleep. Thanks again playful!!
  18. The http text is there originally. Don't want it there all the time just when the user enters it in $description.
  19. That worked but now it's removing http:// from the text. How can you keep it intact? Thanks for your help playful. Much appreciated!!
  20. That worked but if the user enters in a url with http:// it doesn't get included in the a href link and appears as normal text. Also for email links: $description = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $description); See any an needed stuff here? Thanks for your help!! I'll be purchasing a book or read online tutorials how this stuff works in the upcoming weeks. It looks confusing at first glance.
  21. I have it in the a function. Here's the complete code: $description = $row['description']; function autolink($description) { $description = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2">\\2</a>', $description); return $description; }
  22. I'm try to add target="_blank" in the following a href so the link opens in a new tab. How can this be done? $description = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2">\\2</a>', $description); I tried <a href="http://\\2" target="_blank">\\2</a> but it didn't work.
  23. if (file_exists("images/".$id."/img01.jpg")) { echo "<a href=\"/v1/images/".$id."/img01.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb01.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a> "; } if (file_exists("images/".$id."/img02.jpg")) { echo "<a href=\"/v1/images/".$id."/img02.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb02.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a> "; } if (file_exists("images/".$id."/img03.jpg")) { echo "<a href=\"/v1/images/".$id."/img03.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb03.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a> "; } if (file_exists("images/".$id."/img04.jpg")) { echo "<a href=\"/v1/images/".$id."/img04.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb04.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a> "; } if (file_exists("images/".$id."/img05.jpg")) { echo "<a href=\"/v1/images/".$id."/img05.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb05.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a> "; } if (file_exists("images/".$id."/img06.jpg")) { echo "<a href=\"/v1/images/".$id."/img06.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb06.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a> "; } if (file_exists("images/".$id."/img07.jpg")) { echo "<a href=\"/v1/images/".$id."/img07.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb07.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a> "; } if (file_exists("images/".$id."/img08.jpg")) { echo "<a href=\"/v1/images/".$id."/img08.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb08.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a> "; } if (file_exists("images/".$id."/img09.jpg")) { echo "<a href=\"/v1/images/".$id."/img09.jpg\" rel=\"lightbox\"><img src=\"/v1/images/".$id."/thumb09.jpg\" class=\"img\" border=\"0\" width=\"60\" height=\"60\"></a>"; } This code works but it just seems a bit tedious. I may also include up to 20 images to check if they exist. Better way to do this?
  24. This is creating the \r\n tags... <textarea name=\"description\" cols=\"70\" rows=\"15\">$description</textarea> The echoed results include the tags automatically. I can get the variables to match but not if it includes line breaks for some reason.
  25. That didn't work either. The only one that removed the \r\n tags was: $user_description = str_replace(array("\r","\n",'\r','\n'),' ', $user_description); Even with the removed \r\n tags it still doesn't match. I also tried the following: $user_description = str_replace("\r\n",'', $user_description); $user_description = preg_replace("/[rn]+[st]*[rn]+/","n",$user_description); $user_description = preg_replace("!\r|\n!m",'',$user_description); $user_description = preg_replace('/\r\n|\r|\n/m','',$user_description); $user_description = trim_chars('$user_description', '\r\n'); $user_description = trim($user_description, '\r\n'); $user_description = str_replace('\r\n', "<br/>", $user_description); $user_description = preg_replace("/\r\n|\n|\r|rn/", "<br />", $user_description);
×
×
  • 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.