Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4533476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:09:38+00:00 2026-05-21T14:09:38+00:00

I made a form to allow an user to submit and update their advertisement

  • 0

I made a form to allow an user to submit and update their advertisement when they enter the right coupon code but I can’t get the message “Invalid coupon code.” to echo out when they enter the wrong coupon code.

heres my code:

<? require("connect.php"); ?>

<form action="advertisement.php" method="POST" enctype="multipart/form-data">
<table width="50%" border="0" cellspacing="0" cellpadding="8">
    <tr> 
       <td><div align="right"> Apartment:</div></td> 
       <td><select name="apartment" id="apartment"> 
        <option>Place Ad In Which Apartment...</option> 
        <option value="0">Archstone La Jolla</option>
        <option value="1">Archstone La Jolla Colony</option>
        <option value="2">Archstone UTC</option>
        <option value="3">Canyon Park</option>
        <option value="4">Costa Verde Village</option>
        <option value="5">Costa Verde Towers</option>
        <option value="6">La Jolla Crossroads</option>
        <option value="7">La Jolla Del Sol</option>
        <option value="8">La Jolla International Garden</option>
        <option value="9">La Jolla Palms</option>
        <option value="10">La Mirada</option>
        <option value="11">La Regencia</option>
        <option value="12">La Scala</option>
        <option value="13">Las Flores</option>
        <option value="14">The Villas</option>
        <option value="15">Nobel Court</option>
        <option value="16">Pacific Gardens</option>
        <option value="17">Regents Court</option>
        <option value="18">Regents La Jolla</option>
        <option value="19">Trieste</option>
        <option value="20">Valentia</option>
        <option value="21">Whispering Pines</option></select></td>
   </tr>
    <tr>
       <td><div align="right">Description:</div></td>
       <td><textarea name="description" id="description" cols="55" rows="7" wrap="VIRTUAL"></textarea></td>
    </tr>
    <tr>
       <td><div align="right">Coupon Code:</div></td>
       <td><input type="text" name="code" size="60"></td>
    </tr>
    <tr> 
       <td></td>
       <td><div align="left">
        <input type="reset" value="Clear">     
        <input type="submit" name="submit" value="Submit"></div></td>
    </tr>
  </table>
</form>

<?php

$description = $_POST['description'];
$apartment = $_POST['apartment'];
$code = $_POST['code'];

//retrieve data from password table
$query = mysql_query ("SELECT * FROM coupon WHERE code = '$code' ");

//get number of rows in table
$numrows = mysql_num_rows ($query);

if ($numrows !=0)
{
    // gather all codes
    while ($row = mysql_fetch_assoc ($query))
    {
        //retrieve code from database to match with the code that was put into field
        $dbcode = $row['code'];
    }

    //check to see if they match
    if ($code == $dbcode )
        {
            //check to see if coupon code is in both consumer and coupon tables
            $query2 = mysql_query ("SELECT * FROM consumer WHERE code = '$code' ");

            $numrows2 = mysql_num_rows ($query2);


        while ($row2 = mysql_fetch_assoc ($query2))
        {
            $consumercode = $row2['code'];
        }
            if( $dbcode == $consumercode)
            {

                $update = mysql_query ("UPDATE consumer SET description = '$description' WHERE code ='$code'  ");           




                echo "Advertisement successfully updated.";


            }
            //if coupon not in both tables then they haven't posted advertisement yet
            else
             {


$time = time();

$day =  30;

$exp = $time + ($day * 86400);


        mysql_query ("INSERT INTO consumer VALUES ('','$description', '$exp', '$apartment', '$code')");     

        mysql_query ("UPDATE coupon SET exp = '$exp' WHERE code ='$code'  ");       


                echo "Your advertisement has been successfully submitted.";
             }

}
else
    echo "Invalid coupon code.";
}
else 
    echo "";



 ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:09:39+00:00Added an answer on May 21, 2026 at 2:09 pm
    while ($row = mysql_fetch_assoc ($query))
    {
        //retrieve code from database to match with the code that was put into field
        $dbcode = $row['code'];
    }
    

    This block of code isn’t gathering all codes. It’s just overwriting $dbcode with every code, and at the end of the block there is only the last row.

    I am assuming that the rest of the code should be inside of this block.

    }
    else
        echo "Invalid coupon code.";
    }
    else 
        echo "";
    

    This second echo statement at the end should also have a message, which I think would be the invalid code message, since it’s based on if ($numrows !=0)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit stuck on my code right now. I've dynamicly made a form,
I want to create a web form which will allow the user to upload
I have a form where an user can post a global notice into the
I have made a feedback form.i put some jquery code to make it animate
I have a custom edit form made for ASPxGridView but have a big problem
I have a form made up of multiple, optional subparts - each of which
I made a code that translate strings to match each word from the array
I want to allow users to use only one system to login. if they
I have made a php form that is submitted by email. I am trying
i made a simple form designer in delphi, drag and drop a button on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.