Jump to content

I wrote my own advertisements script...


pixy

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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