Jump to content

Recommended Posts

<?php
if ($_POST['B1'] == "Continue")
{
$errorMessage = '';
   	// first check if the number submitted is correct
   	$number = $_POST['txtNumber'];
//echo "number is=".$number."<br>";
//echo md5($number)."<br>";
//echo $_SESSION['image_random_value'];
  	if (md5($number) == $_SESSION['image_random_value'])
   	{
		//echo "iam in if"."<br>";
        	 // set the session
         	$_SESSION['image_is_logged_in'] = true;
        	 // remove the random value from session 
        	 $_SESSION['image_random_value'] = '';
        	// exit;
		//header("location:build_breakroom.php?value=Verified");
		//echo "<input type='hidden' value='verified' name='image_verify'>";
    	

		//echo "iam in if";
		$categoryName=$GET["categoryName"];
		$category=$GET["cat_id"];
		$customername = $_POST["customer_name"];
		//echo "name=".$customername."<br>";
		$name = $_POST["customer_name"];
		$companyname=$_POST["company_name"];
		//echo "companyname=".$companyname."<br>";
		$phone=$_POST["phone"];
		$address=$_POST["address"];
		$city=$_POST["city"];
            $newsletter=$_POST["newsletter"];
		$email=$_POST["email"];
		$no_emp=$_POST["no_emp"];
		$a1 = date(d,strtotime($_POST["reg_date"]));
		$b1 = date(m,strtotime($_POST["reg_date"]));
		$c1 = date(Y,strtotime($_POST["reg_date"]));

		$d1 = $c1 . "-" . $b1 . "-" . $a1;

		$reg_date=$d1;
		$flag=0;

}
else
{
		//echo "iam in else"."<br>";
   			$errorMessage = 'Sorry, wrong number. Please try again';
		header ("location:new_customer.php?error=$errorMessage");
	}
}
if ($newsletter) {
	//add record

	$name = $_POST["customer_name"];
	$sql = "insert into subscribers values('', '$_POST[email]', '$_POST[name]')";
	$result = mysql_query($sql,$conn) or die(mysql_error());
$display_block = "<P><center><strong>Thanks for signing up!</center></strong></P>";
} else {
	//print failure message
	$display_block = "<P><center><strong>You're already subscribed!</center></strong></P>";
}		

?>

When I do an echo I get the name, but it does not post into the database table, only the email does?

 

I have three problems in this code, but felt that if I post one.  I could get some assistance.

 

Thank you

LadyDee

Link to comment
https://forums.phpfreaks.com/topic/148812-inserting-into-datbase-is-not-working/
Share on other sites

There are several tables in the database the customer table has customer names, the table that is used for the newsletter has name.

 

I am including the structure of the tables:

 

Subscribers table:

id email name

 

 

tblcustomer table:

 

Partial Texts

Full Texts

Relational key

Relational display field

Show BINARY

Show BLOB

Hide Browser transformation

cust_id custName custAddress custCity custPhone custEmail Company businessType no_of_emp username password activate reg_date

 

Any solution, or do I have to rename the colun in subscriber table?

 

Thank you

LadyDee

Post your form so we can see your Post variables.  I think you actually need to use $name since you already stored the variable, but it's hard to tell.

 

$name = $_POST["customer_name"];

$sql = "insert into subscribers values('', '{$_POST}', '$name')";

 

Also, you are using $_GET incorrectly, unless you have an array called $GET.

OK, I am posting the form, inserts to both tables are done in other forms, so I hope not to have to change much, everything else for this is working.  I added the form which the user uses and the pages it goes to is here, this does the insert to the database.  And I have two other problems on this page.

 

<?php
ob_start();
session_start();
require_once("connect.inc");

?>

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Georgia Vending Services - Vending Services</title>
<link rel=stylesheet href=style.css type=text/css>
<style>
td{font-family:arial;font-size:12}
</style>
<link rel="stylesheet" href="image/style.css" type="text/css">
<link rel="stylesheet" href="image/linkstyle.css" type="text/css">

