Jump to content

Archived

This topic is now archived and is closed to further replies.

pixy

I wrote my own advertisements script...

Recommended Posts

Alrighty, I know it's connected because if it couldn't connect to the database it has an error message to give me. So, the problem is when I attempt to add a new advertisement, it tells me table 'ads.danceinside_monica' doesn't exist. However, I know table 'ads' exists, but it shouldn't be concatenating the two...

This is my code for ads.php?action=add. Please tell me if you see something I dont--because I've been trying to get to this work. O_O

[code]
elseif ($action=='add') {
    $errors = array();
        if (isset($_POST['submitted'])) {
            if (empty($_POST['name'])) {
                $errors[] = 'You forgot to enter a name!';
            }
            else {
                $name = $_POST['name'];
            }
            if (empty($_POST['banner'])) {
                $errors[] = 'You forgot to link to a banner!';
            }
            else {
                $banner = $_POST['banner'];
            }
            if (empty($_POST['url'])) {
                $errors[] = 'You forgot to enter a url!';
            }
            else {
            $url = $_POST['url'];
            }

// Check for errors in the $errors array
                if (empty($errors)) {
                   $query = "INSERT INTO ads (name, banner, url) VALUES ('$name', '$banner', '$url')";
                   $result = @mysql_query($query) or die(mysql_error());
                   if ($result) {
                       echo "<b>Advertisements updated successfully!</b><p>
                       If you would like to add another banner, <a href=\"ads.php?action=add\">click here</a>.";
                       mysql_free_result ($result);
                       mysql_close();
                    }
                    else {
                       print 'Couldn\'t insert information into database.';
                   }
                }
                else {
                    print '<b>Error!</b><br>';
                    foreach ($errors as $msg) {
                        echo "- $msg<br>";
                    }
                    mysql_free_result ($result);
                    mysql_close();
               }
    }
    else {
        print "To add a new banner, fill in the information below:";
        echo '<form action="ads.php?action=add" method="post">
        <b>Name:</b> <input type="text" name="name" size="15">
        <br><b>Banner Img:</b> <input type="text" name="banner" size="15" value="http://">
        <br><b>Links to:</b> <input type="text" name="url" size="15" value="http://">
        <input type="hidden" name="submitted" value="TRUE">
        <center><input type="submit" name="submit" value="Add New Advertisement"></center></form>';
    }
}
[/code]

Share this post


Link to post
Share on other sites
Bump? Does anyone know why I'm having this problem?

Share this post


Link to post
Share on other sites

×

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.