Jump to content

Wrong var posted to DB


forumnz

Recommended Posts

I have a user select their region from a drop down list. I want some regions to be isolated and some to include others (if that makes sense). Anyway, the user submits the form with the region value. The variable is named $region.

 

I wrote this extra but, but the script still inserts 0 into all three db columns.

 

if($region == 0)
{
$reg1 == 0;
$reg2 == 0;
$reg3 == 0;
}
elseif($region >=2 && $region <=13)
{
$reg1 == 0;
$reg2 == 2;
$reg3 == $region;
}
elseif($region >=14 && $region <=21)
{
$reg1 == 0;
$reg2 == 14;
$reg3 == $region;
}

 

Thanks for your help!

Sam.

 

Link to comment
Share on other sites

Ok here it is:

 

<?php
$buzzname=$_POST['buzzname'];
$sub=$_POST['sub'];
$descr=$_POST['descr'];
$keyw=$_POST['keyw'];
$addst=$_POST['addst'];
$addsu=$_POST['addsu'];
$addci=$_POST['addci'];
$region=$_POST['region'];
$addpc=$_POST['addpc'];
$ph=$_POST['ph'];
$ph2=$_POST['ph2'];
$freeph=$_POST['freeph'];
$fax=$_POST['fax'];
$email=$_POST['email'];


if($region == 0)
{
$reg1 == 0;
$reg2 == 0;
$reg3 == 0;
}
elseif($region >=2 && $region <=13)
{
$reg1 == 0;
$reg2 == 2;
$reg3 == $region;
}
elseif($region >=14 && $region <=21)
{
$reg1 == 0;
$reg2 == 14;
$reg3 == $region;
}

$uid = $_SESSION['id'];

include('dbcon.php');

$sql="INSERT INTO cmads (buzzname, sub, descr, keyw, addst, addsu, addci, region, region2, region3, addpc, userid, ph, ph2, freeph, fax, email) VALUES ('$buzzname','$sub','$descr','$keyw','$addst','$addsu','$addci','$reg1','$reg2','$reg3','$addpc','$uid','$ph','$ph2','$freeph','$fax','$email')";

if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added" . $reg1 . $reg2 . $reg3 . "<br>" . $region;

?>

 

As you can see at the bottom I echoed the three regions, but it only displayed:

1 record added
13

Link to comment
Share on other sites

Like this?

 

if($region == '0')
{
$reg1 == '0';
$reg2 == '0';
$reg3 == '0';
}
elseif($region >='2' && $region <='13')
{
$reg1 == '0';
$reg2 == '2';
$reg3 == $region;
}
elseif($region >='14' && $region <='21')
{
$reg1 == '0';
$reg2 == '14';
$reg3 == $region;
}

 

Still doesn't work.

 

Any ideas?

Sam.

Link to comment
Share on other sites

Change the == to = within the body of the if's

>:( Bah, can't believe I missed that. Oh well, that happens when you're skimming code at work.

 

@forumnz: I generally use d ouble quotes for everything except for inside square ([ ]) brackets. I have no idea if one or the other is better/faster in terms of code execution or parsing.

Link to comment
Share on other sites

so ..

echo 'This is a string';

would be faster than?

echo "This is a string";

 

 

 

 

yep becouse ' single quotes dont phase throw php like  double quotes....

 

in other words php use the " double quotes to do somethink with..........

 

example

<?php
echo ' this is a litrall  $redarrow will not be echoed out';

$redarrow='hi there i am redarrow';

echo"this is a phased  $redarrow will echo";
?>

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.