Jump to content

How do I join two database tables.


Ramario

Recommended Posts

    I have two database tables, "advertisers" and "campaigns".

 

    Advertisers, consists of :

 

    user_id

    name

    email

    password.

 

 

    campaigns consists of :

 

    campaign_id

    user_id

    budget.

 

 

    To create a campaign a user must be logged in. How do I copy the user_id from the table "advertisers" into "campaigns". For example if John has a user_id = 5. And he creates a campaign, the campaign_id = 1

    how do I get his user_id to automatically be placed in the campaigns table when he submits a campaign without having to ask him for it? So for John I would like to see :

 

    Campaign_id = 1

    user_id = 5

    budget = 10.00

 

    Please tell me what mysql_query to use to solve this problem.

    Thanks in advance

 

 

This is my code :

<?php
session_start();

   
   
$id = $_SESSION['id'];
if($_SESSION['username'])
echo"Welcome, ".$_SESSION['username'].
"!<br/><a href='advertiserslogout.php'>Log out</a>";
else 
die("You must be logged in");
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lesultra - The Super Lead Network</title>
<LINK REL="SHORTCUT ICON" HREF="images/lesultra favicon.jpg"
<meta name="keywords" content="advertising, network, leads, lesultra, subscriber, publisher" />
<meta name="description" content="The greatest online advertising network on the internet" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" href="css/nivo-slider.css" type="text/css" media="screen" />

<script language="javascript" type="text/javascript">
function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}
</script>

<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/ddsmoothmenu.js">

/***********************************************
* Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

</script>

<script type="text/javascript">

ddsmoothmenu.init({
mainmenuid: "templatemo_menu", //menu DIV id
orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu', //class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

</script>

<style type="text/css">
#templatemo_wrapper #templatemo_header #site_title strong {
color: #FFFFFF;
font-weight: bold;
text-align: center;
}
#templatemo_wrapper #templatemo_header {
text-align: center;
}
.ultra {
color: #FF0000;
}
#templatemo_wrapper #templatemo_header {
font-size: 36px;
}
#templatemo_wrapper #templatemo_middle #templatemo_middle_left p {
font-family: Verdana, Geneva, sans-serif;
}
.r {
font-size: 10px;
}
.r {
font-size: 12px;
}
#templatemo_main_wrapper #templatemo_main #content .post {
font-size: 16px;
}
#templatemo_main_wrapper #templatemo_main #content .post {
color: #000;
font-size: 12px;
}
</style>
</head>
<body>

<div id="templatemo_wrapper">

    <div id="templatemo_header">
        <div id="site_title">
          <h1> </h1>
          <h1><strong>Les<span class="ultra">ultra</span><span class="r">® </span></strong></h1>
<p> </p>
      </div>
        <div id="templatemo_menu" class="ddsmoothmenu">
            <ul>
                <li><a href="index.html" class="selected"><span></span>Home</a></li>
                <li><a href="myads.php"><span></span>My ads</a> </li>
              <li><a href="billing.php"><span></span>Billing</a></li>
              <li><a href"settings.php"><span></span>Settings</a></li>
              <li><a href="performance.php"><span></span>Performance</a></li>

                            <li></li>

          </ul>
            <br style="clear: left" />
        </div> 
        <p> </p>
</div> <!-- end of header -->
    
<div id="templatemo_main_wrapper">
    	<div id="templatemo_main">
        
          <h2><strong><strong><strong>
   	      Campaign
    	    
  	    & Budget        </strong></h2>
<?php
$submit = ($_POST['submit']);
$id = $_SESSION['id'];
$campaign = strip_tags($_POST['campaign']);
$budget = strip_tags($_POST['budget']);
$category = strip_tags($_POST['category']);
$advert = $_POST['advert'];


if ($submit)
{
//check for existence

if($campaign&&$budget&&$category&&$advert)

{
//submit info

  
  //open database
   $connect = mysql_connect("localhost", "lesultra", "soulplane");
   mysql_select_db("lesultra_members");
mysql_query ("INSERT INTO campaigns ('','id','campaign','budget','category','advert') VALUES '','$query','$campaign', '$budget', '$category','$advert')");	
echo"<p>Your order has been placed. Your ad is pending review and will be up and running within the next 24 hours.<br/>
Thank you for advertising with Lesultra.</p>";

}
else echo "<p>You must fill in all fields!</p>"; 

}
  
  
  
  
?>

        
        <form action="members.php" method="post">
    	  <tr>
          <td><h5>Campaign name:
          </h5></td>
          <td>
            <p>
              <input type="text" name="campaign" />
            </p>
            <p>  </p></td>
</tr> <tr>
          <td><h5>Budget per day (GBP):
          </h5></td>
          <td>
            <p>
      
<input type="text" name="budget"/>
      
            </p>
            <p>  </p></td>
</tr>
<tr>
          <td><h6>To help us find the websites best suited to your advert.<br/>
          	Please tell us what is the topic of your advert. e.g, Food. 
          </h6></td>
          <td>
            <p>
              <input type="text" name="category" />
            </p>
            <p>  </p></td>
</tr> <tr>


            
            
          <h5>Submit your web form or banner:</h5>
            <p>
  <textarea name="advert" cols="40" rows="5">
              </textarea>
            </p>         <br/> <p><input type="submit" name="submit" value="Place order" />

           </p></form>

  <div class="col_2 float_r"></div>
                <div class="cleaner h30"></div>
                <div class="col_2 float_l">
                  <div class="cleaner"></div>
                </div>
                <div class="col_2 float_r"></div>
                <div class="cleaner h30"></div>
                <div class="col_2 float_l"></div>
                <div class="col_2 float_r"></div>
                <div class="cleaner"></div>
          </div><!-- end of sidebar -->
            
          <div class="cleaner"></div>
        </div> <!-- end of main -->
    </div> <!-- end of main wrapper -->
    
</div> <!-- end of wrapper -->

<div id="templatemo_footer_wrapper">
<div id="templatemo_footer">
    	<a href="#templatemo_header" class="goto_top"></a>
    	<div class="col_4">
        	<h5>Pages</h5>
            <ul class="footer_list">
            	<li><a href="home.html">Home</a></li>
                <li><a href="about.html">About Us</a></li>
                <li><a href="Publishers.html">Publishers</a></li>
                <li><a href="Advertisers.html">Advertisers</a></li>
                <li><a href="contact.html">Contact</a></li>
		</ul>
                    <br/><br/>Lesultra © 2012 

        </div>
        
        <div class="col_4">
        	<h5>Partners</h5>
            <ul class="footer_list">
            	<li><a href="http://Quotingquotes.co.uk/">Quotingquotes.co.uk</a></li>
		</ul>             
        </div>
        
        <div class="col_4">
        	<h5> </h5>
</div>
        
        <div class="col_4 col_l">
        	<h5> </h5>
        	<div class="cleaner h40"></div>
            
          
      		
	</div>
        
        <div class="cleaner"></div>
    </div>
</div>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/257573-how-do-i-join-two-database-tables/
Share on other sites

well first you are telling us that the "campaigns" table consists of the fields: campaign_id, user_id, budget. However, in your insert statement (which uses incorrect syntax btw):

 

mysql_query ("INSERT INTO campaigns ('','id','campaign','budget','category','advert') VALUES '','$query','$campaign', '$budget', '$category','$advert')");   

 

you have specified different fields then what you initially stated, i don't see a campaign_id field, i don't see a user_id field. Please get your facts straight, help us help you.

 

Does $_SESSION['id']; contain the user's id? more information is needed to solve this correctly.

Archived

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

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