![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
dc_jt
-
Posts
290 -
Joined
-
Last visited
Never
Posts posted by dc_jt
-
-
Hi
Im exporting fields from a database into an excel file, and everything is coming out fine, except the first row in excel is being skipped and the headers (name, email, address etc) are on the 2nd row down. Why does it not start on the first row?
Here is my code:
[code]<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php');
require_once(LOCAL_CLASSES.'/Tables/RCLTblReaders.class.php');
$oTblReaders = new RCLTblReaders();
$rReaders = $oTblReaders->GetDataP();
//Set username and password for login
$myusername = "****@********.com";
$mypassword = "****";
$areaname = "User Memories";
//If username is blank or password is blank or username or password dont match $myusername or $mypassword (above)
//show username and password login box
if ($_SERVER["PHP_AUTH_USER"] == "" || $_SERVER["PHP_AUTH_PW"] == "" || $_SERVER["PHP_AUTH_USER"] != $myusername || $_SERVER["PHP_AUTH_PW"] != $mypassword) {
header("HTTP/1.0 401 Unauthorized");
header("WWW-Authenticate: Basic realm=\"$areaname\"");
echo "<h1>Authorization Required.</h1>";
die();
}
$sCurrentDate = date("d/m/Y");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=UserMemories".str_replace(' ','', $sUserMemories)."_".$sCurrentDate.".csv");
header("Pragma: no-cache");
header("Expires: 0");
print "Name, Email, Address, Town, City, Postcode, Country";
while ($oReaders = mysql_fetch_object($rReaders))
{?>
<?php
print "$oReaders->name, $oReaders->email, $oReaders->address, $oReaders->town, $oReaders->city, $oReaders->postcode, $oReaders->country";
}?>[/code]
(edit to change [nobbc][quote][/quote][/nobbc] tags to [nobbc][code][/code][/nobbc] tags) -
Thanks :)
-
Ive tried removing all blank lines and still no luck ???
-
Im just looking through some code trying to learn few things.
I came across this line:
[quote]$iStart = ($_GET['page']) ? (((int)$_GET['page']-1) * 5) : 0; [/quote]
I want to comment it so I know what it does, so far ive got:
//Set $iStart to page if the page is an integer....??
Thanks -
Anyone please??
-
Hi
I have the following code which queries my database and shows results in excel.
However, when i open excel to view it the name, email, address etc start on row 2 instead of 1 for some reason.
Also, there is a little square at the end of each row.
Any ideas how to get rid of this?
Here is the code
[quote]<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php');
require_once(LOCAL_CLASSES.'/Tables/RCLTblReaders.class.php');
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=UserMemories".str_replace(' ','', $sUserMemories)."_".$sCurrentDate.".csv");
header("Pragma: no-cache");
header("Expires: 0");
$oTblReaders = new RCLTblReaders();
$rReaders = $oTblReaders->GetDataP();
print "Name, Email, Address, Town, City, Postcode, Country";
while ($oReaders = mysql_fetch_object($rReaders))
{?>
<?php
print "$oReaders->name, $oReaders->email, $oReaders->address, $oReaders->town, $oReaders->city, $oReaders->postcode, $oReaders->country";
}?>[/quote]
Thanks -
I have a form where the user can add a url using a text field.
I want to be able to have 'http://' in the text field all the time so they always put this before their website.
I have the following:
[code] <td >URL</td><td ><input class="fmfield200" type="text" name="url" value="<?=(isset($_POST['url']))?$_POST['url']:$aListing['url']?>"/></td>
</tr>
<tr>[/code]
How can I put it into this?
Thanks -
I have a validation function like this:
[code]private function ValidateData($aPostData)
{
//If normal listing
if ($aPostData['iTypeId'] == 1){
//check all fields
if (trim($aPostData['name']) == "") return false;
if (trim($aPostData['address']) == "") return false;
if (trim($aPostData['postcode']) == "") return false;
if (trim($aPostData['telephone_number']) == "") return false;
if (trim($aPostData['fax']) == "") return false;
if (trim($aPostData['email']) == "") return false;
if (trim($aPostData['description']) == "") return false;
return true;
//All larger Ads
}else{
if (trim($aPostData['name']) == "") return false;
return true;
}
}//end function[/code]
I want to add something so that the user cant enter more than 120 characters in the description box.
How could I add this?
Thanks -
Yeah I thought that was the best way.
Now from my form, I have an AddListing function which inserts name, address, telephone etc into the listings table so do I just run another function which inserts the listing type and the listing id in the listing type table?
Do I have to join them using INNER JOIN or anything?
Thanks
-
Hi
I have a table called listings which contains name, address, telephone etc of each advertising listing.
Each listing has a choice of 4 types (Listing Ad, Quarter Size, Half Size, Full Size).
Each listing only has one type.
What is the best way to insert one of these types into my listings table?
I was thinking of having a checkbox for each on my form like:
Listing Ad []
Quarter Size []
Half Size []
Full Size []
Then whatever one is clicked goes into the table listings.
However, do i have a separate table for the types or do i put them all in the listings table, im not sure?
Hope someone can help asap please
Thanks -
I dont really understand the above post sorry
I have a form with checkboxes for each category like
bars [] (<--Thats meant to be a checkbox)
restaurants []
clubs []
So if they tick bars and clubs how do i create the function for these to go in the linkcategories table?
I tried:
[quote]public function AddLinks($aPostData)
{
if (!$this->ValidateData($aPostData,$sFileName)) return false;
$sSql = "INSERT INTO $this->sTableName SET
`listings_id` = '$aPostData[listings_id]',
`category_id` = '$aPostData[category_id]' ";
return mysql_query($sSql, $this->oDb->GetConnection());
}[/quote]
Any idea?
Thanks -
Hi
That made perfect sense, and thats exactly how i have it at the minute because I thought this would be the method.
The thing that was puzzling me was the fact that I have tick boxes for each category in my listings form.
So if listing X wanted to be in category Bars and category Restaurants, how would I fit that into this:
[quote]public function AddListings($aPostData)
{
if (!$this->ValidateData($aPostData,$sFileName)) return false;
$sSql = "INSERT INTO $this->sTableName SET
`category_id` = '$aPostData[category_id]',
`name` = '$aPostData[name]',
`address` = '$aPostData[address]',
`postcode` = '$aPostData[postcode]',
`telephone_number` = '$aPostData[telephone_number]',
`fax` = '$aPostData[fax]',
`email` = '$aPostData[email]',
`description` = '$aPostData[description]' ";
return mysql_query($sSql, $this->oDb->GetConnection());
}[/quote]
Would I need another function insert into the link table somehow?
Thanks a lot for your help
-
I have a cms which displays all categories with up and down arrows next to them determining what position they will be shown on the webpage. I need to have an option where i can make one listing static at the top (In other words, always position 1)
I have done the up and down arrows like this:
[quote]public function MoveUp($iAwardId)
{
$sSql = "SELECT ordering FROM $this->sTableName WHERE $this->sPrimaryKey = '$iAwardId' ";
$rMoveUp = mysql_query($sSql, $this->oDb->GetConnection());
$iOrder = (int) @mysql_result($rMoveUp, 0, 'ordering');
$sSql = "SELECT $this->sPrimaryKey, ordering FROM $this->sTableName WHERE ordering > '$iOrder' ORDER BY ordering ASC LIMIT 1 ";
$rMoveUp = mysql_query($sSql, $this->oDb->GetConnection());
$iAboveAwardId = (int) @mysql_result($rMoveUp, 0, $this->sPrimaryKey);
$iAboveOrder = (int) @mysql_result($rMoveUp, 0, 'ordering');
if($iAboveAwardId == 0)
{
return false;
}
$sSql = "UPDATE $this->sTableName SET ordering = '$iAboveOrder'
WHERE $this->sPrimaryKey = '$iAwardId' ";
mysql_query($sSql, $this->oDb->GetConnection());
$sSql = "UPDATE $this->sTableName SET ordering = '$iOrder'
WHERE $this->sPrimaryKey = '$iAboveAwardId' ";
//die($sSql);
mysql_query($sSql, $this->oDb->GetConnection());
return true;
}
public function MoveDown($iAwardId)
{
$sSql = "SELECT ordering FROM $this->sTableName WHERE $this->sPrimaryKey = '$iAwardId' ";
$rMoveDown = mysql_query($sSql, $this->oDb->GetConnection());
$iOrder = (int) @mysql_result($rMoveDown, 0, 'ordering');
$sSql = "SELECT $this->sPrimaryKey, ordering FROM $this->sTableName WHERE ordering < '$iOrder' ORDER BY ordering DESC LIMIT 1 ";
//die($sSql);
$rMoveDown = mysql_query($sSql, $this->oDb->GetConnection());
$iBelowAwardId = (int) @mysql_result($rMoveDown, 0, $this->sPrimaryKey);
$iBelowOrder = (int) @mysql_result($rMoveDown, 0, 'ordering');
if($iBelowAwardId == 0)
{
return false;
}[/quote]
Any idea how I do the static one?
Thanks -
I am doing a cms on an advertising company.
When someone submits a listing, their listing can come under one or more categories.
I have a table with categories in (bars, restaurants, clubs etc)
I have another table called listings which contains the listing_id, name, address, tel_number etc and CATEGORIE_ID.
So when someone submits their listing, they can choose it to go under the bars AND restaurants category.
However, when I add the data into the table how do i add both category IDs into the category_id field in listings?
Or do I need another table to link them and if so how?
Thanks a lot, really struggling getting my head round this -
Sorted
in MySQL Help
Sorted -
Hi
I have a list of categories.
If a user clicks a certain category, they are taken to a form where they can add a listing to that category.
In this form, all categories are listed as checkboxes for example hotels, bars, restaurants.
If the user selected the hotel category orginally, how can the hotel checkbox be automatically ticked, representing this categofy they are in?
Thanks -
Ive got this code, however the names show up when i run the php script but they wont go in the database.
When i enter normal text instead of [quote]$sGetData['name'][/quote] in [quote]file_put_contents($FileName, $sGetData['name']) or die ('Could not read file');
[/quote]
this works so I know its something to do with the $sGetData['name'].
Is this not allowed in file_get_contents or something??
Thanks
[quote]<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php');
require_once(LOCAL_CLASSES.'/Tables/RCLTblReaders.class.php');
$oTblReaders = new RCLTblReaders();
$iGetDataP = $oTblReaders->GetDataP($sDataP);
while ($sGetData = mysql_fetch_array($iGetDataP))
{?>
<?=$sGetData['name']?>
<?}?>
<?php
$FileName = ($_SERVER['DOCUMENT_ROOT'].'/DataProtection.txt');
$fh = fopen($FileName, 'w') or die ('Could not open file');
file_put_contents($FileName, $sGetData['name']) or die ('Could not read file');
?>[/quote] -
Sorted it now :)
-
This is what I have now:
[quote]$m = new CMIMEMail("dconnor@......", "liverpool@test.com", $subject);
$m->mailbody($message);
if( $photo != '') {
$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/'.$sFileName,$photo,$_FILES['photo']['type']);
}
elseif( $photo == '') {
$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/'."pixel.jpg","pixel.jpg",$_FILES['photo']['type']);
}
$m->send();
}
}[/quote]
The [quote]$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/'.$sFileName,$photo,$_FILES['photo']['type']);[/quote]
and the [quote]$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/'."pixel.jpg","pixel.jpg",$_FILES['photo']['type']);[/quote]
both work because I have tested them both.
So it must be something to do with the if else statements maybe??
The first bit works fine, if a photo is selected attach it, but when there is no photo then the pixel.jpg is not attached. (This line definitely works though because i swapped it with the one above and it attached the pixel.jpg when a photo was selected.
Please this is driving me mad
Thanks -
thats what i was thinking something like that but it doesnt work.
The attachfile_raw function is:
[quote]function attachfile_raw( $fname, $mailFileName, $content_type ) {
if($f=@fopen($fname,"r")) {
$this->atcmnt[$mailFileName]=fread($f,filesize($fname));
$this->atcmnt_type[$mailFileName]=$content_type;
fclose($f);[/quote]
Therefore, I need the file directory, the name of the image and the content type.
I tried this
[quote]$m->mailbody($message);
if( $photo) {
//die('Photo: '.$_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName);
$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName,$photo,$_FILES['photo']['type']);
//die(here);
}
else {
$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploadsImage.jpg',"uploadsImage.jpg",$_FILES['photo']['type']);
}
$m->send();
}
}
?> [/quote]
Not too sure on the content type but this function works if there is an image selected so any idea??
Thanks -
Changed subject of this thread so it makes more sense
Anyone got any ideas?
Ive got this at the minute which sends the email:
[quote]//send email
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$address=$_REQUEST['address1'];
$town=$_REQUEST['town'];
$city=$_REQUEST['city'];
$postcode=$_REQUEST['postcode'];
$country=$_REQUEST['country'];
$license=$_REQUEST['license'];
$memory=$_REQUEST['memory'];
$photo=$sFileName;
$datap=$_REQUEST['datap'];
$subject = "Readers Archive";
$message = 'Name: ' .$name."\n". 'Email: '.$email."\n". 'Address: '.$address."\n". 'Town: '.$town."\n". 'City: '.$city."\n".'Postcode: '.$postcode."\n".'Country: '.$country."\n". 'Memory: '.$memory."\n". 'Photo: '.$photo;
$m = new CMIMEMail("dconnor@******.com", "liverpool@test.com", $subject);
$m->mailbody($message);
if( $photo) {
$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName,$photo,$_FILES['photo']['type']);
}
$m->send();
}
}
?> [/quote]
Im guessing maybe an else statement after [quote]if( $photo) {
$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName,$photo,$_FILES['photo']['type']);
}
[/quote]
Anyone?
Thanks -
Hi
I have a form where a user enters their name, address, postcode etc.
I also have a field where a user can upload an image (This is optional)
These details are then emailed to the intended recipient.
If they choose not to upload an image I need to be able to still send an image. For example, a default image so that every user has an image attached to their email.
Is this possible and if so how?
Thanks -
Hi
Ive got an email working, all i need to do is attach the photo to the image. I have tried reading PHPMailer, Mime and all them but dont know how to integrate them into this, im really struggling.
Anyone five me an idea or tell me a tutorial which is easy to understand and is similar to the below:
Thanks a lot
[quote]<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php');
require_once(LOCAL_CLASSES.'/Tables/RCLTblReaders.class.php');
require_once(GLOBALS.'global_fns.php');
$oTblReaders = new RCLTblReaders();
if($_REQUEST[mode]=="apply"){
//error checking here
if(!$_REQUEST['name']){$_REQUEST[errors]['Name']='<div class="errors">Please enter your Name</div>';}
if(!$_REQUEST['address1']){$_REQUEST[errors]['Address']='<div class="errors">Please enter your Address</div>';}
if(!$_REQUEST['town']){$_REQUEST[errors]['Town']='<div class="errors">Please enter your Town</div>';}
if(!$_REQUEST['city']){$_REQUEST[errors]['City']='<div class="errors">Please enter your City</div>';}
if(!$_REQUEST['postcode']){$_REQUEST[errors]['Postcode']='<div class="errors">Please enter your Postcode</div>';}
if(!$_REQUEST['country']){$_REQUEST[errors]['Country']='<div class="errors">Please enter your Country</div>';}
if(!$_REQUEST['license']){$_REQUEST[errors]['License']='<div class="errors">Please agree to grant a license for the use of your text/photo</div>';}
if(!$_REQUEST['memory'] && $_FILES['photo']['error'] != UPLOAD_ERR_OK){$_REQUEST[errors]['Optional']='<div class="errors">Please enter either a photo or a memory</div>';}
if(validateemail($_REQUEST['email'])===false){$_REQUEST[errors]['Email']='<div class="errors">Please enter a valid Email address</div>';}
$sEmail = $_REQUEST['email'];
$iDuplicate = $oTblReaders->DuplicateEmail($sEmail);
if(sizeof($_REQUEST['errors'])<1)
{
//if no errors then execute.
if(isset($_FILES['photo']))
{
if($_FILES['photo']['error'] != UPLOAD_ERR_OK)
{
print("WARNING: You have not submitted a photo <br />");
}
else{
$sFileName = $_FILES['photo']['name'];
move_uploaded_file($_FILES['photo']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName);
echo "Name: ".$_FILES['photo']['name']."<br />";
echo "Size: ".$_FILES['photo']['size']."<br />";
echo "Type: ".$_FILES['photo']['type']."<br />";
echo "Photo Uploaded....<br />";
}
}
if($iDuplicate != 0)
{
echo 'please choose a different email this one is already stored in the database';
}
else{
$oTblReaders->AddReader($_POST, $sFileName);
$_REQUEST['mode']="complete";
}
//send email
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$address=$_REQUEST['address1'];
$town=$_REQUEST['town'];
$city=$_REQUEST['city'];
$postcode=$_REQUEST['postcode'];
$country=$_REQUEST['country'];
$license=$_REQUEST['license'];
$memory=$_REQUEST['memory'];
$photo=$_REQUEST['photo'];
$datap=$_REQUEST['datap'];
$to = "liverpool@liverpooltest.com";
$subject = "Readers Archive";
$message = 'Name: ' .$name."\n". 'Email: '.$email."\n". 'Address: '.$address."\n". 'Town: '.$town."\n". 'City: '.$city."\n".'Postcode:'.$postcode."\n".'Country: '.$country."\n".'Photo:'.$photo;
$from = 'From: website@liverpooltest.com';
mail($to, $subject, $message, $from);
mail("***********", $subject, $message, $from);
}
}
?>
<?php
if ($_REQUEST['mode'] == 'complete')
{
echo '<div class="complete">Thank You for submitting your details.</div>';
}
else
{
?>
<? if($_REQUEST[errors]){
?>
<ul>
<?
foreach($_REQUEST[errors] as $error){echo $error;}
?></ul><?
}
?>
<form enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF']?>" method="post">
</center><BLOCKQUOTE><center><P><TABLE BORDER=0 CELLSPACING=0>
<TR>
<TD WIDTH=116>
<H4>Name:</H4>
</TD><TD>
<H4><input name="name" type="text" value="<?=htmlentities(stripslashes($_POST['name']))?>" SIZE=50/>
<br class="clear"/></H4>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Address:</H4>
</TD><TD>
<H4><input name="address1" type="text" value="<?=htmlentities(stripslashes($_POST['address1']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Town:</H4>
</TD><TD>
<H4><input name="town" type="text" value="<?=htmlentities(stripslashes($_POST['town']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>City:</H4>
</TD><TD>
<H4><input name="city" type="text" value="<?=htmlentities(stripslashes($_POST['city']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Post Code/Zip Code:</H4>
</TD><TD>
<H4><input name="postcode" type="text" value="<?=htmlentities(stripslashes($_POST['postcode']))?>"/></H4>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Country:</H4>
</TD><TD>
<H4>
<select name="country">
<option value="United Kingdom">United Kingdom</option>
<option value="United States of America">United States of America</option>
<option value="Spain">Spain</option>
<option value="Italy">Italy</option>
</select>
<TR>
<TD WIDTH=116>
<H4>Email Address:</H4>
</TD><TD>
<H4><input name="email" type="text" value="<?=htmlentities(stripslashes($_POST['email']))?>" SIZE=50/>
<br class="clear"/></H4>
</TD></TR>
<TR>
<TD WIDTH=210>
<H4>I agree to grant a license for you to use my text/photograph</H4>
</TD><TD>
<H4><input name="license" type="checkbox" id="license" value="1" <?=($_POST['license'] == '1')?' checked="checked"':''?>/></H4>
<TR>
<TD WIDTH=116>
<H4>Photo:</H4>
</TD><TD>
<H4><input type="file" name="photo" ></H4>
<br class="clear"/></H4>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Memory:</H4>
</TD><TD>
<H4><textarea name="memory" rows=6 cols=40 id="memory"><?=($_POST['memory'])?></textarea></textarea></H4>
</TD></TR>
<TR>
<TD WIDTH=210>
<H4>Data Protection:</H4>
</TD><TD>
<H4><input name="datap" type="checkbox" id="datap" value="1" <?=($_POST['datap'] == '1')?' checked="checked"':''?>/></H4>
<br class="clear"/>
<input type="Submit" name="submit" value="Submit" class="button"/>
<input type="hidden" name="mode" value="apply" />
<?php }//end else?>[/quote] -
Think ive done it, was using or instead of and when putting them together
Equivalent to onKeyPress and onKeyDown
in Javascript Help
Posted
Im looking for an equivalent to onKeyPress and onKeyDown to run the following:
[quote]function CheckLength(id)
{
var maxLen = 250;
var curContent = tinyMCE.getContent(id);
var stripped = curContent.replace(/(<([^>]+)>)/ig,"");
stripped = stripped.replace(/ /ig," ");
var curLen = stripped.length;
alert(stripped);
if (curLen >= maxLen)
{
var msg = "You have reached your maximum limit of characters allowed";
alert(msg);
//add_edit.description.value = add_edit.description.value.substring(0, maxLen);
}
else
{
document.getElementById('text_num').value = maxLen - curLen;
}
}[/quote]
This is my field in the form:
[quote]<td>Description</td><td>
<textarea onKeyPress="CheckLength(this.id);" onKeyDown="CheckLength(this.id)" id="content" name=description style="width:100%; height:250;" rows="20"><?=(isset($_POST['description']))?$_POST['description']:$aListing['description']?></textarea>
<input size="1" value="250" name="text_num" id="text_num"> Characters Left
<input type="button" onClick="CheckLength('content')" />
</span>
</td>[/quote]
Hope someone can help
Thanks