</head>

<body topmargin="0" leftmargin="0" background="image/background.gif">
<center>

<script>
function show_cart()
{
window.open ('show_cart.php','','toolbars=0,scrollbars=0,width=300,height=300,top=100,left=160');
}
</script>

<p>


<?php
if ($_POST['B1'] == "Continue")
{
$errorMessage = '';
   	// first check if the number submitted is correct
   	$number = $_POST['txtNumber'];
//echo "number is=".$number."<br>";
//echo md5($number)."<br>";
//echo $_SESSION['image_random_value'];
  	if (md5($number) == $_SESSION['image_random_value'])
   	{
		//echo "iam in if"."<br>";
        	 // set the session
         	$_SESSION['image_is_logged_in'] = true;
        	 // remove the random value from session 
        	 $_SESSION['image_random_value'] = '';
        	// exit;
		//header("location:build_breakroom.php?value=Verified");
		//echo "<input type='hidden' value='verified' name='image_verify'>";
    	

		//echo "iam in if";
		$categoryName=$GET["categoryName"];
		$category=$GET["cat_id"];
		$customername = $_POST["customer_name"];
		//echo "name=".$customername."<br>";
		$name = $_POST["customer_name"];
		$companyname=$_POST["company_name"];
		//echo "companyname=".$companyname."<br>";
		$phone=$_POST["phone"];
		$address=$_POST["address"];
		$city=$_POST["city"];
            $newsletter=$_POST["newsletter"];
		$email=$_POST["email"];
		$no_emp=$_POST["no_emp"];
		$a1 = date(d,strtotime($_POST["reg_date"]));
		$b1 = date(m,strtotime($_POST["reg_date"]));
		$c1 = date(Y,strtotime($_POST["reg_date"]));

		$d1 = $c1 . "-" . $b1 . "-" . $a1;

		$reg_date=$d1;
		$flag=0;

}
else
{
		//echo "iam in else"."<br>";
   			$errorMessage = 'Sorry, wrong number. Please try again';
		header ("location:new_customer.php?error=$errorMessage");
	}
}
if ($newsletter) {
	//add record

	$name = $_POST["customer_name"];
	$sql = "insert into subscribers values('', '$_POST[email]', '$_POST[name]')";
	$result = mysql_query($sql,$conn) or die(mysql_error());
$display_block = "<P><center><strong>Thanks for signing up!</center></strong></P>";
} else {
	//print failure message
	$display_block = "<P><center><strong>You're already subscribed!</center></strong></P>";
}		

?>

<table width="46%" cellspacing cellpadding>
  <tr>
    <td width="100%"><img border="0" src="image/top.gif" width="780" height="10"></td>
  </tr>
  <tr>
    <td width="100%"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="780" height="66" title="header">
      <param name="movie" value="flash/header.swf">
      <param name="quality" value="high">
      <embed src="flash/header.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="66"></embed></object></td>

  </tr>
  <tr>
    <td width="100%"><center></center>
      </td>
  </tr>
  <tr>
    <td width="100%" height="16" bgcolor="#FFB600"> </td>
  </tr>
  <tr>
    <td width="100%" bgcolor="#FFB600">
      <table width="100%" cellspacing cellpadding>
        <tr>
          <td width="30%" valign="top" align="left"><br>
            <p> </p>
            <div align="center">
              <center>
              <table border="0" width="80%" cellspacing="5" cellpadding="0">
                <tr>
			<td width="12%" valign="top" align="left"<img src="image/links_left.gif" width="205" height="294"></td>
			</tr>
			<tr>
                  <td width="100%" class="MainTitle">Breakroom Selection</td>
                </tr>
                <tr>
<?

$category = $_POST["category"];

