miscreant Posted May 11, 2010 Share Posted May 11, 2010 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/201410-passing-a-returned-variable-with-a-1/ Share on other sites More sharing options...
kenrbnsn Posted May 11, 2010 Share Posted May 11, 2010 That's not the correct way of adding 1 to a value. The correct was is either <?php $var = $var +1; ?> or <?php $var++; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/201410-passing-a-returned-variable-with-a-1/#findComment-1056728 Share on other sites More sharing options...
miscreant Posted May 11, 2010 Author Share Posted May 11, 2010 I am really new at this where would I need to put that? Quote Link to comment https://forums.phpfreaks.com/topic/201410-passing-a-returned-variable-with-a-1/#findComment-1056743 Share on other sites More sharing options...
greatstar00 Posted May 11, 2010 Share Posted May 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201410-passing-a-returned-variable-with-a-1/#findComment-1056761 Share on other sites More sharing options...
miscreant Posted May 11, 2010 Author Share Posted May 11, 2010 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) ?> Quote Link to comment https://forums.phpfreaks.com/topic/201410-passing-a-returned-variable-with-a-1/#findComment-1056782 Share on other sites More sharing options...
miscreant Posted May 11, 2010 Author Share Posted May 11, 2010 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) ?> Quote Link to comment https://forums.phpfreaks.com/topic/201410-passing-a-returned-variable-with-a-1/#findComment-1056792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.