Jump to content

Passing a returned variable with a +1


miscreant

Recommended Posts

<?php

$con = mysql_connect("localhost","user","pass");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("spotid", $con);

 

$query = "SELECT spot_id FROM spot_num ORDER BY spot_id LIMIT 0,1";

 

$result = mysql_query($query);

 

while ($row = mysql_fetch_array($result)) {

$row[spot_id]+1;

}                                 

 

$sql="INSERT INTO spot_num (name_id, spot_id)

VALUES

('$_POST[name_id]','$_POST[$row]')";

 

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo $_POST[name_id],$_POST[$row];

 

mysql_close($con)

?>

 

 

 

 

 

This works up to here "$row[spot_id]+1"  everything below that  works with the exception "$_POST[$row]" I want to pass the "$row[spot_id]+1" to "$_POST[$row]"

So when someone fills out the form page it will then pass along what they enter on the form page on submit, it will then query the DB for the [spot_id] then increment by 1 then write both the incremented value and the users form information back to the DB.

 

Help

 

Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/201410-passing-a-returned-variable-with-a-1/
Share on other sites

he is saying

$row[spot_id]+1;

is incorrect, although it added 1, and it didnt save the result somewhere, and the computer will soon replaced this memory chunk with some other variables

so, what it means, the result produced by above code is garbage

 

so, change that to what he suggested

Ok I have tried this it is not incrementing but it is posting the single Value of 1 in spot_id

 

while ($row = mysql_fetch_array($result))

$row[spot_id] = $plus++;

 

$sql="INSERT INTO spot_num (name_id, spot_id)

VALUES

('$_POST[name_id]','$plus')";

 

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo $_POST[name_id],$plus;

 

mysql_close($con)

?>

Got it Thank you all so much.

 

I also had to add this to the sql query..  DESC

 

 

<?php

$con = mysql_connect("localhost","user","pass");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("spotid", $con);

 

$query = "SELECT spot_id FROM spot_num ORDER BY spot_id DESC LIMIT 0,1";

 

$result = mysql_query($query);

 

while ($row = mysql_fetch_array($result))

$plus = $row[spot_id] +1;

 

$sql="INSERT INTO spot_num (name_id, spot_id)

VALUES

('$_POST[name_id]','$plus')";

 

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo $_POST[name_id],$plus;

 

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.