Jump to content

HoTDaWg

Members
  • Posts

    275
  • Joined

  • Last visited

Posts posted by HoTDaWg

  1. post your code, and what you have tried.

     

    Also, just ask one for help with one feature at a time dude. We aren't gonna teach you how to grow a forest but we can help you figure out why one of the seeds you planted isnt sprouting.

     

    as for sending an email to multiple people here is an example of what your code might look like:

    <?php
    //assuming the user enters "admin@example.com,fake@fake.com,hi@hi.com" under the TO: section
    $to = $_POST['to'];
    $newto = explode(',',$to);
    foreach ($newto as $indvidual){
         sendAnEmail();
    }
    ?>
    

    its pretty basic, but it should give you an idea.

     

    HoTDaWg

     

  2. hi there,

     

    when i run calendar.php, its function ShowCalendar works fine as i echo its returned variable. However, when i require_once the file(calendar.php) and echo the function from another file it gives me the error:Only Variables Should be passed by Reference. It says the error is on line 25:

    <?php
    //here is the area around line 25
    $dateformatted = $today['month'] . ' ' . $today['year'];
    
    $days = array();   
        $query = "SELECT post_id,post_date FROM blog_posts";
        $result = mysqli_query($connection1,$query);
        while($row = mysqli_fetch_array($result)){
    	if (settype(date('F Y',$row['post_date']),"string") == settype($dateformatted,"string")){#is the problem how I formatted this?
    		array_push($days,date('j',$row['post_date']));
    	}
    }
    ?>
    

     

    here is the full calendar.php:

    <?php
    
    /**
    * @author PHPtoys.com administrator
    * @modified HoTDaWg
    * @copyright 2009
    */
    error_reporting(E_ALL);
    //calendar taken from http://www.phptoys.com/e107_plugins/content/content.php?content.33.1
    //the script was merely changed to create a link that shows up everytime a post was created 
    //on a certain day.
    function ShowCalendar(){
        //dont worry, this isnt my actual db username/pass hahaha
       //this is also NOT how i call upon my $connection variable, i just set it like this for testing purposes
        $connection1 = mysqli_connect('localhost','root','','blog'); 
        // Get key day informations. 
        // We need the first and last day of the month and the actual day
        $today    = getdate();
        $firstDay = getdate(mktime(0,0,0,$today['mon'],1,$today['year']));
        $lastDay  = getdate(mktime(0,0,0,$today['mon']+1,0,$today['year']));
    $dateformatted = $today['month'] . ' ' . $today['year'];
    
    $days = array();   
        $query = "SELECT post_id,post_date FROM blog_posts";
        $result = mysqli_query($connection1,$query);
        while($row = mysqli_fetch_array($result)){
    	if (settype(date('F Y',$row['post_date']),"string") == settype($dateformatted,"string")){ #is the problem how I formatted this?
    		array_push($days,date('j',$row['post_date']));
    	}
    }
        $fullstring = '';
        // Create a table with the necessary header informations
        $fullstring .= '<table>';
        $fullstring .= '  <tr><th colspan="7">'.$today['month']." - ".$today['year']."</th></tr>";
        $fullstring .= '<tr class="days">';
        $fullstring .= '  <td>Mo</td><td>Tu</td><td>We</td><td>Th</td>';
        $fullstring .= '  <td>Fr</td><td>Sa</td><td>Su</td></tr>';
        
        
        // Display the first calendar row with correct positioning
        $fullstring .= '<tr>';
        for($i=1;$i<$firstDay['wday'];$i++){
            $fullstring .= '<td> </td>';
        }
        $actday = 0;
        for($i=$firstDay['wday'];$i<=7;$i++){
            $actday++;
            if ($actday == $today['mday']) {
                $class = ' class="actday"';
            } else {
                $class = '';
            }
            if(in_array($actday,$days)){
    		$fullstring .= "<td$class><a href='viewentries.php?year=month=day='>$actday</a></td>";
    	}else{
    		$fullstring .= "<td$class>$actday</td>";
    	}
        }
        $fullstring .= '</tr>';
        
        //Get how many complete weeks are in the actual month
        $fullWeeks = floor(($lastDay['mday']-$actday)/7);
        
        for ($i=0;$i<$fullWeeks;$i++){
            $fullstring .= '<tr>';
            for ($j=0;$j<7;$j++){
                $actday++;
                if ($actday == $today['mday']) {
                    $class = ' class="actday"';
                } else {
                    $class = '';
                }
            if(in_array($actday,$days)){
    			$fullstring .= "<td$class><a href='viewentries.php?year=month=day='>$actday</a></td>";
    		}else{
    			$fullstring .= "<td$class>$actday</td>";
    		}
            }
           $fullstring .= '</tr>';
        }
        
        //Now display the rest of the month
        if ($actday < $lastDay['mday']){
           $fullstring .= '<tr>';
            
            for ($i=0; $i<7;$i++){
                $actday++;
                if ($actday == $today['mday']) {
                    $class = ' class="actday"';
                } else {
                    $class = '';
                }
                
                if ($actday <= $lastDay['mday']){
    	        if(in_array($actday,$days)){
    				$fullstring .= "<td$class><a href='viewentries.php?year=month=day='>$actday</a></td>";
    			}else{
    				$fullstring .= "<td$class>$actday</td>";
    			}
                }
                else {
                    $fullstring .= '<td> </td>';
                }
            }
            
            
            $fullstring .= '</tr>';
        }
        
        $fullstring .= '</table>';
    return $fullstring;
    }
    ?>
    

    the area around line 25 basically finds all the posts in my database where the Month and Year are equal to the current month and year. It stores the days of such posts into an array and later on when the calendar is being created, it finds the appropriate days and puts a link around them.

     

    again, the problem is the function does not work when im using it from another file.

     

    any help would be greatly appreciated,

    thanks,

     

    HotDaWg

  3. hahahaha

    never mind

    simple typo

    take a look at the brackets for DbReach:P

     

    heres how the function should have looked:

    <?php
    //...previous code here...
    public function DbReach($datarbase)
    {
    	$this->datarbase = $datarbase;
    	$this->result = mysql_select_db($this->datarbase,$this->dalink) or die (mysql_error());
    	if ($this->result)
    	{			
    		$this->result_message = " successfully established connection with database <br>";
    	}
    	else
    	{
    		$this->result_message = " failed to connect to database <br>";
    	}	
    }
    

     

    thanks for the help guys! :)

     

    sorry i didnt mean to waste time like this...

     

  4. hi there,

     

    im having difficulty passing simple text in quotes to a method.

     

    here is the class:

    <?php
    error_reporting(E_ALL);
    class DbActions
    {
    protected $dausername = "******";
    protected $dapassword = "********";
    public $datarbase;
    protected $hostess = "localhost";
    var $result;
    var $result_message;
    var $dalink;
    
    function DbConnect ()
    {
    	$this->dalink = mysql_connect($this->hostess,$this->dausername,$this->dapassword);
    	if (!$this->dalink)
    	{
    		mysql_error();
    		echo "Failed to connect to database. <br>";
    		exit();
    	} 
    }
    
    public function DbReach($databarbase)
    {
    	echo $this->datarbase;
    	$this->result = mysql_select_db($this->datarbase,$this->dalink) or die (mysql_error());
    	if ($this->result)
    	{			
    		$this->result_message = " successfully established connection with database <br>";
    	}
    	else
    	{
    		$this->result_message = " failed to connect to database <br>";
    	}		
    }
    }
    ?>
    

     

    i call upon the class and function with:

    <?php
    require ("connect.php");
    
    $connection = new DbActions();
    $connection -> DbConnect();
    $connection -> DbReach("main");
    echo $connection->result_message;
    ?>
    

     

    however, the mysql error message it gives me is

    No database selected

     

    to reiterate,

    I am trying to pass the word "main" to the function DbReach but i dont think im doing it right?

    any idea how to do this properly?

     

    thanks

     

    HoTDaWg

  5. hi there

    this script reads a bunch of words from a text file and adds them to an array. Ultimately it creates this string with either just a word or a number added to it or a letter added to it.  The problem is everytime there is a word, it adds a space behind it? wats up with this... ive tried ereg_replace, str_replace, and ereg replace at the ultimate string even but it still doesnt work!

    any ideas?

    <?php
    error_reporting(E_ALL);
    $username = "hi29a";
    $password = "hello";
    
    #assign a letter to a key in an array<br>
    #split array or use { } to refer to a specific character within a string
    $stringofletters = "abcdefghijklmnopqrstuvwxyz";
    $letters = str_split($stringofletters);
    
    #count how many lines there are in total of the username text document
    $linecount = 0;
    if ($file = fopen("usernames.txt","r")) 
    {
    while(!feof($file))
    {
    	$line = fgets($file,5000);
    	$linecount ++;
    }
    }
    
    #for each username, add that username to an array.
    $names = array();
    if ($file = fopen("usernames.txt","rb"))
    {
    for($i = 1; $i <= $linecount; $i++)
    {
    	$line = fgets($file,5000);
    	$names [$i] = strtolower($line);
    }
    } else {
    echo "could not open file.";
    }
    
    #develop username, one represents just a word, two represents a word and a number, three represents a word, a number, and a letter at the end
    $selection = rand(1,3);
    switch($selection)
    {
    case 1:
    	$random = rand(1,$linecount);
    	$attempt = $names[$random];
    	break;
    case 2:
    	$random = rand(1,$linecount);
    	$attempt = $names[$random].rand(1,999);
    	break;
    case 3:
    	$random = rand(1,$linecount);
    	$letter = rand(1,24);
    	$attempt = "$names[$random]".rand(1,999)."$letters[$letter]";
    	break;
    }
    $finalattempt = str_replace(' ', '', $attempt); 
    print $finalattempt;
    ?>
    

    thanks!

  6. oh hahah thanks

    thank you its a force of habit from turing:P i guess vb might have the syntax i wouldnt know.

    but now im getting this error:

    Fatal error: Call to undefined function abcdefghijklmnopqrstuvwxyz() in C:\xampp\htdocs\learnphp\hacks\test.php on line 6
    

    im guessing this has to do with my inital question

    here is the updated code

    <?php
    $stringofletters = "abcdefghijklmnopqrstuvwxyz";
    $letters = array();
    for ($i = 1; $i <= strlen($stringofletters); $i ++)
    {
    $letters[$i] = $stringofletters($i);
    }
    ?>
    

    how do i refer to a specific character in that string?

    thanks

  7. lmfao im fresh outta turing so forgive me lol

    here is a basic string manipulation application assigning a letter from a string onto an array:

    <?php
    $stringofletters = "abcdefghijklmnopqrstuvwxyz";
    $letters = array();
    for ($i = 1; $i <= strlen($stringofletters); $i ++)
    {
    $letters($i) = $stringofletters($i); #This is where the problem is
    }
    ?>
    

    im having trouble with pointing to a specific character in the stringofletters. here is the error im getting:

    Fatal error: Can't use function return value in write context in C:\xampp\htdocs\learnphp\hacks\test.php on line 6
    

    how do i go about referring to a specific character in the string?

  8. hey there,

    ive just been working on getting the for loops syntax down but i cant get this simple script to work.

    in summary, this script counts from the start integer to the stop integer (or vice versa depending upon the users selection) by a select number of increments for a selected number of times. but for some reason, it counts correctly but does not repeat the sets of numbers...

    any ideas:S

    <?php
    error_reporting(E_ALL);
    print<<<HTML
    <html>
    <head>
    <title>Activity Seven- ask for a low integer, high integer, increment to count by, how many times to count up or down, and whether to count from HL or LH</title>
    </head>
    <body>
    <form method="post">
    <input type = "text" name = "startint" value="start integer"><br>
    <input type = "text" name = "stopint" value="stop integer"><br>
    <input type = "text" name = "incr" value= "increment"><br>
    <input type = "text" name = "method" value="hl or lh"><br>
    <input type = "text" name = "reps" value= "repetitions"><br>
    <input type = "submit">
    </form>
    HTML;
    if ((isset($_POST['startint'])) && (isset($_POST['stopint'])) &&  (isset($_POST['incr'])) && (isset($_POST['method'])) &&  (isset($_POST['reps'])))
    {
    $startint = $_POST['startint'];
    $stopint = $_POST['stopint'];
    $incr = $_POST['incr'];
    $method = $_POST['method'];
    $reps = $_POST['reps'];
    for ($c = 1; $c <= $reps; $c++)
    {
    	if ($method == "lh")
    	{
    		for ($g = &$startint ; $g <= $stopint ; $g += $incr)
    		{
    			print "<br>$c) " . $g;
    		}
    	} else {
    		for ($g = &$stopint ; $g >= $startint ; $g -= $incr) 
    		{
    			print "<br>$c) " . $g;
    		}
    	}
    }
    }
    ?>
    

    any help would be greatly appreciated

    thanks. 

  9. here is my interpretation lol

    <?php
    print <<<html
    <form method="post">
    <input type="text" name="sentence">
    <input type="submit">
    </form>
    html;
    if (isset($_POST['sentence']))
    {
    $swears = array("fuck","shit","cunt","motherfucker","ass","bitch");
    $sentence = $_POST['sentence'];
    $replacement = "<b> [censored] </b>";
    foreach ($swears as $word)
    {
    	$sentence = ereg_replace($word,$replacement,$sentence);
    }
    print $sentence;
    }
    ?>
    

    just something i whipped up out of curiousity lol

     

     

  10. try this:

    //CODE THAT DOES REPLACING:
    <?php
    class modules {
       function findModules($text) {
    
          require_once('registry/loader.php');
          $loader = new loader;
          $loader->load("connect_db", "function");
          
          connect_db();
          $query = "SELECT * from modules";
          $run_query = mysql_query($query);
          $num_modules = mysql_num_rows($run_query);          // Get the number of modules
          $i = 0;            // The index of how many modules we've replaced so far
          
          while($i != $num_modules) {
             $module_name = mysql_result($run_query, $i, "modname");      // ALWAYS in format: {module.XXXX}  Where XXXX is the module name
             $module_html = mysql_result($run_query, $i, "modhtml");
             
             $module_html = str_replace('<?php', '',$module_html); // Strip Open PHP Tags
             $module_html = str_replace('<?', '',$module_html); // Strip Open PHP Tags (Other type)
             
             $module_html = str_replace('?>', '',$module_html); // Strip Closed PHP Tags
             $text = str_replace($module_name, $module_html, $text, $count);
             require_once('registry/functions/function.connect_db.php');
          
             $count = (int)$count;
             if($count != 0) {
                $text = str_replace($module_html, eval($module_html), $text);
                   
                ?>
                <script>
                alert("<?php echo $text; ?>"); //For debug purposes
                </script>
                <?php
             }
    
             $i++; // Increase amount of modules we've replaced
          }
          /* Done with replacing ALL modules recognized :: return the text*/
          return $text; 
       }
       
    }
    ?><!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>Untitled Document</title>
    </head>
    
    <body>
    </body>
    </html>
    

    you missed a single quote on line 23 :D >.< im so glad i spotted that lol

     

    best of luck!

  11. hello there

    i hope this can help you.

    <?php
    define('LANG_ESPANOL', "es");
    define('LANG_ENGLISH', "en");
    
           function language(){
            $languages = espanol;
            $languaje = substr($languages, 0, 2);
            return $languaje;
           }
    if (language() == "es") {
    echo "hablas espanol";
    }
    elseif (language() == "en") {
    echo "you speak english";
    
       } else {
    echo "unknow language";
    }
    ?>

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