Jump to content

webguync

Members
  • Posts

    951
  • Joined

  • Last visited

Posts posted by webguync

  1. I need some assistance with an error I get when trying to submit a form to my email address.

    the error is this:

     

    Warning: mail() [function.mail]: SMTP server response: 555 syntax error (#5.5.4) in E:\Contact\process.php on line 74

    Sorry, unexpected error. Please try again later

     

    the form code is

     

    <form id="form" action="process.php" method="post" name="ContactForm">
    
       	 <label for="Name">Name</label>
       	 <input type="text" name="name" id="name" />
       	 <label for="email">E-mail</label>
       	 <input type="text" name="email" id="email" />
         <label for="website">Website</label>
       	 <input type="text" name="website" id="website" />
          <label for="message">Message</label>
       	 <textarea class="resizable" name="comment">
    </textarea>
        	 <input type="submit" name="submit" id="submit" value="Submit">
        </form>
    
    and the process code
    
    [code=php:0]
    
    <?php
    
    //Retrieve form data. 
    //GET - user submitted data using AJAX
    //POST - in case user does not support javascript, we'll use POST instead
    $name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
    $email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
    $website = ($_GET['website']) ?$_GET['website'] : $_POST['website'];
    $comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment'];
    
    //flag to indicate which method it uses. If POST set it to 1
    if ($_POST) $post=1;
    
    //Simple server side validation for POST data, of course, you should validate the email
    if (!$name) $errors[count($errors)] = 'Please enter your name.';
    if (!$email) $errors[count($errors)] = 'Please enter your email.'; 
    if (!$comment) $errors[count($errors)] = 'Please enter your comment.'; 
    
    //if the errors array is empty, send the mail
    if (!$errors) {
    
    //recipient
    $to = 'My Name <email@gmail.com>';	
    //sender
    $from = $name . ' <' . $email . '>';
    
    //subject and the html message
    $subject = 'Comment from ' . $name;	
    $message = '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>
    <table>
    	<tr><td>Name</td><td>' . $name . '</td></tr>
    	<tr><td>Email</td><td>' . $email . '</td></tr>
    	<tr><td>Website</td><td>' . $website . '</td></tr>
    	<tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>
    </table>
    </body>
    </html>';
    
    //send the mail
    $result = sendmail($to, $subject, $message, $from);
    
    //if POST was used, display the message straight away
    if ($_POST) {
    	if ($result) echo 'Thank you! I have received your message.';
    	else echo 'Sorry, unexpected error. Please try again later';
    
    //else if GET was used, return the boolean value so that 
    //ajax script can react accordingly
    //1 means success, 0 means failed
    } else {
    	echo $result;	
    }
    
    //if the errors array has values
    } else {
    //display the errors message
    for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
    echo '<a href="form.php">Back</a>';
    exit;
    }
    
    
    //Simple mail function with HTML header
    function sendmail($to, $subject, $message, $from) {
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: ' . $from . "\r\n";
    
    $result = mail($to,$subject,$message,$headers);
    
    if ($result) return 1;
    else return 0;
    }
    
    ?>
    
    

     

     

     

    [/code]

  2. Hi, I have some code which displays my blog post in a foreach loop, and I want to add some social sharing code(FB like button, share on Twitter etc.), but the problem is the way I have my code now, creates 3 instances of the sharing buttons, but if you like one post, all three are liked and any thing you do affects all of the blog post. How can I fix this?

     

    <?php
    include ("includes/includes.php");
    
    $blogPosts = GetBlogPosts();
    
    foreach ($blogPosts as $post)
    {
    	echo "<div class='post'>";
    	echo "<h2>" . $post->title . "</h2>";
    	echo "<p class='postnote'>" . $post->post . "</p";
    	echo "<span class='footer'>Posted By: " . $post->author . "</span>";
    	echo "<span class='footer'>Posted On: " . $post->datePosted . "</span>";
    	echo "<span class='footer'>Tags: " . $post->tags . "</span>";
    	echo '
    <div class="addthis_toolbox addthis_default_style ">
    <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
    <a class="addthis_button_tweet"></a>
    <a class="addthis_counter addthis_pill_style"></a>
    </div>
    <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
    <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=webguync"></script>';
    
    	echo "</div>";
    }
    
    
    ?>
    

  3. well as I interpret this is what I need to do.

     

    var $jq = JQuery.noConflict();
    $jq(document).ready(function () {
        $jq('img.menu_class').click(function () {
    $jq('ul.the_menu').slideToggle('medium');
        });
    });
    

     

    but on a page I have a JQuery slider menu (the code above), the menu doesn't work on the same page as a form which also uses the mootools.js library to submit data.

     

    one or the other works but not both.

     

  4. Hi,

     

    I am trying to get a facebook like button displayed under each of my blog post, but so far I am just getting three like buttons displayed above the blog post instead of below each one. Below is the function code to display my blog post and also where I cam currently placing the FB like button code.

     

    <?php
    include 'blogpost.php';
    
    $connection = mysql_connect('localhost', 'username', 'pw') or die ("<p class='error'>Sorry, we were unable to connect to the database server.</p>");
    $database = "DBName";
    mysql_select_db($database, $connection) or die ("<p class='error'>Sorry, we were unable to connect to the database.</p>");
    
    
    function GetBlogPosts($inId=null, $inTagId =null)
    {
    if (!empty($inId))
    {
    	$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC LIMIT 2"); 
    }
    else if (!empty($inTagId))
    {
    	$query = mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" . $tagID . " ORDER BY blog_posts.id DESC");
    }
    else
    {
    	$query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
    }
    
    $postArray = array();
    while ($row = mysql_fetch_assoc($query))
    {
    	$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['postfull'], $row["author_id"], $row['date_posted']);
    
    	array_push($postArray, $myPost);
    	echo '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like show_faces="true" width="450"></fb:like>';//this is where I am currently implementing the FB Like button
    }
    return $postArray;
    }
    ?>
    

  5. I have a form which is working, but the client wanted to add a recapatcha field so I am implementing that and placed the recaptcha code in the same directory as my form. The recaptcha displays, but you can enter in anything and the form still submits, so it's not doing any good!

     

    Not sure where the problem lies exactly, but was hoping for some help if someone has experienced anything similar.

     

    here is my code

     

    in the html

    <li>
    <pre> <script> var RecaptchaOptions = {
    
      theme : 'clean'
    
    }; </script> </pre>
    <?php
              require_once('../ContactUs/recaptchalib.php');
              $publickey = "6LdZX8ASAAAAABUejj-bfZey47TTjN6X-EKfKBwy "; // you got this from the signup page
              echo recaptcha_get_html($publickey);
            ?>
    
    
                     </li>
    

     

    the PHP to submit the Post data

    <?php
    
    if(!$_POST) exit;
    
    $email = $_POST['email'];
    
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
    $error.="Invalid email address entered";
    $errors=1;
    }
    if($errors==1) echo $error;
    else{
    
    $values = array ('name','email','phone','concerning','message','recaptcha_response_field');
    $required = array('name','email','message','recaptcha_response_field');
    
    $your_email = "email@email.com";
    $email_subject = "New Message from our web site!";
    $email_content = "new message:\n";
    
    foreach($values as $value){
      if(in_array($value,$required)){
        if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
        $email_content .= $value.': '.$_POST[$value]."\n";
      }
    }
    
    if(mail($your_email,$email_subject,$email_content)) {
    echo 'Your message has been successfully sent!'; 
    } else {
    echo 'ERROR! please try again or use the email address listed above to contact Sandbox-Band';
    }
    }
    ?>
    
    
    

     

    the recaptchalib.php file is exactly as I downloaded it from their site.

  6. I am having some problems with a page I am working on that utilizes JQuery and MooTools. The JQuery is used on a sliding menu and the Moo Tools is used as a form field checker. i can get one or the other to work, but not both. I did some research at found you can invoke some no conflict code, but what I have tried so far isn't working. My configuration is below.

     

    <?php require('../includes/JQuery.php'); ?>//this is where I have all of my JQuery scripts.
    <script type="text/javascript">//this initializes the slider for the menu
           jQuery.noConflict();//trying the no conflict
       $(document).ready(function () {
        $('img.menu_class').click(function () {
    $('ul.the_menu').slideToggle('medium');
        });
    });
        </script>
    
    <script type="text/javascript" src="../js/mootools.js"></script>
    

     

    as the code is now, the MooTools feature works, but the JQuery does not. I also tried moving the MootTools call above the JQuery call and that enables the JQuery slide to work, but then the MooTools effect doesn't work.

  7. I need help echoing out my SQL statement in the following code. This is a data upload application which uploads a tab delemeted txt file into a MySQL table. I am getting a MySQL error.

     

    MySQL Error: 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 'Group,Title) VALUES ('','','','','' at line 1
    
    

     

    so I need to see the SQL to see why it isn't working. I have tried echoing out but not seeing the echo, so must be doing it wrong.

     

    <?php
    require_once('databaseClass.php');
    
    if ($_POST) {
    foreach($_POST as $key=>$value) {
    	if (empty($value)) {
    		if ($key == 'fileurl') {
    			$errors[] = 'Please provide the URL to the text file containing the data you want to load';
    			}
    		else if ($key == 'dbname') {
    			$errors[] = 'Please provide the name of the database into which you want to load the data';
    			}
    		else if ($key == 'dbuser') {
    			$errors[] = 'Please provide the appropriate Username for the database';
    			}
    		else if ($key == 'db_pw') {
    			$errors[] = 'Please provide the appropriate PW for the database';
    			}
    		else if ($key == 'dbtable') {
    			$errors[] = 'Please provide the database table into which you would like to insert data';
    			}
    		else if ($key == 'fields') {
    			$errors[] = 'Please specify the field names for the table';
    			}
    		}
    	}
    if (!isset($errors)) {
    	$file = fopen('../'.$_POST['fileurl'], 'r');
    	if ($file) {
    		$pattern = '/[\n\r\t]/';
    		while (!feof($file)) {
    			$line = trim(fgets($file));
    			$newline = preg_replace($pattern,'\t',$line);
    			$lines[] = explode('\t',$newline);
    			//echo (fgets($file));
    			}
    		fclose($file);
    		if (count($lines) > 0) {
    			$countSuccess = 0;
    			$fields = explode(',',$_POST['fields']);
    			//$entryCnt = count($tmp);
    			$db = new Database('localhost',$_POST['dbuser'],$_POST['db_pw'],$_POST['dbname'],0);
    			for ($i=0; $i<count($lines); $i++) {
    				$tmp = NULL;
    				$sql = 'INSERT INTO '.$_POST['dbtable'].' (';
    				for ($k=0; $k<count($lines[$i]); $k++) {
    					if (isset($lines[$i][$k]) && $lines[$i][$k] != NULL) {
    						$tmp[] = $fields[$k];
    						}
    					}
    				$sql .= implode(',',$tmp);
    
    				$sql .= ') VALUES (';
    				for ($j=0; $j<count($lines[$i]); $j++) {
    					if (isset($lines[$i][$j]) && $lines[$i][$j] != NULL) {
    						if (is_numeric($lines[$i][$j])) {
    $sql .= $lines[$i][$j];
    echo $sql;//trying to echo out SQL here
    
    }
    else {
      $sql .= "'".mysql_real_escape_string($lines[$i][$j])."'";
    }
    if($j != (count($lines[$i])-1)) {
      $sql .= ',';
    }
    }
    					}
    				$sql .= ')';
    
    				$result = $db->query($sql);
    				if($result) {
    					$countSuccess++;
    					}
    				//escape $sql;
    
    				}
    
    			$db->close();
    			if($countSuccess > 0) {
    				header('Location: '.$_SERVER['PHP_SELF'].'?numInserted='.$countSuccess);
    				}
    			else {
    				$errors[] = 'No data was inserted into the database.  Please check all fields again.';
    				}
    			//print_r($lines);
    			}
    		else {
    			$errors[] = 'No data in designated file';
    			}
    		}
    	else {
    		$errors[] = 'Not able to open specified file.  Please check that it is the correct URL to text file.';
    		}
    	}
    }
    
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>LOAD DATA alternative</title>
    <link href="load.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <?php 
    if ($_GET) {
    echo '<div id="success"><h1>'.$_GET['numInserted'].' rows inserted successfully!</h1></div>';
    }
    ?>
    <div id="loadform">
      <h1>Please fill in all fields.</h1>
      <?php if (isset($errors)) {
    	echo '<div id="alert"><p>Please correct the following:</p><ul>';
    	foreach ($errors as $item) {
    		echo "<li>$item</li>";
    		}
    	echo '</ul></div>';
    	}
    ?>
      <form name="loaddata" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
        <p>Text file URL (RELATIVE to etsi-dataservices.com/):</p>
        <input name="fileurl" type="text" class="longfield" />
        <br />
        <p>DB Name:</p>
        <input name="dbname" type="text" class="shortfield" />
        <br />
        <p>DB Username:</p>
        <input name="dbuser" type="text" class="shortfield" />
        <br />
        <p>DB PW:</p>
        <input name="db_pw" type="password" class="shortfield"  />
        <br />
        <p>DB Table Name:</p>
        <input name="dbtable" type="text" class="shortfield" />
        <br />
        <p>Comma-delimited list of table's field names (e.g.- name,id,score,etc.), in SAME ORDER as text file data:</p>
        <input name="fields" type="text" class="longfield" />
        <br />
        <br />
        <input name="submit" type="submit" />
      </form>
    </div>
    </body>
    </html>
    

  8. thanks for the reply. I think if I did it the with the code you posted I would have to re-do a lot of what I have, and I was hoping for a simpler solution. I realized it will probably help if I post all of the code, so I am doing that now.

     

    blogpost.php...

    <?php
    
    class BlogPost
    {
    
    public $id;
    public $title;
    public $post;
    public $author;
    public $tags;
    public $datePosted;
    
    function __construct($inId=null, $inTitle=null, $inPost=null, $inPostFull=null, $inAuthorId=null, $inDatePosted=null)
    {
    if (!empty($inId))
    {
    	$this->id = $inId;
    }
    if (!empty($inTitle))
    {
    	$this->title = $inTitle;
    }
    if (!empty($inPost))
    {
    	$this->post = $inPost;
    }
    
    if (!empty($inDatePosted))
    {
    	$splitDate = explode("-", $inDatePosted);
    	$this->datePosted = $splitDate[1] . "/" . $splitDate[2] . "/" . $splitDate[0];
    }
    
    if (!empty($inAuthorId))
    {
    	$query = mysql_query("SELECT first_name, last_name FROM people WHERE id = " . $inAuthorId);
    	$row = mysql_fetch_assoc($query);
    	$this->author = $row["first_name"] . " " . $row["last_name"];
    }
    
    $postTags = "No Tags";
    if (!empty($inId))
    {
    	$query = mysql_query("SELECT tags.* FROM blog_post_tags LEFT JOIN (tags) ON (blog_post_tags.tag_id = tags.id) WHERE blog_post_tags.blog_post_id = " . $inId);
    	$tagArray = array();
    	$tagIDArray = array();
    	while($row = mysql_fetch_assoc($query))
    	{
    		array_push($tagArray, $row["name"]);
    		array_push($tagIDArray, $row["id"]);
    	}
    	if (sizeof($tagArray) > 0)
    	{
    		foreach ($tagArray as $tag)
    		{
    			if ($postTags == "No Tags")
    			{
    				$postTags = $tag;
    			}
    			else
    			{
    				$postTags = $postTags . ", " . $tag;
    			}
    		}
    	}
    }
    $this->tags = $postTags;
    }
    
    }
    
    ?>
    

     

    includes.php

     

    <?php
    include 'blogpost.php';
    // Change this info so that it works with your system.
    $connection = mysql_connect('localhost', 'username', 'pw') or die ("<p class='error'>Sorry, we were unable to connect to the database server.</p>");
    $database = "DBName";
    mysql_select_db($database, $connection) or die ("<p class='error'>Sorry, we were unable to connect to the database.</p>");
    
    
    function GetBlogPosts($inId=null, $inTagId =null)
    {
    if (!empty($inId))
    {
    	$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC LIMIT 2"); 
    }
    else if (!empty($inTagId))
    {
    	$query = mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" . $tagID . " ORDER BY blog_posts.id DESC");
    }
    else
    {
    	$query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
    }
    
    $postArray = array();
    while ($row = mysql_fetch_assoc($query))
    {
    	$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['postfull'], $row["author_id"], $row['date_posted']);
    	array_push($postArray, $myPost);
    }
    return $postArray;
    }
    ?>
    
    

     

     

  9. Hey there, I am trying out some tag cloud code, but something is amiss, as am getting no tags displaying. Using PHP/MYSQL and JQuery.

    <?php
    
    //connection information
      $host = "localhost";
      $user = "username";
      $password = "pw";
      $database = "DBName";
    
    //make connection
      $server = mysql_connect($host, $user, $password);
      $connection = mysql_select_db($database, $server);
    
    //query the database
      $query = mysql_query("SELECT * FROM tags");
    
    
    //start json object
    $json = "({ tags:["; 
    
    //loop through and return results
      for ($x = 0; $x < mysql_num_rows($query); $x++) {
        $row = mysql_fetch_assoc($query);
    
    	//continue json object
        $json .= "{tag:'" . $row["tag"] . "',freq:'" . $row["frequency"] . "'}";
    
    	//add comma if not last row, closing brackets if is
    	if ($x < mysql_num_rows($query) -1)
    		$json .= ",";
    	else
    		$json .= "]})";
      }
    
    //return JSON with GET for JSONP callback
    $response = $_GET["callback"] . $json;
    echo $response;
    
    //close connection
    mysql_close($server);
    
    ?>
    
    
    
    

    and the JS

     

    <script type="text/javascript">
    		$(function() {
    
    			//get tag feed
    			$.getJSON("/tagcloud.php?callback=?", function(data) {
    
    				//create list for tag links
    				$("<ul>").attr("id", "tagList").appendTo("#tagCloud");
    
    				//create tags
    				$.each(data.tags, function(i, val) {
    
    					//create item
    					var li = $("<li>");
    
    					//create link
    					$("<a>").text(val.tag).attr({title:"See all pages tagged with " + val.tag, href:"http://localhost/tags/" + val.tag + ".html"}).appendTo(li);
    
    					//set tag size
    					li.children().css("fontSize", (val.freq / 10 < 1) ? val.freq / 10 + 1 + "em": (val.freq / 10 > 2) ? "2em" : val.freq / 10 + "em");
    
    					//add to list
    					li.appendTo("#tagList");
    
    				});
    			});
    		});
    	</script>
    

     

    when i turn on error reporting I get a lot of undefined index notices for tag and frequency so not sure if that is causing the problem or not.

  10. Hi, I have a blog page I am working on and I am trying to make some enhancements that I need some help with. In MySQL I have a table with id, title and post. In my page display I want to enable the user to click on the title and display a post on it's own so the URL would look like www.mysite.com/blog/?id=1 or something like that. Here is the PHP function to display the post from MySQL. all on one page.

     

    function GetBlogPosts($inId=null, $inTagId =null)
    {
    if (!empty($inId))
    {
    	$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC LIMIT 2"); 
    }
    else if (!empty($inTagId))
    {
    	$query = mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" . $tagID . " ORDER BY blog_posts.id DESC");
    }
    else
    {
    	$query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
    }
    
    $postArray = array();
    while ($row = mysql_fetch_assoc($query))
    {
    	$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['postfull'], $row["author_id"], $row['date_posted']);
    	array_push($postArray, $myPost);
    }
    return $postArray;
    }
    

     

     

  11. Hi, I have some code that I think worked at one point, but now it doesn't. I have a side navigation menu which I have set as an include. I want to change CSS styling to a current state to whatever page you are current on. For instance the portfolio link would look like this.

    <li><a id="current" href="../Portfolio/" title="Visit my Portfolio">Portfolio</a></li>
    

     

    Both the page I am trying to set this on and my includes are in separate directories, so I am not sure if that is messing things up, but the id="current is not being set with what I currently have as my code.

     

     

    Here is my current code.

     

    <?php
    $menu = <<< MENU
    <div id="SideMenu">
    <div id="button">
    <img src="../images/NavButton.png" width="184" height="32" class="menu_class" />
    <ul class="the_menu">
    <li><a href="../index.php" title="take me home">Home</a></li>
    <li><a  href="../Portfolio/" title="Visit my Portfolio">Portfolio</a></li>
    <li><a href="../blog/" title="See what I have to say">Blog</a></li>
    <li><a href="../Contact/" title="Get in Touch with me">Contact</a></li>
    </ul>
    </div><!--end button div-->
    </div><!--end SideMenu div-->
    MENU;
    $lines = split("\n", $menu);
    foreach ($lines as $line) {
    $current = false;
    preg_match('/href="([^"]+)"/', $line, $url);
    if (substr($_SERVER["REQUEST_URI"], 0, 5) == substr($url[1], 0, 5)) {
    $line = str_replace('<a h', '<a id="current" h', $line);
    }
    echo $line."\n";
    }
    
    ?>
    

     

    any ideas?

×
×
  • 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.