Jump to content


acctman

Member Since 28 Jul 2007
Offline Last Active Jan 18 2013 04:49 PM

Topics I've Started

Simple HTML Dom... get width value

17 January 2013 - 06:17 PM

Hi i'm using Simple HTML Dom to scrap a site page. I'm trying to grab the width value for each img src. Below is the html and php i've been using so far.



<table>
<tr>
<th colspan="4">
<font size="3" color="#a74165">Interest Levels</font>
</th>
</tr>
<tr>
<td nowrap>
<font size="2">MobileT</font>
</td>
<td><img src="http://pictures.domain.com/images/7.gif" alt="1 on a scale of 0-4" border="0" height="15" width="9">
</td>
<td> &nbsp;&nbsp;&nbsp;
</td>
<td nowrap>
<font size="2">MobileC</font>
</td>
<td>
<img src="http://pictures.domain.com/images/7.gif" alt="3 on a scale of 0-4" border="0" height="15" width="27">
</td>
</tr>
<tr>
<td nowrap>
<font size="2">Moderate</font>
</td>
<td><img src="http://pictures.domain.com/images/7.gif" alt="3 on a scale of 0-4" border="0" height="15" width="27">
</td>
<td> &nbsp;&nbsp;&nbsp;
</td>
<td nowrap>
<font size="2">Males</font>
</td>
<td>
</td>
</tr>
<tr>
<td nowrap>
<font size="2">Wild</font>
</td>
<td><img src="http://pictures.domain.com/images/7.gif" alt="3 on a scale of 0-4" border="0" height="15" width="27">
</td>
<td> &nbsp;&nbsp;&nbsp;
</td>
<td nowrap>
<font size="2">Females</font>
</td>
<td>
<img src="http://pictures.domain.com/images/7.gif" alt="4 on a scale of 0-4" border="0" height="15" width="36">
</td>
</tr>
</table>






include('simple_html_dom.php');

$html = new simple_html_dom();   
$html = file_get_html('http://dev.domain.com/');

$element = $html->find("td font[size=3]", 0);  
echo $element-> plaintext . '<br>';

$element = $html->find("font", 7);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[color=red]", 0);  
echo $element-> plaintext . '<br>';

$element = $html->find("font", 3);  
echo $element-> plaintext . '<br>';

# city state country
$element = $html->find("font[size=2]", 3);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=2]", 10);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=2]", 11);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=2]", 12);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=-1]", 0);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=-1]", 1);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=-1]", 2);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=-1]", 3);  
echo $element-> plaintext . '<br>';

$html->clear();

Http Authentication With Php?

11 December 2012 - 09:56 PM

Hi does anyone have an example of using a PHP code to access the .htpasswd file for a user / pass login.

Error in SQL syntax LEFT JOIN

08 May 2012 - 03:47 AM

I'm trying to create a query to where the code below will work... I typed out the general idea of what I'm trying to do

SELECT 
    entry_id, author_id, title, status
FROM exp_channel_titles
WHERE title LIKE %Member Package% 
AND status = 'complete'

LEFT JOIN SELECT
    entry_id, 
    field_id_14, field_id_15, field_id_25, field_id_27, field_id_28, field_id_29, 
    field_id_30, field_id_31, field_id_32, field_id_33, field_id_34, field_id_35
FROM exp_channel_data
WHERE entry_id = exp_channel_titles.entry_id

LEFT JOIN SELECT   
    member_id, email
FROM exp_members
WHERE member_id = exp_channel_titles.author_id


I tried something like this but got an error.

#1064 - 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 '.field_id_14, d.field_id_15, d.field_id_25, d.field_id_27, d.field_id_28, d.fiel' at line 3
SELECT 
    t.entry_id, t.author_id, t.title, t.status
    d.field_id_14, d.field_id_15, d.field_id_25, d.field_id_27, d.field_id_28, d.field_id_29, 
    d.field_id_30, d.field_id_31, d.field_id_32, d.field_id_33, d.field_id_34, d.field_id_35,
    m.member_id, m.email
FROM exp_channel_titles t
LEFT JOIN exp_channel_data d on t.entry_id = d.entry_id
LEFT JOIN exp_members m on t.author_id = m.author_id
WHERE t.title LIKE %Member% 
  AND t.status = 'complete'

Possible explode() and/or function problem.

04 May 2012 - 08:29 AM

