Jump to content

How do I add a number?


designedfree4u

Recommended Posts

How do I add a number to a certain field? I want to add 1 number to every entry into the field named count

 

('$_POST[email]','$_POST[count]')";if (!mysql_query($sql,$con))

 

I tryed: but doesn't work

('$_POST[email]','$_POST[count ++]')";if (!mysql_query($sql,$con))

 

Any help?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/147248-how-do-i-add-a-number/
Share on other sites

$_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] ;

}

 

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)
?>

 

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.