if(strlen($category)>0)
{
	foreach ($_POST['category'] as  $category) 
	{ 
if ($category == "1")
		{
			$_SESSION['snack'] = "";
		}
		if ($category == "2")
		{
		$_SESSION['colddrink'] = "";
		}
		if ($category == "3")
		{
		$_SESSION['frozen'] = "";
		}
		if ($category == "4")
		{
		$_SESSION['hotbeverage'] = "";
		}
		if ($category == "5")
		{
		$_SESSION['watercooler'] = "";
		}
		if ($category == "6")
		{
		$_SESSION['bsupplies'] = "";
		}

	}
$category = $_POST["category"];

}

if ($_SESSION['ss_cust_id'] != "")
{
$sql = "SELECT tblcustcat.category_id,categoryName FROM tblcustcat,tblcategory where tblcustcat.category_id=tblcategory.category_id and cust_id=".$_SESSION['ss_cust_id'];
$result = mysql_query($sql);
$noofrow = mysql_num_rows($result);
}

$cnt = 0;
if ($_SESSION['snacktype'] != "")
{

 $cnt = $cnt + 1;
}
if ($_SESSION['drinktype'] != "")
{
	$cnt = $cnt + 1;	}
if ($_SESSION['coffeetype'] != "")
{
	$cnt = $cnt + 1;	}
if ($_SESSION['foodtype'] != "")
{
	$cnt = $cnt + 1;	}
if ($_SESSION['water_coolertype'] != "")
{
	$cnt = $cnt + 1;	}
if ($_SESSION['suppliestype'] != "")
{
	$cnt = $cnt + 1;	}


?>

                  <td width="100%" class="GeneralText"><span style="mso-bidi-font-size: 10.0pt; mso-fareast-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><? if ($cnt != 0) { echo " $cnt Items Selected "; }?></span>
                    <p></td>
                </tr>
                <tr>
                  <td width="100%"><?php
?>
<form method=post action=new_cust_final.php>
<?
if ($_SESSION['ss_cust_id'] != "")
{
echo "<table border=0 cellpadding=5 cellspacing=5 bordercolor=maroon width=90%>";
if ($_SESSION['snack'] != "")
{
$query = "select * from tblcategory where category_id=".$_SESSION['snack'];
$result = mysql_query($query);
$no = mysql_num_rows($result);
$array = mysql_fetch_object($result);
if ($no > 0)
{
	echo "<tr><Td width=10><input type=checkbox name=category[] value=".$_SESSION['snack']."></td><td class=GeneralText>".$array->categoryName."</td></tr>";

}
}
if ($_SESSION['colddrink'] != "")
{
$query = "select * from tblcategory where category_id=".$_SESSION['colddrink'];
$result = mysql_query($query);
$no = mysql_num_rows($result);
$array = mysql_fetch_object($result);
if ($no > 0)
{
	echo "<tr><Td width=10><input type=checkbox name=category[] value=".$_SESSION['colddrink']."></td><td class=GeneralText>".$array->categoryName."</td></tr>";
}
}
if ($_SESSION['frozen'] != "")
{
$query = "select * from tblcategory where category_id=".$_SESSION['frozen'];
$result = mysql_query($query);
$no = mysql_num_rows($result);
$array = mysql_fetch_object($result);
if ($no > 0)
{
	echo "<tr><Td width=10><input type=checkbox name=category[] value=".$_SESSION['frozen']."></td><td class=GeneralText>".$array->categoryName."</td></tr>";
}

}
if ($_SESSION['hotbeverage'] != "")
{
$query = "select * from tblcategory where category_id=".$_SESSION['hotbeverage'];
$result = mysql_query($query);
$no = mysql_num_rows($result);
$array = mysql_fetch_object($result);
if ($no > 0)
{
	echo "<tr><Td width=10><input type=checkbox name=category[] value=".$_SESSION['hotbeverage']."></td><td class=GeneralText>".$array->categoryName."</td></tr>";
}

}
if ($_SESSION['bsupplies'] != "")
{
$query = "select * from tblcategory where category_id=".$_SESSION['bsupplies'];

$result = mysql_query($query);
$no = mysql_num_rows($result);
$array = mysql_fetch_object($result);
if ($no > 0)
{
	echo "<tr><Td width=10><input type=checkbox name=category[] value=".$_SESSION['bsupplies']."></td><td class=GeneralText>".$array->categoryName."</td></tr>";
}

}

if ($_SESSION['watercooler'] != "")
{
$query = "select * from tblcategory where category_id=".$_SESSION['watercooler'];
$result = mysql_query($query);
$no = mysql_num_rows($result);
$array = mysql_fetch_object($result);
if ($no > 0)
{
	echo "<tr><Td width=10><input type=checkbox name=category[] value=".$_SESSION['watercooler']."></td><td class=GeneralText>".$array->categoryName."</td></tr>";
}

}
	?>
              </center>
	<Tr><Td colspan=2 align=center>
        <p align="left">
<?
	if ($_SESSION['snack'] == "" && $_SESSION['colddrink'] == "" && $_SESSION['frozen'] == "" && $_SESSION['hotbeverage'] == "" && $_SESSION['watercooler'] == "")
	{
	}
	else
	{
?>
	<input type=submit value=Remove class=button1>
<?
}
?>		
        </p>

	</td></tr></table>

              <center>
<?
}
?></center></td>
                </tr>
                <tr>
                  <td width="100%"><br>
