Jump to content

How do I add a number?


designedfree4u

Recommended Posts

$_POST[count ++]  count ++ <-- will be treated as string here so no ++ or incrementing here

 

you need tto make it like this

 

$counter = 0;

$counter ++;

 

$_POST['count'.$counter]  or $_POST[$counter]

 

or you might want to loop it

 

for($i = 0; $i<n ; $i++){

echo $_POST[$i] ;

}

 

Link to comment
Share on other sites

I'm pretty new at this, here is the intire code. i added the new var, like you said, but i'm having trouble incorporating it into my code.

 

$counter = 0;

$counter ++;

 

Intire code:

<?php
$con = mysql_connect("localhost","******","******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
  $counter = 0;
  $counter ++;

  
mysql_select_db("jaybirdf_contestvote", $con);$sql="INSERT INTO Jason (email,count)


VALUES
('$_POST[email]','$_POST[count]')";if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";mysql_close($con)
?>

 

Link to comment
Share on other sites

You're right, you can't use ++ with POST arrays, but you can just do plain old + 1.

 

$count = $_POST['count'] + 1;
mysql_select_db("jaybirdf_contestvote", $con);
$sql="INSERT INTO Jason (email,count) VALUES ('$_POST[email]','$count')";

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.