sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 Your not using title_id in your query so why do you need it? i need it for the front end of the bookstore that displays a list of all the titles with their prices and quantities. if its not inserted with it, it wont show the title in the front end table Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791366 Share on other sites More sharing options...
trq Posted March 23, 2009 Share Posted March 23, 2009 Just call mysql_insert_id() after the inserts are done. Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791369 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 Just call mysql_insert_id() after the inserts are done. oh $title_id = mysql_insert_id(); like that? edit: oh nvm, i got it thanks $sql2 = "INSERT INTO stock SET title_id='$title_id', quantity='$quantity', price='$price';"; that part is working now thanks now i gotta make it so the user can edit the quantity and price of the existing titles in the db Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791372 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 i thought i'd try it myself but it seems i'm lost without help lol. here's what the table currently looks like: i need it to have all the price and quantity fields replaced with forms that the user can edit, then select the radio button for which one he wants to update, then hit the submit button for it to update it here's my current pastebin: http://pastebin.com/m2461827e <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Administration</title> <link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="banner"> <h1><center><a href="index.php">Bookstore Administration</a></center></h1> </div><!-- banner --> <div id="mainContent"> <?php echo "<pre>",print_r($_POST),"</pre>"; ////////// CONNECT TO SERVER ////////// $dbcnx = @mysql_connect('localhost', 'dbase18', '*******') or die ('I cannot connect to the database because: ' .mysql_error()); ///////// CONNECT TO DATABASE //////////// mysql_select_db('dbase18', $dbcnx); if (!@mysql_select_db('dbase18')) { exit ('<p>Error in query.'. mysql_error(). '<p>'); } /////////// FIRST SQL QUERY /////////// if (isset($_POST['update'])){ $books_id=$_POST['books_id']; $title = htmlentities($_POST['title']); $sql1 = "INSERT INTO books SET title='$title'"; if (!mysql_query($sql1)){ echo "<p>Error updating. ".mysql_error()."</p>"; } } /////////// GET PRIMARY KEY FROM PREVIOUS QUERY ///////// $title_id = mysql_insert_id(); ////////// SECOND SQL QUERY ////////// if (isset($_POST['update'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql2 = "INSERT INTO stock SET title_id='$title_id', quantity='$quantity', price='$price';"; if (!mysql_query($sql2)) { echo "<p>Error updating. ".mysql_error()." $sql2</php>"; }else{ echo "<p>Updated successfully.</p>"; } } ////////// QUERY DATABASE ////////// $queryresult = @mysql_query('SELECT stock_id, title, quantity, price FROM stock LEFT JOIN books ON stock.title_id = books.books_id ORDER BY title;'); if (!$queryresult) { exit ('<p>Error in query.'. mysql_error().'</p>'); } ///////// MAKE A TABLE CONTAINING FORMS FOR USER TO ADD NEW TITLES ////////// ?> <p> <h2>Add Titles</h2> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <form name="edit" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <tr> <td><input name="title" type="text" value="<?php echo $title; ?>" size="30" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="quantity" type="text" value="<?php echo $quantity; ?>" size="4" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="price" type="text" value="<?php echo $price; ?>" size="6" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="update" type="submit" value="update"></td> </tr> </form> </table> </p> <p> <h2>Update quantities and prices</h2> <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post"> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</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>'); } ?> <tr><td colspan="4"><input type="submit" value="Submit" name="submit" /></td></tr> </form> </table> </p> </div><!-- mainContent --> <div id="footer"> <p>Coded and designed by: <a href="mailto:[email protected]">Steve Stoveld</a></p> </div><!-- footer --> </div><!-- wrapper --> </body> </html> im not sure how to fit it in there :/ Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791390 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 ok ive got just about everything working now, except when i update the prices for the stock and quantities, it's taking them from the wrong place. it seems to be taking it from the last title in the list eg: Watchmen pastebin: http://pastebin.com/m3a604c <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Administration</title> <link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="banner"> <h1><center><a href="index.php">Bookstore Administration</a></center></h1> </div><!-- banner --> <div id="mainContent"> <?php ////////// CONNECT TO SERVER ////////// $dbcnx = @mysql_connect('localhost', 'dbase18', '*******') or die ('I cannot connect to the database because: ' .mysql_error()); ///////// CONNECT TO DATABASE //////////// mysql_select_db('dbase18', $dbcnx); if (!@mysql_select_db('dbase18')) { exit ('<p>Error in query.'. mysql_error(). '<p>'); } /////////// FIRST SQL QUERY /////////// if (isset($_POST['update'])){ $books_id=$_POST['books_id']; $title = htmlentities($_POST['title']); $sql1 = "INSERT INTO books SET title='$title'"; if (!mysql_query($sql1)){ echo "<p>Error updating. ".mysql_error()."</p>"; } } /////////// GET PRIMARY KEY FROM PREVIOUS QUERY ///////// $title_id = mysql_insert_id(); ////////// SECOND SQL QUERY ////////// if (isset($_POST['update'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql2 = "INSERT INTO stock SET title_id='$title_id', quantity='$quantity', price='$price';"; if (!mysql_query($sql2)) { echo "<p>Error updating. ".mysql_error()." $sql2</php>"; }else{ echo "<p>Updated successfully.</p>"; } } ////////// QUERY DATABASE ////////// $queryresult = @mysql_query('SELECT stock_id, title, quantity, price FROM stock LEFT JOIN books ON stock.title_id = books.books_id ORDER BY title;'); if (!$queryresult) { exit ('<p>Error in query.'. mysql_error().'</p>'); } ///////// MAKE A TABLE CONTAINING FORMS FOR USER TO ADD NEW TITLES ////////// ?> <p> <h2>Add Titles</h2> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <form name="edit" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <tr> <td><input name="title" type="text" value="<?php echo $title; ?>" size="30" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="quantity" type="text" value="<?php echo $quantity; ?>" size="4" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="price" type="text" value="<?php echo $price; ?>" size="6" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="update" type="submit" value="update"></td> </tr> </form> </table> </p> <p> <h2>Update quantities and prices</h2> <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post"> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <?php echo "<pre>",print_r($_POST),"</pre>"; /////////// QUERY //////////////////// if (isset($_POST['subsend'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='$stock_id';"; if (!mysql_query($sql3)) { echo "<p>Error updating. ".mysql_error()." $sql3</php>"; }else{ echo "<p>Updated successfully.</p>"; } } while ($row = mysql_fetch_array($queryresult)) { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> <tr><td colspan="4"><input type="submit" value="Submit" name="subsend" /></td></tr> </form> </table> </p> </div><!-- mainContent --> <div id="footer"> <p>Coded and designed by: <a href="mailto:[email protected]">Steve Stoveld</a></p> </div><!-- footer --> </div><!-- wrapper --> </body> </html> its taking the values from the 2 fields from Watchmen, instead of the ones from other titles Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791458 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 sorry for the spam, but i cant edit my last post... but for instance, if i put in a quantity of 1 and a price of 1.00 in the Watchmen row, and selected the radio button for Linked, it would update the quantity and price for Linked with the values for Watchmen instead of the values for linked Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791483 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 let all understand this. are you saying that , when you use this code it updating but in reverse order. so if you update two fields it does it but backwards putting the info in but in the wrong fields reverse, or in fields but not the correct ones. <h2>Update quantities and prices</h2> <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post"> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <?php echo "<pre>",print_r($_POST),"</pre>"; /////////// QUERY //////////////////// if (isset($_POST['subsend'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='$stock_id';"; if (!mysql_query($sql3)) { echo "<p>Error updating. ".mysql_error()." $sql3</php>"; }else{ echo "<p>Updated successfully.</p>"; } } while ($row = mysql_fetch_array($queryresult)) { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791502 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 let all understand this. are you saying that , when you use this code it updating but in reverse order. so if you update two fields it does it but backwards putting the info in but in the wrong fields reverse. <h2>Update quantities and prices</h2> <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post"> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <?php echo "<pre>",print_r($_POST),"</pre>"; /////////// QUERY //////////////////// if (isset($_POST['subsend'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='$stock_id';"; if (!mysql_query($sql3)) { echo "<p>Error updating. ".mysql_error()." $sql3</php>"; }else{ echo "<p>Updated successfully.</p>"; } } while ($row = mysql_fetch_array($queryresult)) { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> well no, whatever i have in the 2 fields for watchmen, those values will be put into whatever radio button i select. so say i put 1 and 1.00 into the quantity and price fields for LINKED, and put 99 and 99.99 in the quantity and price fields for WATCHMEN, and select the radio button for LINKED, LINKED will be updated to 99 and 99.99. it takes whatever is in the fields for WATCHMEN, and puts it into whatever title i select, whichever radio button i select. i cant figure out why Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791503 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 this select statement is the problam i think you need to create another then update. i say that because all the variables are correct. only conclusion i got as the while loop ends after the update statement (( must be that i am guessing here)) or i mean the while loop used is on a join,you only need the stock i d am i right. $queryresult = @mysql_query('SELECT stock_id, title, quantity, price FROM stock LEFT JOIN books ON stock.title_id = books.books_id ORDER BY title;'); if (!$queryresult) { exit ('<p>Error in query.'. mysql_error().'</p>'); } Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791505 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 while ($row = mysql_fetch_array($queryresult)) <<< i mean this why are you selecting this and not selecting what in the databse cheek your database it is updating. your selecting old info with new updated info. i might be wrong but as you post cheek the database for the correct figures do they really go into the correct database fields. would that do anything different i don't no so always back up. it a complete guess. <?php $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='{$queryresult['stock_id']}';"; ?> Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791517 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 while ($row = mysql_fetch_array($queryresult)) <<< i mean this why are you selecting this and not selecting what in the databse cheek your database it is updating. your selecting old info with new updated info. would that do anything different i don't no so always back up. it a complete guess. <?php $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='{$queryresult['stock_id']}';"; ?> no go man Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791522 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 let me explain properly, if i use a join to collect the info i need,, then i need to update via that join, and out put info with a new select to show the new updated info. your selecting the joined info not the new collected info you dont need to use a join will you. get mixed results. i might be completely wrong sorry if i am. Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791523 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 let me explain properly, if i use a join to collect the info i need,, then i need to update via that join, and out put info with a new select to show the new updated info. your selecting the joined info not the new collected info you dont need to use a join will you. get mixed results. im sorry im not following you on that. i dont understand. Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791525 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 your currenly showing the join sql while ($row = mysql_fetch_array($queryresult))<<<< goes to a join { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> while ($row = mysql_fetch_array($queryresult))<<<< goes to a join it selecting this $queryresult = @mysql_query('SELECT stock_id, title, quantity, price FROM stock LEFT JOIN books ON stock.title_id = books.books_id ORDER BY title;'); if (!$queryresult) { exit ('<p>Error in query.'. mysql_error().'</p>'); } that was to get the info to curretly update the database .... you need a new select to show what in the database now... your not showing what in the current database that was updated. might be wrong Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791526 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 your currenly showing the join sql while ($row = mysql_fetch_array($queryresult))<<<< goes to a join { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> your not showing what in the current database that was updated. might be wrong oh i think i understand what you're saying. how do i show the updated database? Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791527 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 trie this please always update info <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Administration</title> <link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="banner"> <h1><center><a href="index.php">Bookstore Administration</a></center></h1> </div><!-- banner --> <div id="mainContent"> <?php ////////// CONNECT TO SERVER ////////// $dbcnx = @mysql_connect('localhost', 'dbase18', '*******') or die ('I cannot connect to the database because: ' .mysql_error()); ///////// CONNECT TO DATABASE //////////// mysql_select_db('dbase18', $dbcnx); if (!@mysql_select_db('dbase18')) { exit ('<p>Error in query.'. mysql_error(). '<p>'); } /////////// FIRST SQL QUERY /////////// if (isset($_POST['update'])){ $books_id=$_POST['books_id']; $title = htmlentities($_POST['title']); $sql1 = "INSERT INTO books SET title='$title'"; if (!mysql_query($sql1)){ echo "<p>Error updating. ".mysql_error()."</p>"; } } /////////// GET PRIMARY KEY FROM PREVIOUS QUERY ///////// $title_id = mysql_insert_id(); ////////// SECOND SQL QUERY ////////// if (isset($_POST['update'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql2 = "INSERT INTO stock SET title_id='$title_id', quantity='$quantity', price='$price';"; if (!mysql_query($sql2)) { echo "<p>Error updating. ".mysql_error()." $sql2</php>"; }else{ echo "<p>Updated successfully.</p>"; } } ////////// QUERY DATABASE ////////// $queryresult = @mysql_query('SELECT stock_id, title, quantity, price FROM stock LEFT JOIN books ON stock.title_id = books.books_id ORDER BY title;'); if (!$queryresult) { exit ('<p>Error in query.'. mysql_error().'</p>'); } ///////// MAKE A TABLE CONTAINING FORMS FOR USER TO ADD NEW TITLES ////////// ?> <p> <h2>Add Titles</h2> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <form name="edit" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <tr> <td><input name="title" type="text" value="<?php echo $title; ?>" size="30" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="quantity" type="text" value="<?php echo $quantity; ?>" size="4" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="price" type="text" value="<?php echo $price; ?>" size="6" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="update" type="submit" value="update"></td> </tr> </form> </table> </p> <p> <h2>Update quantities and prices</h2> <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post"> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <?php echo "<pre>",print_r($_POST),"</pre>"; /////////// QUERY //////////////////// if (isset($_POST['subsend'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='$stock_id';"; if (!mysql_query($sql3)) { echo "<p>Error updating. ".mysql_error()." $sql3</php>"; }else{ echo "<p>Updated successfully.</p>"; } } $updated_echo = @mysql_query('SELECT * FROM stock'); while ($row = mysql_fetch_array($updated_echo)) { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> <tr><td colspan="4"><input type="submit" value="Submit" name="subsend" /></td></tr> </form> </table> </p> </div><!-- mainContent --> <div id="footer"> <p>Coded and designed by: <a href="mailto:[email protected]">Steve Stoveld</a></p> </div><!-- footer --> </div><!-- wrapper --> </body> </html> Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791529 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 trie this please always update info <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Administration</title> <link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="banner"> <h1><center><a href="index.php">Bookstore Administration</a></center></h1> </div><!-- banner --> <div id="mainContent"> <?php ////////// CONNECT TO SERVER ////////// $dbcnx = @mysql_connect('localhost', 'dbase18', '*******') or die ('I cannot connect to the database because: ' .mysql_error()); ///////// CONNECT TO DATABASE //////////// mysql_select_db('dbase18', $dbcnx); if (!@mysql_select_db('dbase18')) { exit ('<p>Error in query.'. mysql_error(). '<p>'); } /////////// FIRST SQL QUERY /////////// if (isset($_POST['update'])){ $books_id=$_POST['books_id']; $title = htmlentities($_POST['title']); $sql1 = "INSERT INTO books SET title='$title'"; if (!mysql_query($sql1)){ echo "<p>Error updating. ".mysql_error()."</p>"; } } /////////// GET PRIMARY KEY FROM PREVIOUS QUERY ///////// $title_id = mysql_insert_id(); ////////// SECOND SQL QUERY ////////// if (isset($_POST['update'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql2 = "INSERT INTO stock SET title_id='$title_id', quantity='$quantity', price='$price';"; if (!mysql_query($sql2)) { echo "<p>Error updating. ".mysql_error()." $sql2</php>"; }else{ echo "<p>Updated successfully.</p>"; } } ////////// QUERY DATABASE ////////// $queryresult = @mysql_query('SELECT stock_id, title, quantity, price FROM stock LEFT JOIN books ON stock.title_id = books.books_id ORDER BY title;'); if (!$queryresult) { exit ('<p>Error in query.'. mysql_error().'</p>'); } ///////// MAKE A TABLE CONTAINING FORMS FOR USER TO ADD NEW TITLES ////////// ?> <p> <h2>Add Titles</h2> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <form name="edit" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <tr> <td><input name="title" type="text" value="<?php echo $title; ?>" size="30" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="quantity" type="text" value="<?php echo $quantity; ?>" size="4" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="price" type="text" value="<?php echo $price; ?>" size="6" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="update" type="submit" value="update"></td> </tr> </form> </table> </p> <p> <h2>Update quantities and prices</h2> <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post"> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <?php echo "<pre>",print_r($_POST),"</pre>"; /////////// QUERY //////////////////// if (isset($_POST['subsend'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='$stock_id';"; if (!mysql_query($sql3)) { echo "<p>Error updating. ".mysql_error()." $sql3</php>"; }else{ echo "<p>Updated successfully.</p>"; } } $updated_echo = @mysql_query('SELECT * FROM stock'); while ($row = mysql_fetch_array($updated_echo)) { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> <tr><td colspan="4"><input type="submit" value="Submit" name="subsend" /></td></tr> </form> </table> </p> </div><!-- mainContent --> <div id="footer"> <p>Coded and designed by: <a href="mailto:[email protected]">Steve Stoveld</a></p> </div><!-- footer --> </div><!-- wrapper --> </body> </html> nah it didnt work Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791530 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 when you look at the stock table from the database is it getting the correct info yes or no. dont look at the script or browser look at php myadmin ..... when you update are the write fields getting updated correctly please. ive looked at your code and the update must be going in correctly. Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791533 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 when you look at the stock table from the database is it getting the correct info yes or no. dont look at the script or browser look at php myadmin ..... when you update are the write fields getting updated correctly please. ive looked at your code and the update must be going in correctly. the stock table from the database is reflecting the same info as the browser is showing Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791541 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 what all the ids for in hidden form <td><input name="title" type="text" value="<?php echo $title; ?>" size="30" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="quantity" type="text" value="<?php echo $quantity; ?>" size="4" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="price" type="text" value="<?php echo $price; ?>" size="6" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="update" type="submit" value="update"></td> Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791543 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 what all the ids for in hidden form <td><input name="title" type="text" value="<?php echo $title; ?>" size="30" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="quantity" type="text" value="<?php echo $quantity; ?>" size="4" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="price" type="text" value="<?php echo $price; ?>" size="6" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="update" type="submit" value="update"></td> im actually not sure lol, i re-used some old code and might have overlooked that. should i get rid of all of that? or not? im afraid to break this lol Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791545 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 echo the update sql please.... Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791547 Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 update and post what comes on the browser. remember the values you just updated please... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Administration</title> <link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="banner"> <h1><center><a href="index.php">Bookstore Administration</a></center></h1> </div><!-- banner --> <div id="mainContent"> <?php ////////// CONNECT TO SERVER ////////// $dbcnx = @mysql_connect('localhost', 'dbase18', '*******') or die ('I cannot connect to the database because: ' .mysql_error()); ///////// CONNECT TO DATABASE //////////// mysql_select_db('dbase18', $dbcnx); if (!@mysql_select_db('dbase18')) { exit ('<p>Error in query.'. mysql_error(). '<p>'); } /////////// FIRST SQL QUERY /////////// if (isset($_POST['update'])){ $books_id=$_POST['books_id']; $title = htmlentities($_POST['title']); $sql1 = "INSERT INTO books SET title='$title'"; if (!mysql_query($sql1)){ echo "<p>Error updating. ".mysql_error()."</p>"; } } /////////// GET PRIMARY KEY FROM PREVIOUS QUERY ///////// $title_id = mysql_insert_id(); ////////// SECOND SQL QUERY ////////// if (isset($_POST['update'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql2 = "INSERT INTO stock SET title_id='$title_id', quantity='$quantity', price='$price';"; if (!mysql_query($sql2)) { echo "<p>Error updating. ".mysql_error()." $sql2</php>"; }else{ echo "<p>Updated successfully.</p>"; } } ////////// QUERY DATABASE ////////// $queryresult = @mysql_query('SELECT stock_id, title, quantity, price FROM stock LEFT JOIN books ON stock.title_id = books.books_id ORDER BY title;'); if (!$queryresult) { exit ('<p>Error in query.'. mysql_error().'</p>'); } ///////// MAKE A TABLE CONTAINING FORMS FOR USER TO ADD NEW TITLES ////////// ?> <p> <h2>Add Titles</h2> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <form name="edit" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <tr> <td><input name="title" type="text" value="<?php echo $title; ?>" size="30" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="quantity" type="text" value="<?php echo $quantity; ?>" size="4" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="price" type="text" value="<?php echo $price; ?>" size="6" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="update" type="submit" value="update"></td> </tr> </form> </table> </p> <p> <h2>Update quantities and prices</h2> <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post"> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <?php echo "<pre>",print_r($_POST),"</pre>"; /////////// QUERY //////////////////// if (isset($_POST['subsend'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='$stock_id';"; if (!mysql_query($sql3)) { echo "<p>Error updating. ".mysql_error()." $sql3</php>"; }else{ echo "<p>Updated successfully.</p>"; echo $sql3; exit; } } while ($row = mysql_fetch_array( $queryresult)) { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> <tr><td colspan="4"><input type="submit" value="Submit" name="subsend" /></td></tr> </form> </table> </p> </div><!-- mainContent --> <div id="footer"> <p>Coded and designed by: <a href="mailto:[email protected]">Steve Stoveld</a></p> </div><!-- footer --> </div><!-- wrapper --> </body> </html> Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791548 Share on other sites More sharing options...
sstoveld Posted March 23, 2009 Author Share Posted March 23, 2009 update and post what comes on the browser. remember the values you just updated please... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Administration</title> <link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="banner"> <h1><center><a href="index.php">Bookstore Administration</a></center></h1> </div><!-- banner --> <div id="mainContent"> <?php ////////// CONNECT TO SERVER ////////// $dbcnx = @mysql_connect('localhost', 'dbase18', '*******') or die ('I cannot connect to the database because: ' .mysql_error()); ///////// CONNECT TO DATABASE //////////// mysql_select_db('dbase18', $dbcnx); if (!@mysql_select_db('dbase18')) { exit ('<p>Error in query.'. mysql_error(). '<p>'); } /////////// FIRST SQL QUERY /////////// if (isset($_POST['update'])){ $books_id=$_POST['books_id']; $title = htmlentities($_POST['title']); $sql1 = "INSERT INTO books SET title='$title'"; if (!mysql_query($sql1)){ echo "<p>Error updating. ".mysql_error()."</p>"; } } /////////// GET PRIMARY KEY FROM PREVIOUS QUERY ///////// $title_id = mysql_insert_id(); ////////// SECOND SQL QUERY ////////// if (isset($_POST['update'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql2 = "INSERT INTO stock SET title_id='$title_id', quantity='$quantity', price='$price';"; if (!mysql_query($sql2)) { echo "<p>Error updating. ".mysql_error()." $sql2</php>"; }else{ echo "<p>Updated successfully.</p>"; } } ////////// QUERY DATABASE ////////// $queryresult = @mysql_query('SELECT stock_id, title, quantity, price FROM stock LEFT JOIN books ON stock.title_id = books.books_id ORDER BY title;'); if (!$queryresult) { exit ('<p>Error in query.'. mysql_error().'</p>'); } ///////// MAKE A TABLE CONTAINING FORMS FOR USER TO ADD NEW TITLES ////////// ?> <p> <h2>Add Titles</h2> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <form name="edit" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <tr> <td><input name="title" type="text" value="<?php echo $title; ?>" size="30" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="quantity" type="text" value="<?php echo $quantity; ?>" size="4" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="price" type="text" value="<?php echo $price; ?>" size="6" /> <input type="hidden" name="id" value="<?php echo $id;?>"> <td><input name="update" type="submit" value="update"></td> </tr> </form> </table> </p> <p> <h2>Update quantities and prices</h2> <form name="submit" action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post"> <table> <tr> <td>Title</td> <td>Stock</td> <td>Price</td> <td>Update</td> </tr> <?php echo "<pre>",print_r($_POST),"</pre>"; /////////// QUERY //////////////////// if (isset($_POST['subsend'])){ $title=$_POST['title']; $stock_id=$_POST['stock_id']; $quantity = htmlentities($_POST['quantity']); $price = htmlentities($_POST['price']); $sql3 = "UPDATE stock SET quantity='$quantity', price='$price' where stock_id='$stock_id';"; if (!mysql_query($sql3)) { echo "<p>Error updating. ".mysql_error()." $sql3</php>"; }else{ echo "<p>Updated successfully.</p>"; echo $sql3; exit; } } while ($row = mysql_fetch_array( $queryresult)) { echo('<tr><td>' . $row['title'] . '</td><td><input type="text" name="quantity" size="4" maxlength="4" value="' . $row['quantity'] . '"/></td><td><label>$<input type="text" name="price" size="6" maxlength="6" value="' . $row['price'] . '" /></label></td><td><input type="radio" name="stock_id" value="' . $row['stock_id'] . '"></td></tr>'); } ?> <tr><td colspan="4"><input type="submit" value="Submit" name="subsend" /></td></tr> </form> </table> </p> </div><!-- mainContent --> <div id="footer"> <p>Coded and designed by: <a href="mailto:[email protected]">Steve Stoveld</a></p> </div><!-- footer --> </div><!-- wrapper --> </body> </html> its still just using the values for the last row for some reason i really appreciate the help, but the deadline has already passed so i had to turn in my assignment without it being fully functional ive gotta get some sleep. thanks again Link to comment https://forums.phpfreaks.com/topic/150622-solved-need-some-help-with-bookstore-administration-page/page/2/#findComment-791549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.