/    Sign up×
Community /Pin to ProfileBookmark

Last question for awhile

This will be the last question for awhile, the rest of my codes I know how to do it.

This code is suppose to send me an e-mail with the Title and Category the Ad is placed in. It is also suppose to tell me if any of the checkmark boxes are checked.

Here is the code:

[code=php]<?php
require(‘header.php’);
//If you’re not logged in…
if($user->name == ”)
{
echo ‘Sorry, you must be logged in to post an ad…’;
require(‘footer.php’);
die(”);
}

//If you’re trying to post a new ad
if(isset($_POST[‘NewAd’]))
{
//Create the CAd object, and create the ad
$ad = new CAd($sql);
var_dump($_POST);
var_dump($_FILES);
if($ad->NewAd($user->ID, $_POST[‘title’], ((isset($_POST[‘image_l’]) && $_POST[‘image_l’] != ”) ? $_POST[‘image_l’] : $_FILES[‘image_f’]), $_POST[‘category’], $_POST[‘price’], nl2br($_POST[‘info’]), $_POST[‘location’]))
echo ‘<script language=”JavaScript”>alert(“Success. Your ad has been placed.”);</script>’;
}

echo ‘<input type=”checkbox” name=”premier” value=”permier”>’;
echo ‘<input type=”checkbox” name=”bold” value=”bold”>’;
echo ‘<input type=”checkbox” name=”border” value=”border”>’;

if(isset($_POST[‘premier’])) echo “this checkbox has been checked!”;
if(isset($_POST[‘bold’])) echo “this checkbox has been checked!”;
if(isset($_POST[‘border’])) echo “this checkbox has been checked!”;

if(isset($_POST[‘NewAd’]))
{
$to = “”;

$content = $_POST[‘title’] . $_POST[‘category’] . $_POST[‘premier’] . $_POST[‘bold’] . $_POST[‘border’];

mail($to,”);

}
[/code]

I get an e-mail with the Title and Category, but when I click on the checkbox, it doesn’t send me an e-mail telling me it has been checked.

The Checkmarks, Title, and Category all are being sent to me in one e-mail, not seperate.

Thanks again, this site has really been helpful! ?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@BeachSideMay 19.2005 — Try this

[code=php]
<?php
require('header.php');
//If you're not logged in...
if($user->name == '')
{
echo 'Sorry, you must be logged in to post an ad...';
require('footer.php');
die('');
}

//If you're trying to post a new ad
if(isset($_POST['NewAd']))
{
//Create the CAd object, and create the ad
$ad = new CAd($sql);
var_dump($_POST);
var_dump($_FILES);
if($ad->NewAd($user->ID, $_POST['title'], ((isset($_POST['image_l']) && $_POST['image_l'] != '') ? $_POST['image_l'] : $_FILES['image_f']), $_POST['category'], $_POST['price'], nl2br($_POST['info']), $_POST['location']))
echo '<script language="JavaScript">alert("Success. Your ad has been placed.");</script>';
}

echo '<input type="checkbox" name="premier" value="premier">';
echo '<input type="checkbox" name="bold" value="bold">';
echo '<input type="checkbox" name="border" value="border">';

if(isset($_POST['premier'])) {
$premiere = "this checkbox has been checked!rn";
}
if(isset($_POST['bold'])) {
$bold = "this checkbox has been checked!rn";
}
if(isset($_POST['border'])) {
$border = "this checkbox has been checked!rn";
}
if(isset($_POST['NewAd']))
{
$to = "[email protected]";

$content = $_POST['title'] . $_POST['category'] . $premiere . $bold . $border;

mail($to,"New Ad Posted on RacingRides.com",$content);

}
[/code]
Copy linkTweet thisAlerts:
@LaoauthorMay 19.2005 — Hi,

Thanks for the reply!

I tried it, it doesn't send the checkboxes to my e-mail still. ?
Copy linkTweet thisAlerts:
@BeachSideMay 19.2005 — If that didn't work then I would try error checking it. You can do it the quick way by placing an echo after each if statement to make sure that it is passing that variable. Also for what is below you will need to check all three checkboxes to see what if anything is being passed.

Like this...
[code=php]
<?php
require('header.php');
//If you're not logged in...
if($user->name == '')
{
echo 'Sorry, you must be logged in to post an ad...';
require('footer.php');
die('');
}

