Jump to content

[SOLVED] Need some help with PHP/MySQL Bookstore


sstoveld

Recommended Posts

ok well i hope that works otherwise i will have to find something else if its wrong and there cant possibly be thet much more to do before this all works perfectly

 

haha lets hope so :P

 

ok well it didnt seem to work. i think i did everything you said to.

 

here's a screen of my terminal:

term.jpg

 

and here's my pastebin:

http://pastebin.com/m5744715a

 

see something wrong?

change

$sql = "UPDATE stock SET quantity = quantity - 1 WHERE stock_id = '$id'";
if (!mysql_query($sql)){

 

to

echo('submit working');
$sql = "UPDATE stock SET quantity = quantity - 1 WHERE stock_id = '$id'";
$result = mysql_query($sql)
if (!$result){

change

$sql = "UPDATE stock SET quantity = quantity - 1 WHERE stock_id = '$id'";
if (!mysql_query($sql)){

 

to

echo('submit working');
$sql = "UPDATE stock SET quantity = quantity - 1 WHERE stock_id = '$id'";
$result = mysql_query($sql)
if (!$result){

 

getting a parse error :( line 38

 

http://pastebin.com/m2b56cc81

 

Parse error: parse error, unexpected T_IF in /Users/dbase18/Sites/bookstore/index.php on line 38

finally your form is wrong aswell lol didnt spot that

 

replace

 
<table>
<tr>
<td><strong>Title</strong></td>
<td><strong>Stock</strong></td>
<td><strong>Price</strong></td>
</tr>

<?php


/////////// RESULTS OF QUERY AND PUBLISH TO TABLE ///////////

while ($row = mysql_fetch_array($queryresult)){
echo '<tr><td>'.$row['title'].'</td><td>'.$row['quantity'].'</td><td>'.$row['price'].'</td><td><input type="radio" name="'.$row['title'].'" value="'.$row['stock_id'].'"></td></tr>';

}

?>

</table>

<p>
<form name="submit" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="submit" value="Submit" name="submit" />
</form>
</p> 

 

with

<p>
   <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post">
      <table>
         <tr>
            <td><strong>Title</strong></td>
            <td><strong>Stock</strong></td>
            <td><strong>Price</strong></td>
         </tr>
         <?php
            while ($row = mysql_fetch_array($queryresult))
            {
               echo('<tr><td>' . $row['title'] . '</td><td>' . $row['quantity'] . '</td><td>' . $row['price'] . '</td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>');
            }
         ?>
         <input type="submit" value="Submit" name="submit" />
      </form>
   </table>
</p>

 

p.s. soz bout missin off the semi-colon XD

finally your form is wrong aswell lol didnt spot that

 

replace

 
<table>
<tr>
<td><strong>Title</strong></td>
<td><strong>Stock</strong></td>
<td><strong>Price</strong></td>
</tr>

<?php


/////////// RESULTS OF QUERY AND PUBLISH TO TABLE ///////////

while ($row = mysql_fetch_array($queryresult)){
echo '<tr><td>'.$row['title'].'</td><td>'.$row['quantity'].'</td><td>'.$row['price'].'</td><td><input type="radio" name="'.$row['title'].'" value="'.$row['stock_id'].'"></td></tr>';

}

?>

</table>

<p>
<form name="submit" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="submit" value="Submit" name="submit" />
</form>
</p> 

 

with

<p>
   <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post">
      <table>
         <tr>
            <td><strong>Title</strong></td>
            <td><strong>Stock</strong></td>
            <td><strong>Price</strong></td>
         </tr>
         <?php
            while ($row = mysql_fetch_array($queryresult))
            {
               echo('<tr><td>' . $row['title'] . '</td><td>' . $row['quantity'] . '</td><td>' . $row['price'] . '</td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>');
            }
         ?>
         <input type="submit" value="Submit" name="submit" />
      </form>
   </table>
</p>

 

p.s. soz bout missin off the semi-colon XD

 

OMG YES! it works! hahah thanks so much

 

it works now, but my submit button is floating above the table lol. i had that problem earlier so i moved the form action stuff below where it was. i guess that was a bad idea :P how do i get the submit button below the table?

 

also have another question..., how do i make the radio button not show up there if the quantity is at 0 (so the user cant make it go to -1)?

lol almost done hehe

 

<p>
   <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post">
      <table>
         <tr>
            <td><strong>Title</strong></td>
            <td><strong>Stock</strong></td>
            <td><strong>Price</strong></td>
            </tr>
            <?php
               while ($row = mysql_fetch_array($queryresult))
               {
                  if($row['quantity'] > 0)
                  {
                     echo('<tr><td>' . $row['title'] . '</td><td>' . $row['quantity'] . '</td><td>' . $row['price'] . '</td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>');
                  }else{
                     echo('<tr><td>' . $row['title'] . '</td><td>' . $row['quantity'] . '</td><td>' . $row['price'] . '</td><td>Out of Stock, Sorry.</td></tr>');
                  }
               }
            ?>
         <tr><td><input type="submit" value="Submit" name="submit" /></td></tr>
      </form>
   </table>
</p>

 

try that

 

p.s. could you link me to the page by any chance coz i would just like to see how it is looking and operating if not its ok im just curious lol

lol almost done hehe

 

<p>
   <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post">
      <table>
         <tr>
            <td><strong>Title</strong></td>
            <td><strong>Stock</strong></td>
            <td><strong>Price</strong></td>
            </tr>
            <?php
               while ($row = mysql_fetch_array($queryresult))
               {
                  if($row['quantity'] > 0)
                  {
                     echo('<tr><td>' . $row['title'] . '</td><td>' . $row['quantity'] . '</td><td>' . $row['price'] . '</td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>');
                  }else{
                     echo('<tr><td>' . $row['title'] . '</td><td>' . $row['quantity'] . '</td><td>' . $row['price'] . '</td><td>Out of Stock, Sorry.</td></tr>');
                  }
               }
            ?>
         <tr><td><input type="submit" value="Submit" name="submit" /></td></tr>
      </form>
   </table>
</p>

 

try that

 

p.s. could you link me to the page by any chance coz i would just like to see how it is looking and operating if not its ok im just curious lol

 

absolutely perfect! thanks so much. now i just gotta get the administration back end done :P ill most likely be back to bother you guys again

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.