I'm not getting any errors but its also not INSERTing into the database. Without an error I can figure out whats wrong.


$db_server = 'localhost';
$db_user = 'user_db';
$db_pass = 'password';

$dbc = mysql_connect ($db_server, $db_user, $db_pass);
if (!$dbc) { 
    die(mysql_error());
    header ('Location: /form');
    exit;
}

	if (is_array($_POST)) {
        foreach ($_POST as $key => $value) {
            $_POST[$key] = mysql_real_escape_string(stripslashes($value));
        }
    }

    $xRequestType      = $_POST["xRequestType"];
    $xConsumerBusiness = $_POST["xConsumerBusiness"];
    $xGlobalLocation   = $_POST["xGlobalLocation"];
    $xFirstName        = strtolower(str_replace("'","''",$_POST["xFirstName"]));
    $xFirstName        = strtoupper(substr($xFirstName,0,1)).substr($xFirstName,1);
    $xLastName         = strtolower(str_replace("'","''",$_POST["xLastName"]));
    $xLastName         = strtoupper(substr($xLastName,0,1)).substr($xLastName,1);
    $xEmail            = strtolower(str_replace("'","''",$_POST["xEmail"]));
    $xTitle            = strtolower(str_replace("'","''",$_POST["xTitle"]));

function dbSet($fields, $source = array()) {
    $set='';
    if (!source) $source = &$_POST;
    foreach ($fields as $field) {
        if (isset($source[$field])) {
            $set.="`$field`='".mysql_real_escape_string($source[$field])."', ";
        }
    }
    return substr($set, 0, -2);
}

// INSERT INTO DATABASE
            mysql_select_db("new_contact",$dbc) or die("Could not select new_contact");
            
$fields =   explode(" ", "xRequestType xConsumerBusiness xGlobalLocation xFirstName xLastName xEmail xTitle xCompany xAddress xCity xState xZip xPhone xFax xProductDesc xComment");
            $query = "INSERT INTO new_contact SET ".dbSet($fields, $_POST);
            mysql_query($query);


form submission $_Post

04 May 2012 - 04:25 AM

can someone visually just read through my code and let me know if this looks like it'll work? I'm not getting any errors in my IDE so now I want to double check the structure


<?php
require_once '/usr/local/cpanel/3rdparty/lib/php/Mail.php';

$db_server = 'localhost';
$db_user = '-----';
$db_pass = '-----';

$dbc = mysql_connect ($db_server, $db_user, $db_pass);
if (!$dbc) { 
    die(mysql_error());
    header ('Location: /contact');
    exit;
}