<?				  		if ($_SESSION['snack'] == "" && $_SESSION['colddrink'] == "" && $_SESSION['bsupplies'] == "" && $_SESSION['frozen'] == "" && $_SESSION['hotbeverage'] == "" && $_SESSION['watercooler'] == "")
	{
	}
	else

	{ ?>

			  <input type="submit" value="Finish / Submit" name="B1" class="button3"><? } ?></td>
<?

$categoryName=$GET["categoryName"];
$subject = "Request For Vending Services Category Name: " . $_POST['category_id'];
//$subject = "Request For Vending Services";

				$msg = "Customer Name: $_POST[customer_name]\n";
				$msg .= "Company Name: $_POST[company_name]\n";
				$msg .= "Phone: $_POST[phone]\n";
				$msg .= "Address: $_POST[address]\n";
				$msg .= "City: $_POST[city]\n";
				$msg .= "No. of Employees: = $_POST[no_emp]\n";
                    $msg .= "E-Mail:  $_POST[email]\n";
				$msg .= "Category Name: $_POST[categoryName]\n";

				//Mail to Client

                        $mailheaders = "From: [email protected]\n";
					$mailheaders .= "$_POST[email]"."\r\n";
				    $mailheaders .= "Bcc: [email protected]"."\r\n";
					$headers .= "Bcc: [email protected]"."\r\n";
				//	$mailheaders .= "Bcc: [email protected]"."\r\n";
			        $mailheaders .= "MIME-Version: 1.0\n";
					$mailheaders .= "Content-type: text/html; charset=iso-8859-1\n";
					$mailheaders .= "X-Priority: 1\n";
					$mailheaders .= "X-MSMail-Priority: High\n";
					$mailheaders .= "X-Mailer: php\n";
			 		$To .= "$_POST[email]";
					mail($To,$subject,$msg,$mailheaders);
