PHP - Adding The Email Section To My View Listings Page
hope someone can help me out here, stuck on this page...
This page shows the details of the listing they had just clicked on on the previous page. this part works If the person logged in is the person who is looking at the page, the email section does not show. this part works However, the part I cannot get to work, is when the logged in user types their email message and clicks send email. at this point the details of listing stop showing please SOMEONE HELP ME thanks in advance, i hope Code: [Select] <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Listing Details'; require_once('header.php'); require_once('connectvars.php'); // Show the navigation menu require_once('navmenu.php'); if(isset($_POST['submit'])){ $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the user data from MySQL $query1 = 'SELECT email FROM ob_user WHERE username="' . $user_name . '"'; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); $email = $row1['email']; $to = $email; $subject = 'OurBazzar response to' . $subject . ''; $body = $_POST['email']; $headers = 'From: caleb.jordan.flax@gmail.com'; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } end(); } if (isset($_GET['listing_id']) && isset($_GET['subject']) && isset($_GET['description']) && isset($_GET['price']) && isset($_GET['date']) && isset($_GET['city']) && isset($_GET['state']) && isset($_GET['user_id']) && isset($_GET['category_id'])) { // Grab the score data from the GET $listing_id = $_GET['listing_id']; $title = $_GET['subject']; $description = $_GET['description']; $price = $_GET['price']; $date = $_GET['date']; $city = $_GET['city']; $state = $_GET['state']; $userid = $_GET['user_id']; $categoryid = $_GET['category_id']; } // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the user data from MySQL $query = 'SELECT username FROM ob_user WHERE user_id="' . $userid . '"'; $data = mysqli_query($dbc, $query); $row = mysqli_fetch_array($data); $query1 = 'SELECT name FROM ob_category WHERE category_id="' . $categoryid . '"'; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); $user_name = $row['username']; $category_name = $row1['name']; echo '<table>'; echo '<tr><td colspan="2"><strong>' . $title . '</strong></td></tr>'; echo '<tr><td>Created by: </td><td>' . $user_name . '</td></tr>'; echo '<tr><td>Date created: </td><td>' . $date . '</td></tr>'; echo '<tr><td>Location: </td><td>' . $city . ', ' . $state . '</td></tr>'; echo '<tr><td>Category: </td><td>' . $category_name . '</td></tr>'; echo '<tr><td>Description: </td><td>' . $description . '</td></tr>'; echo '</table>'; if ((isset($_SESSION['username'])) && ($_SESSION['username'] != $user_name)) { ?> <br /> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Send Email to <?php echo $user_name; ?></legend> <label for="email">Message: </label> <input type="text" name="email" /><br /> <input type="submit" value="Send Email" name="submit"> </fieldset> <?php } require_once('footer.php'); ?> Similar Tutorialshi i have got the following issues i am using the following code. Code: [Select] <?php //DB CONNECTION $ROWS = "id,firstname,lastname"; // explode at the comma and insert into an array $test = explode("," , $ROWS); //adds array test to the var sam $sam = array($test); // querys the database $new = mysql_query("SELECT * FROM {$DB_TABLE}"); // while loop to loop through selected fields while ($row = mysql_fetch_array($new)) { foreach ($sam[0] as $v) { echo $row[$v] . $DELIMITER . "<br />"; } } ?> i get the following results. 834(|) Steph(|) Thompson(|) 835(|) Lucy(|) kim(|) 836(|) Iwan(|) Will(|) 837(|) Sarah (|) Good(|) The problem i have is the br tag where do i put it because i need it to output like this. like it shows in the $ROWS variable above "$ROWS = "id,firstname,lastname";"; 834(|)Step(|)Thompson(|) 835(|)Lucy(|)kim(|) 836(|)Iwan(|)Will(|) 837(|)Sarah (|)Good(|) Where do i add the br tag??? Any Help PLease I would love to add a comment section to my music blogging site. Does anyone have some simple code that they would not mind sending me? or at least helping me with this situation? I may not be a PHP wizard, but a view counter seems pretty damn simple and easy to implement. Unless you leave it in my hands... It's a pretty simple problem, so I'm hoping it'll be a simple solution. Every time you load a game on my website, at the top of the php "playgame.php" is a function call: $objGlobal->update_gameplay($gameid); In my functions.class.php is the function declaration: function update_gameplay() { $args = func_get_args(); $getsql = mysql_query("select * from games where gameid = $args[0]"); if($getsql) { $resultgame = mysql_fetch_array($getsql, MYSQL_ASSOC); $timesplayed = $resultgame['timesplayed'] + 1; $updatesql = "update games set timesplayed = '$timesplayed', last_played = now() where gameid = $args[0]"; if(mysql_query($updatesql)) return true; else return false; } } Yet, when I load the playgame page, it adds 1,2 or 3!!! So this means the function is being called 1, 2 or 3 times, but how can that be if it is at the VERY top of the page? Try it yourself on my website, www.gpstudios.com. Click on a game and reload. For some reason, the newer games always add 1, but other older/more popular games add 1, 2 or 3 I've searched for the string "update" and the string "timesplayed" in every file using a program called FileSeek and I can say for certain that the function must be being called multiple times for some reason. What's weirder is that my game reviews (http://www.gpstudios.com/reviews.php) are also having their view counter incremented by 1 or 2 on a page load. Please help me solve this quick. Thanks, -Tom Hi! I'd like to echo a text section from pageB.php to pageA.php Is it possible to mark it up somehow and tell the browser to echo the variable? I'm thinking something like this should work after some alteration: pageA: <?php echo pageb.php/variable; ?> pageB: <?php $variable = ***the content section I want to be displayed on pageA*** "; ?> I'd be very grateful if someone could help me out. (: Can i open a pdf within a page? e.g. within <td> or <table> of htmls so that it appears on a section of a page where someone can just read through and still able to browse the web page. I dont want the PDF downloading or taking the whole page or even opening a new window and filling it. Thanks in advance. Alright guys i have an idea on what am going to do here, although i am unsure that it's the best way to go about it. I am creating a blog and i need to count how many views an article gets in order to display the top 10 most viewed articles. Here is my plan... 1. Add an additional field to my blog posts table called viewed 2. On the view article page have an update method that adds one to the current number on the the coloum viewed 3. When displaying the 10 most viewed articles query it by the heightest number and limet to 5 when i right click to view page source i just saw the javascript calling php as source file , while on page there is table, i need to read that table in database , is there nay way to do that, file_get contents dont work on it its just take javascript not the page table I've got another funny one... I've noticed that sometimes on some of my pages (all of which are generated by PHP), when i click view source, the source it shows me is not from the page i'm looking at. This isn't a problem that affects me in any way (not yet anyway), it's just a bit odd. I've noticed it happens a little more often in chrome than any other browser. Has anyone else noticed anything like this before? I'm intrigued to know the cause. The only real google response was this: http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg144609.html and i haven't seen another issue similar on here. Hello all, i have a feeling im doing something wrong, but i have no idea what. being server-side code, php should not show when you 'view page source' in your browser (or rather it should display as html), correct ? why, then am i seeing php code when i view page source? see attached image Hey everyone, So here is my problem. I have some code to display the amount of views that page has got. In this case it is the thread in my forums section. I have used the same code to show how many people have views a certain persons profile page and that works fine but when I use it on my forum thread page I get this error. Quote 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 'WHERE id='20' LIMIT 1' at line 1 Here is the section of code: Code: [Select] <?php $thread_id = preg_replace('#[^0-9]#i', '', $_GET['id']); $getThreadViews = mysql_query("SELECT view_count FROM forum_posts WHERE id='$thread_id' LIMIT 1") or die (mysql_error()); $row = mysql_fetch_assoc($getThreadViews); $counter = $row['view_count']; if($counter == 0){ $counter = 1; $startCounter = mysql_query("INSERT INTO forum_posts (view_count) VALUES ('$counter') WHERE id='$thread_id' LIMIT 1") or die (mysql_error()); } $threadViews = $counter+1; $appendCounter = mysql_query("UPDATE forum_posts SET view_count='$view_count' WHERE id='$thread_id'") or die (mysql_error()); ?> I have checked that there are no spelling errors so just wanted to show it to a fresh pair of eyes because its really starting to annoy me. Thanks in advance for any help. I have a bit of php code that sends an email. I would like to add another email recipient to this code, so that the email is sent to BOTH the post author AND the following email address... help@dealfiles.com
Yes, this is part of a Wordpress plugin. It's a small part of a large plugin that I have a LOT of time investing in setting up, so I can't just look for an alternate plugin. I really need to get this one to work.
Thanks in advance for any and all help with this. Here is the existing code: <?php if (get_post_meta( $post->ID, '_listing_contact_form', true) != '') { echo do_shortcode(get_post_meta( $post->ID, '_listing_contact_form', true) ); } else { $nameError = ''; $emailError = ''; if(isset($_POST['submitted'])) { $url = get_permalink(); $listing = get_the_title(); if(trim($_POST['contactName']) === '') { $nameError = 'Please enter your name.'; $hasError = true; } else { $name = trim($_POST['contactName']); } if(trim($_POST['email']) === '') { $emailError = 'Please enter your email address.'; $hasError = true; } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) { $emailError = 'You entered an invalid email address.'; $hasError = true; } else { $email = trim($_POST['email']); } $phone = trim($_POST['phone']); if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['comments'])); } else { $comments = trim($_POST['comments']); } if(!isset($hasError)) { $emailTo = get_the_author_meta( 'user_email', $post->post_author ); if (!isset($emailTo) || ($emailTo == '') ){ $emailTo = get_option('admin_email'); } $subject = 'Listing Inquiry from '.$name; $body = "Name: $name \n\nEmail: $email \n\nPhone: $phone \n\nListing: $listing \n\nURL: $url \n\nComments: $comments"; $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; wp_mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> Hi all . I have a script , which will display the records from sql . If user wish to view more details of the record , they can click view . Code: [Select] echo "<td>$objResult[Message] </td>"; echo "<td>$objResult[mylocaltime] </td>"; echo '<td><a href="historydetails.php?id=' . $objResult[Groupnumber] . '">View</a></td>'; Then it will link to a page which will display more details according to the Groupnumber . Which will display 2 records per page . Code: [Select] <? $groupnumber = $_GET['id']; $strSQL = "SELECT * FROM esp WHERE Groupnumber='$groupnumber'"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 2; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL .=" order by id DESC LIMIT $Page_Start , $Per_Page"; $objQuery = mysql_query($strSQL); ?> But when I click next to view the third record , then the table will become blank . Is it because when I click to next page , the $groupnumber is no longer getting the data from $_GET['id'] ? Or is there any other problem? Thanks for every reply . I am sending emails using PHPMailer. My configuration is below.
When adding a link to the message, should I use anchor tags? Both seem to work. What is the implication to recipients who are not using HTML email?
On a side note, if anything below seems wrong, please let me know.
Thanks
$msg='<p>Hello</p><p>Link: http://phpmailer.worxware.com/</p><p>Link: http://phpmailer.worxware.com</p><a href="http://phpmailer.worxware.com">http://phpmailer.worxware.com</a>'; $mail = new myPHPMailer(true); $mail->AddReplyTo('myEmail@xxx.com', 'Michael Reed'); $mail->SetFrom('myEmail@xxx.com', 'Michael Reed'); $mail->AddAddress('johndoe@xxx.com', 'John Doe'); $mail->Subject = "Here is your email"; //AltBody property need not be sent since PHPMailer will create an alternate automatically $mail->MsgHTML($message); return ($mail->Send()); class myPHPMailer extends PHPMailer { public function __construct($allow_exceptions=false){ $this->isSMTP(); $this->SMTPDebug = 0; $this->Host = "smtp.gmail.com"; $this->Port = 587; $this->SMTPSecure='tls'; // sets the prefix to the server. Used for gmail only. $this->SMTPAuth = true; $this->Username = 'xxx'; $this->Password = 'xxx'; } } Hi I am gathering numbers in an array and then want to add together all the numbers attached to the same email so I end up with the Grand totals of each email address. Below is the code I am using to pull out the email and attached values Code: [Select] $getcashdonationsdb = $wpdb->get_results("SELECT * FROM cashdepo WHERE cause='$causename' AND status='2' ORDER BY user DESC"); $i = 0; while($i < $count2) { foreach($getcashdonationsdb as $getcashdonationsdb){ $dataa[$i]['email'] = $getcashdonationsdb->email; $dataa[$i]['cost'] = $getcashdonationsdb->cost; } } Anyone have any suggestions how I can achieve this most efficiently. I am trying to add my email to a contact form to where a customer would fill in a few boxes and hit send and i would receive. Where would i find the code to enter it? thanks, w i have the following problem i have a mail id displayed on the site. on clicking the link the email address should get saved to the outlook express contacts. all i have been doing is reading through but did not find any revelance to implement any help of any sort will be appreciated thanks Hi everyone, this is my first post. i am starting to learn flash and other programs and haven't started on PHP yet. I have purchased a template that i am modifying and the problem i am having is that my server is a windows one and doesn't like the code that i have attached. It is very simple and doesn't offer any protection with strip slashes etc but the real problem is that i need to add the smpt auth. I have tried several lines of code but it doesnt seem to work. I cant change the headers so i am hoping i can get a little help from this community. It is greatly appreciated This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=318858.0 I have a strange problem. When a guest visits my contact-user.php page, they get a message telling them the must login before viewing the page. After the guest logs in, they view the same page and it tells them they have to login again (keeps on looping). But if they manually refresh that page with the "you must be logged in" message, it recognizes the login and lets them in. How can I get this page to immediately recognize that the user is logged in and not require them to refresh the page manually? Here is my code for contact-user.php <?php session_start(); header("Cache-Control: private, max-age=10800, pre-check=10800"); header("Pragma: private"); header("Expires: " . date(DATE_RFC822,strtotime("+2 day"))); include("connection.php"); mysql_select_db("database"); if (isset($_SESSION['username'])) { ******** MY HTML PAGE CONTENT ******** } else { echo "<meta http-equiv='REFRESH' content='2;url=http://www.mysite.com/login.php'> <center><font color='#EE0000'><p>You must be logged in before negotiating. You will now be redirect to the login page.</p></font></center>"; } ?> Here is my code for login.php script: <?php include("connection.php"); mysql_select_db("database"); session_start(); if(isset($_POST['login'])){ $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $tUnixTime = time(); $sGMTMySqlString = gmdate("Y-m-d H:i:s", $tUnixTime); if (!$username || !$password) { print "Please fill out all fields."; exit; } $logres = mysql_num_rows(mysql_query("SELECT * FROM members WHERE username = '$username' and password = '$password'")); if ($logres <= 0) { print "Login failed. If you have not already, please signup. Otherwise, check your spelling and login again."; exit; } else { $_SESSION['username'] = $username; if (isset($_SESSION)) { echo'You are now logging in'; mysql_query("UPDATE members SET activity = '$sGMTMySqlString' WHERE username = '$username'"); } else { echo "You are not logged in!"; } echo'<html><head><meta http-equiv="REFRESH" content="1;url=http://www.mysite.com/members/' . $_SESSION['username'] . '/"></head><body></body></html>'; exit; } } ?> Hey guys, Just lately I have been trying to start a specific project for myself. I started off by designing the pages etc on HTML, and then a friend of mine helped me convert them to PHP.
At the moment, when a user registers to the site, they only require to enter a Username and Password. I would like to add their email to it too, due to adding slightly extra security. It would also be used for future reasons such as sending emails out etc.
I'm not sure about adding this, I know that most likely it is going to be VERY similar to how it already is, but I couldn't seem to get it to work when I tried.
Ill give the coding which I am using for this below (the documents which I believe would need editing) :
Register.php
<?php require($_SERVER['DOCUMENT_ROOT'] . '/TruckWorld/includes/config.php'); $sOutput .= '<div id="register-body">'; if (isset($_GET['action'])) { switch (strtolower($_GET['action'])) { case 'register': // If the form was submitted lets try to create the account. if (isset($_POST['username']) && isset($_POST['password'])) { if (createAccount($_POST['username'], $_POST['password'])) { $sOutput .= '<h1>Account Created</h1><br />Your account has been created. You can now login <a href="login.php">here</a>.'; }else { // unset the action to display the registration form. unset($_GET['action']); } }else { $_SESSION['error'] = "Username and or Password was not supplied."; unset($_GET['action']); } break; } } // If the user is logged in display them a message. if (loggedIn()) { $sOutput .= '<h2>Already Registered</h2> You have already registered and are currently logged in as: ' . $_SESSION['username'] . '. <h4>Would you like to <a href="login.php?action=logout">logout</a>?</h4> <h4>Would you like to go to <a href="index.php">site index</a>?</h4>'; // If the action is not set, we want to display the registration form }elseif (!isset($_GET['action'])) { // incase there was an error // see if we have a previous username $sUsername = ""; if (isset($_POST['username'])) { $sUsername = $_POST['username']; } $sError = ""; if (isset($_SESSION['error'])) { $sError = '<span id="error">' . $_SESSION['error'] . '</span><br />'; } $sOutput .= '<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Truck World - Register</title> <!-- Core CSS - Include with every page --> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="font-awesome/css/font-awesome.css" rel="stylesheet"> <!-- SB Admin CSS - Include with every page --> <link href="css/sb-admin.css" rel="stylesheet"> </head> <body> <div align=center><img src="images/logintitle.png" alt="LoginTitle" /></div> <div class="container"> <div class="row"> <div class="col-md-4 col-md-offset-4"> <div class="login-panel panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">Register To Join Truck World!</h3> </div> <div class="panel-body"> ' . $sError . ' <form name="register" method="post" action="' . $_SERVER['PHP_SELF'] . '?action=register"> <fieldset> <div class="form-group"> <input class="form-control" placeholder="Username" name="username" type="username" autofocus=""> </div> <div class="form-group"> <input class="form-control" placeholder="Password" name="password" type="password" value=""> </div> <div class="form-group"> <input class="form-control" placeholder="Email" name="email" type="email" value=""> </div> <!-- Change this to a button or input when using this as a form --> <input type="submit" class="btn btn-lg btn-success btn-block" name="submit" value="Register" /> <a href="login.php"class="btn btn-lg btn-success btn-block">Login</a> </fieldset>'; } $sOutput .= '</div> </div> </div> </div> </div> <div align=center><h5><small>Copyright - Lewis Pickles 2014 - All Rights Reserved</small></h5></div> <!-- Core Scripts - Include with every page --> <script src="js/jquery-1.10.2.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> <!-- SB Admin Scripts - Include with every page --> <script src="js/sb-admin.js"></script> </body> </html> '; // display our output. echo $sOutput; ?>Functions.php (Not sure if this would need editing, I think it might, Correct me if I'm wrong) <?php function createAccount($pUsername, $pPassword) { // First check we have data passed in. if (!empty($pUsername) && !empty($pPassword)) { $uLen = strlen($pUsername); $pLen = strlen($pPassword); // escape the $pUsername to avoid SQL Injections $eUsername = mysql_real_escape_string($pUsername); $sql = "SELECT username FROM users WHERE username = '" . $eUsername . "' LIMIT 1"; // Note the use of trigger_error instead of or die. $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); // Error checks (Should be explained with the error) if ($uLen <= 4 || $uLen >= 11) { $_SESSION['error'] = "Username must be between 4 and 11 characters."; }elseif ($pLen < 6) { $_SESSION['error'] = "Password must be longer then 6 characters."; }elseif (mysql_num_rows($query) == 1) { $_SESSION['error'] = "Username already exists."; }else { // All errors passed lets // Create our insert SQL by hashing the password and using the escaped Username. $sql = "INSERT INTO users (`username`, `password`) VALUES ('" . $eUsername . "', '" . hashPassword($pPassword, SALT1, SALT2) . "');"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); if ($query) { return true; } } } return false; } /*********** string hashPassword (string $pPassword, string $pSalt1, string $pSalt2) This will create a SHA1 hash of the password using 2 salts that the user specifies. ************/ function hashPassword($pPassword, $pSalt1="2345#$%@3e", $pSalt2="taesa%#@2%^#") { return sha1(md5($pSalt2 . $pPassword . $pSalt1)); } /*********** bool loggedIn verifies that session data is in tack and the user is valid for this session. ************/ function loggedIn() { // check both loggedin and username to verify user. if (isset($_SESSION['loggedin']) && isset($_SESSION['username'])) { return true; } return false; } /*********** bool logoutUser Log out a user by unsetting the session variable. ************/ function logoutUser() { // using unset will remove the variable // and thus logging off the user. unset($_SESSION['username']); unset($_SESSION['loggedin']); return true; } /*********** bool validateUser Attempt to verify that a username / password combination are valid. If they are it will set cookies and session data then return true. If they are not valid it simply returns false. ************/ function validateUser($pUsername, $pPassword) { // See if the username and password are valid. $sql = "SELECT username FROM users WHERE username = '" . mysql_real_escape_string($pUsername) . "' AND password = '" . hashPassword($pPassword, SALT1, SALT2) . "' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); // If one row was returned, the user was logged in! if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $_SESSION['username'] = $row['username']; $_SESSION['loggedin'] = true; return true; } return false; } ?>The Database for the email is as follows: Edited by Lewis2212, 06 August 2014 - 10:20 AM. |