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

Link to comment
Share on other sites

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)

?>

Link to comment
Share on other sites

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)

?>

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.