?>
			  
                </tr>
                <tr>
                  <td width="100%"></td>
                </tr>
              </table>
            </div>
          </td>
          <td width="70%" valign="top" align="left">
          			<?	 if($flag==1)
				{
				echo "<center><Br><br><Br>";
				echo $err_msg;
				echo "<Br>";
				echo "<input type=button onClick='javascript:history.back();' value='Try Again' class=button2>";
				?>
				<table border="0" width="100%" bgcolor="#FFB600">
				  <tr>
				    <td width="100%" height="175"> </td>
				  </tr>
				</table>
				<?
				}
				else
				{
				?>
   
            <p style="margin-left: 10" class="MainTitle">Build Your Breakroom</p>
            <p style="margin-left: 10" class="GeneralText"><span style="mso-bidi-font-size: 10.0pt; mso-fareast-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">Please
							select an item on the below to add machines /
                                services to your Breakroom</span></p>
            <div align="center">
              <center>
              <table border="0" width="90%" cellspacing="10" cellpadding="0">
                <tr>
                  <td width="30%" align="center" valign="bottom"><a href="snack.php"></a><a href="snack.php"><img border="0" src="image/buttons/snacks_img.jpg" width="75" height="98"></a><br>
                    <a href="snacktype.php" class="MainTitle">Snacks</a></td>
                  <td width="30%" align="center"  valign="bottom"><a href="drinktype.php"><img border="0" src="image/buttons/colddrink_img.jpg" width="75" height="96"></a><br>
                    <a href="drinktype.php" class="MainTitle">Cold Drinks</a></td>
                  <td width="30%" align="center" valign="bottom"><a href="foodtype.php"><img border="0" src="image/buttons/food_img.jpg" width="75" height="98"></a><br>
                    <a class="MainTitle" href="foodtype.php">Frozen / Cold Food</a></td>
                </tr>
                <tr>
                  <td width="30%" align="center"  valign="bottom"> 
                    <p><a href="coffeetype.php"><img border="0" src="image/buttons/coffee_img.jpg" width="77" height="84"></a><br>
                    <a class="MainTitle" href="coffeetype.php">Hot Beverage / Office Coffee</a></p>
                  </td>
                  <td width="30%" align="center"  valign="bottom"><a href="water_coolertype.php"><img border="0" src="image/buttons/watercooler_img.jpg" width="75" height="78"></a><br>
                    <a class="MainTitle" href="water_coolertype.php">Filter Water Coolers</a></td>
                  <td width="30%" align="center"  valign="bottom"><a href="suppliestype.php"><img border="0" src="image/buttons/supplies_img.jpg" width="75" height="86"></a><br>
                    <a class="MainTitle" href="suppliestype.php">Breakroom Supplies</a></td>

                </tr>
              </table>
		  <input type="submit" value="Finish / Submit" name="B1" class="button3">
              </center>
            </div>
            <p style="margin-left: 45; margin-right: 25" align="justify">
            <p style="margin-left: 45; margin-right: 25" align="justify"> <? } ?></center></td>

        </tr>
      </table>
    </td>

  </tr>
  
  <tr>
    <td width="100%"><img border="0" src="image/white.gif" width="780" height="1"></td>
  </tr>
  <tr>
    <td width="100%" bgcolor="#EC4C11" height="25">
      <p align="center"><font face="Arial" size="2" color="#FFFFFF">Copyright @
      2009 Georgia Vending
      Services                                                                                          
      Privacy Statement</font></td>
  </tr>
  <td width="100%">
    <p align="center"><font face="Arial" size="2"><b><a href="index.php"><font color="#FFFFFF">Home</font></a> 
      | <a href="about.html"><font color="#FFFFFF">About Us</font></a>  | <a href="community_services.html"><font color="#FFFFFF">Community Services</font></a> | <a href="emp_opp.php"><font color="#FFFFFF">Employment Opportunities</font></a> | <a href="contact.html"><font color="#FFFFFF">Contact Us</font></a> | <a href="new_customer.php"><font color="#FFFFFF">New Customer</font></a> | <a href="vending_services.html"><font color="#FFFFFF">Vending Services</font></a> <br> <a href="office_coffee.html"><font color="#FFFFFF">Office Coffee</font></a> | <a href="Whatsnew.php"><font color="#FFFFFF">Whats New</font></a>  |  <a href="manage.php"><font color="#FFFFFF">Newsletter</font></a></font></p>
    </td>    
</table>

	<?
		mysql_close($conn);
	?>
			</form>
</body>
</center>
</html>

Thank you

LadyDee

 

 

 

[attachment deleted by admin]

I think you meant $_POST['customer_name'] not $_POST['name'].

 

Think the above is the issue.

 

You have:-

 

      $name = $_POST["customer_name"];
      $sql = "insert into subscribers values('', '$_POST[email]', '$_POST[name]')";

 

Nowhere on your form do you have a field called name. You either mean $_POST[customer_name] or $name (either would be fine).

 

All the best

 

Keith

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.