I am new to php and mysql so it may be that I am missing something obvious but here goes:
I am setting up a database to store items with stock. Each item is assigned an amount of stock (e.g. 5). Each item is displayed on my webpage with buttons next to it to manually add or remove stock from the database:
$query = "SELECT * FROM classes"; // This uses a mysql function that act upon our $query variable above $result = mysql_query($query); // This is a loop that says "while there is data to display...keep looping round and displaying that data". while($class_data = mysql_fetch_array($result)) { // Now we are going to echo that data echo "<div class=\"classmanagertablecontent\">" . $class_data['name'] . "</div> <div class=\"classmanagertablecontent\">" . $date['date'] . "</div> <div class=\"classmanagertablecontent\">" . $class_data['stock'] . "</div> <div class=\"classmanagertablecontent\">" . $class_data['button_paypal'] . "</div>"; <form action="../url.php" method="post"> <input type="hidden" name="button_paypal_fromform" value="<?php echo $class_data['button_paypal'] ?>"> <input type="submit" value="remove stock" name="remove stock"> </form> <form action="../url.php" method="post"> <input type="hidden" name="button_paypal_fromform" value="<?php echo $class_data['button_paypal'] ?>"> <input type="submit" value="add to stock" name="add to stock" > </form> </div> } The code in the url that the "add to stock" button posts to is as follows:
<?php $button_paypal = $_POST['button_paypal_fromform']; mysql_query("UPDATE classes SET stock = stock+1 WHERE button_paypal = ". $button_paypal .""); ?> For whatever reason WHERE button_paypal = "a number" it works... ...but if button_paypal = "a string" it does nothing.
I cannot get my head around this. The paypal hosted buttons I will be using are made up of letter and numbers so it need to work with a combination of the two.
I have tried...
echo "$button_paypal"; ...on my url.php page and the button reads fine (e.g. SD76S9SFGV)
in my database "button_paypal" is a TEXT field but i have also tried VARCHAR. STOCK is an INT.
If anyone can help then I will be very grateful. Thanks. #hopethismakessense
code.