//If you're trying to post a new ad
if(isset($_POST['NewAd']))
{
//Create the CAd object, and create the ad
$ad = new CAd($sql);
var_dump($_POST);
var_dump($_FILES);
if($ad->NewAd($user->ID, $_POST['title'], ((isset($_POST['image_l']) && $_POST['image_l'] != '') ? $_POST['image_l'] : $_FILES['image_f']), $_POST['category'], $_POST['price'], nl2br($_POST['info']), $_POST['location']))
echo '<script language="JavaScript">alert("Success. Your ad has been placed.");</script>';
}

echo '<input type="checkbox" name="premier" value="premier">';
echo '<input type="checkbox" name="bold" value="bold">';
echo '<input type="checkbox" name="border" value="border">';

// Also I put your if statements inside of the main one below
if(isset($_POST['NewAd']))
{
if(isset($_POST['premier'])) {
$premiere = "this checkbox has been checked!rn";
} else {
echo('<h1>Premiere is not checked!</h1>');
}
if(isset($_POST['bold'])) {
$bold = "this checkbox has been checked!rn";
} else {
echo('<h1>Bold is not checked!</h1>');
}
if(isset($_POST['border'])) {
$border = "this checkbox has been checked!rn";
} else {
echo('<h1>Border is not checked!</h1>');
}
$to = "[email protected]";

$content = $_POST['title'] . $_POST['category'] . $premiere . $bold . $border;

// Comment your mail function out for debugging
// mail($to,"New Ad Posted on RacingRides.com",$content);

}
[/code]


Hope that helps

BeachSide
Copy linkTweet thisAlerts:
@LaoauthorMay 19.2005 — Hi, Thanks. ?

It doesn't e-mail me if the checkboxes where checked or not. After I place an ad, it says the Ad was placed, and it says 3 times that the checboxes were not checked (1 for each).

Thanks for any help and tips! ?
Copy linkTweet thisAlerts:
@BeachSideMay 19.2005 — Ok that is what it is supposed to say if the variable wasn't passed for some reason. So we have narrowed you problem down a bit.

You know now that I look at it, this is wrong. You have the checkboxes in the wrong place there. I don't know what the rest of your code looks like but the checkboxes need to be in with the rest of the form so that when it sends it and you have checked the checkboxes it will pass their values with the rest of the form.
Copy linkTweet thisAlerts:
@LaoauthorMay 19.2005 — Hi,

Your completely correct, I never thought about that.

I found the code where the rest of the form is (Atleast I'm pretty sure):

[code=php]function NewAd($owner_id, $title, $image, $category, $price, $info, $location)
{
$this->sql->query("SELECT * FROM ads WHERE title = '%s'", $title);

//Die if there's another ad with the same name
if($this->sql->num_rows != 0)
{
echo "<script>alert('Sorry. Another ad exists with this title. Please choose another title.');</script>";
return FALSE;
}
//If $image is an array (i.e. not a link to an offsite hosted image)
if(is_array($image))
{
move_uploaded_file($image['tmp_name'], AD_IMAGES.addslashes($title));
$image_url = SERVER_ROOT.AD_IMAGES.addslashes($title);
}
//If $image is the URL to an image hosted elsewhere.
else
$image_url = $image;

//Query to add this information into the db
$this->sql->query("INSERT INTO ads SET owner = '%s', title = '%s', image = '%s', category = '%s', price = '%s', info = '%s', date = '%s', location = '%s'", $owner_id, $title, $image_url, $category, $price, $info, time(), $location);

return TRUE;
}[/code]


I see how I can insert text boxes, but not completely sure how to add checkboxes. I'm going to try to figure it out, if I do figure it out I'll post... If not, any help will greatly be appreciated.

THANKS! ?
Copy linkTweet thisAlerts:
@LaoauthorMay 20.2005 — I can't figure it out on how to add the checkboxes. I did everything I needed to do to add the varibles, but need the code to make it a checkbox in the form.

If anyone knows how to do that, if you could tell me that would be great.

Thanks. ?
Copy linkTweet thisAlerts:
@BeachSideMay 21.2005 — There is no form in your last post
×

Success!

Help @Lao spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...