if ($_POST['contactsent'] != 'yes') {
    header ('Location: /contact');
    exit;
    
} else {
    
	if (is_array($_POST)) {
        foreach ($_POST as $key => $value) {
            $_POST[$key] = mysql_real_escape_string(stripslashes($value));
        }
    }

    $RequestType      = $_POST["RequestType"];
    $ConsumerBusiness = $_POST["ConsumerBusiness"];
    $GlobalLocation   = $_POST["GlobalLocation"];
    $FirstName        = strtolower(str_replace("'","''",$_POST["FirstName"]));
    $FirstName        = strtoupper(substr($FirstName,0,1)).substr($FirstName,1);
    $LastName         = strtolower(str_replace("'","''",$_POST["LastName"]));
    $LastName         = strtoupper(substr($LastName,0,1)).substr($LastName,1);
    $Email            = strtolower(str_replace("'","''",$_POST["Email"]));
    $Title            = strtolower(str_replace("'","''",$_POST["Title"]));
    $Title            = strtoupper(substr($Title,0,1)).substr($Title,1);
    $Company          = strtolower(str_replace("'","''",$_POST["Company"]));
    $Company          = strtoupper(substr($Company,0,1)).substr($Company,1);
    $Address          = strtolower(str_replace("'","''",$_POST["Address"]));
    $Address          = strtoupper(substr($Address,0,1)).substr($Address,1);
    $City             = strtolower(str_replace("'","''",$_POST["City"]));
    $City             = strtoupper(substr($City,0,1)).substr($City,1);
    $State            = $_POST["State"];
    $Zip              = $_POST["Zip"];
    $Phone            = $_POST["Phone"];
    $F              = $_POST["F"];
    $ProductDesc      = $_POST["ProductDesc"];
    $Comment          = $_POST["Comment"];

    if ($GlobalLocation == "Canada"):
        $SendTo="canadainfo@------.com";
    elseif ($GlobalLocation == "Central America"): 
        $SendTo="customer.service@------.com.pa";
    elseif ($GlobalLocation == "Europe"):
        $SendTo="marketing@-----.uk";
    elseif ($GlobalLocation == "Mexico"):
        $SendTo="ventas@------.com.mx";
    else:
        $SendTo="info@------.com";
    endif;

function dbSet($fields, $source = array()) {
    $set='';
    if (!source) $source = &$_POST;
    foreach ($fields as $field) {
        if (isset($source[$field])) {
            $set.="`$field`='".mysql_real_escape_string($source[$field])."', ";
        }
    }
    return substr($set, 0, -2);
}

// INSERT INTO DATABASE
            mysql_select_db("new_contact",$dbc) or die("Could not select new_contact");
            
$fields =   explode(" ", "RequestType ConsumerBusiness GlobalLocation FirstName LastName Email Title Company Address City State Zip Phone F ProductDesc Comment");
            $query = "INSERT INTO new_contact SET ".dbSet($fields, $_POST);
            mysql_query($query);

// SETUP EMAIL
		$Bodycopy = "This information was submitted via the ------.com website and sent to you because of the location 
        identified by the user. <br>If this has reached you in error, please forward this email to info@------.com";
		$Bodycopy. "<br>----------------------------------------------------------------------------------------------<br><br>";
				
        if ($RequestType != "")      $Bodycopy. "What kind of information do you need? : " .$RequestType. "<br>";	
		if ($ConsumerBusiness != "") $Bodycopy. "What type of customer or vendor are you? : " .$ConsumerBusiness. "<br>";
		if ($GlobalLocation != "")   $Bodycopy. "Global Location : " .$GlobalLocation. "<br>";
		if ($Company != "")          $Bodycopy. "Company : " .$Company. "<br>";
		if ($FirstName != "")        $Bodycopy. "First Name : " .$FirstName. "<br>";
		if ($LastName != "")         $Bodycopy. "Last Name : " .$LastName. "<br>";
		if ($Title != "")            $Bodycopy. "Title : " .$Title. "<br>";
		if ($Email != "")            $Bodycopy. "Email : " .$Email. "<br>";
		if ($Address != "")          $Bodycopy. "Address : " .$Address. "<br>";
		if ($City != "")             $Bodycopy. "City : " .$City. "<br>";	
		if ($State != "")            $Bodycopy. "State : " .$State. "<br>";
		if ($Zip != "")              $Bodycopy. "Zip/Postal Code : " .$Zip. "<br>";
		if ($Phone != "")            $Bodycopy. "Phone : " .$Phone. "<br>";
		if ($F != "")              $Bodycopy. "F : " .$F. "<br>";
		if ($ProductDesc != "")      $Bodycopy. "UPC or product description : " .$ProductDesc. "<br>";
		
		$Bodycopy. "<br>----------------------------------------------------------------------------------------------<br><br>";
        
		if ($Comment != "")          $Bodycopy. "Comments : <br>" .$Comment. "<br>";
		
        $Bodycopy. "<br><br>";
        $Bodycopy. $IP = $_SERVER["remote_addr"];
        
// PROCESS EMAIL

// mail server info...

        $from = $SendTo;
        $to = "Do Not Reply <donotreply@------>";
        $subject = "Website Contact : " . $GlobalLocation;
        $body = $Bodycopy;
        $host = "mail.------";
        $port = "25";
        $username = "donotreply@-------";
        $password = "-------";
        
        $headers = array ('From' => $from,
        'To' => $to,
        'Subject' => $subject);
        $smtp = Mail::factory('smtp',
        array ('host' => $host,
         'auth' => true,
         'port' => $port,
         'username' => $username,
         'password' => $password));
        
        $mail = $smtp->send($to, $headers, $body);
        
        if (PEAR::isError($mail)) {
        echo("<p>" . $mail->getMessage() . "</p>");
        } else {
        echo("<p>Message successfully sent!</p>");
        }

// MAKE SURE DB CONN IS CLOSED
        mysql_close($dbc);

// REDIRECT TO THANK YOU PAGE
        header ('Location: /index.php?option');
        exit();

}

?>

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com