Jump to content

uncaringuser

Members
  • Posts

    10
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

uncaringuser's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Psycho thank you so much for the example script, after a few modifications it proved to be exactly what I needed. Thanks again for the help and support. Consider this matter SOLVED
  2. I agree, a for each loop would be the best approach I feel however how would I apply the for-loop syntax to the backend script based on the front end variables I have now created?
  3. I have followed your example and changed the code for the front end, however I do not know how to take the array and update my database using an array as data in the back end. Would you be able to (based on your example) come up with an example update statement so I can get a better understanding?
  4. I have tried that and its still not working, im certain that the problem lies with the update statement in the back end script. Thank you for your help so far.
  5. The forms are generated from how much data is in the tables, so it would be impossible to provide a specified name to each of them, hence why I used a variable which was automatically generated from when the data was created. Is there a way I could automatically assign a name to the form inputs that is recognised by PHP thus resulting in a successful query?
  6. Hey people, I am faced with a problem that I need guidance with in order to solve. I have a catering website that is connected to a mysql database that has a back end to do changes to the menu. I have created an update page that originally updated the price but I was asked for it to update all the fields with any changes being made on the page, sounds simple right? Only problem is, is that the data that is being displayed is pulled from the database and displayed as values in input boxes so that the user can make changes. Each input box has a nameid which is a unique number that is pulled from the database that is stored in a field for each entry. I want it so that the user can change any input box data and click on the one button and it update the records to each correct field based on their own unique id. Here is the code for the front end <form action="chstarterprice.php" method="post"> <br><br> <?php include("connection.php"); $result= mysql_query("SELECT title, subtext, nameid, category, price FROM starters"); while($row = mysql_fetch_array($result)) { $nameid = $row['nameid']; $title = $row['title']; $subtext = $row['subtext']; $category = $row['category']; $price = $row['price']; echo"<table>"; echo"<tr>"; echo"<td width=\"70px\">"; echo"<p class=\"form2\">"; echo "<b>Title</b>"; echo"</td>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo "<b>Subtext</b>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo "<b>Category</b>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo "<b>Price</b>"; echo"</td>"; echo"</tr>"; echo"<tr>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$title\">"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$subtext\">"; echo"</td>"; echo"</td>"; echo"<td width=\"80px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$category\">"; echo"</td>"; echo"<td width=\"120px\">"; echo"<p class=\"form2\">"; echo"<input type=\"text\" name=\"$nameid\" value=\"$price\">"; echo"</td>"; echo"</tr>"; echo"<tr>"; echo"</tr>"; echo"</table>"; } mysql_close($con); ?> <br> <input name="Submit" type="submit" value="Change" /></p> </form> Here is the backend script that processes the form data <? ob_start(); ?> <?php include("connection.php"); $nameid = $_POST['nameid']; $query = "update starters set title, subtext, nameid, category, price = ('$_POST[nameid]') where 'starters'.'nameid' = '$nameid' or die(mysql_error)"; if(mysql_query($query)){ header("location:change-prices.php");} else{ header("location:change-prices.php");} ?> <? ob_flush(); ?> If you guys can point me in the right direction with the code to make this work I would be greatly appreciated, I am really sure that it has something to do with the backend script as opposed to the front end. Please get back to me, thanks guys. Mitch
  7. I did, and I know but it is, I dunno why it is coming up with it, I'm stumped. Here's the entire code in a more appropriate format. <!DOCTYPE html> <html> <head> <title>Mistrys Catering</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <div id="canvas"> <div id="header"> <div id="logo"></div> <div id="slogan"></div> </div> <div id="top"> <div id="step">Step 3 of 10</div><div id="detail"><img src="./images/starters.png"></div> </div> <div id="middle"> <div id="stepcontent" class="form"> <div id="content-left"> <img src="./images/meat.png" class="food"><br><br> <form method="post" action="step4.php"> <table class="food"> <?php $con = mysql_connect("database details"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("webnw_catering", $con); $result= mysql_query("SELECT * FROM starters WHERE category='meat'"); while($row = mysql_fetch_array($result)) { $nameid = $row['nameid']; $amountid = $row['amountid']; $title = $row['title']; $checkbox = $_POST['checkbox']; echo"<tr>"; echo"<td>"; echo"<p class=\"form2\">"; echo $row["title"]; echo " - £"; echo $row["price"]; echo"<br>"; echo"<span class=\"subtext\">". $row['subtext'] . "</span>"; echo"</p>"; echo"</td>"; echo"<td class=\"addon\">"; echo"<input type=\"checkbox\" class=\"largecheckbox\" name=\"checkbox[{$row['title']}]\" id =\"$nameid\" value=\"$title\">"; echo"</td>"; echo"<td class=\"addon\">"; echo"<input type=\"text\" class=\"amount\" name=\"amount[]\" id =\"$amountid\">"; echo"</td>"; echo"</tr>"; } echo ""; mysql_close($con); ?> </table> </div> <div id="content-right"> <img src="./images/veg.png" class="food"><br><br> <table class="food"> </table> </div><br> </div> </div> <div id="bottom"> <div id="build"></div> <div id="backbutt"><a href="step2.html"><img src="./images/prevbutt.png"></a></div> <div id="nextbutt"><input type="image" src="./images/nextbutt.png"></div> </form> </div> </div> <div id="footer"> <p class="footer">Mistrys Catering | 01204 527 139 | info@mistryscatering.com</p> </div> </div> </body> </html> <!DOCTYPE html> <html> <head> <title>Mistrys Catering</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <div id="canvas"> <div id="header"> <div id="logo"></div> <div id="slogan"></div> </div> <div id="top"> <div id="step">Step 4 of 10</div><div id="detail"><img src="./images/starters.png"></div> </div> <div id="middle"> <div id="stepcontent" class="form"> <div id="content-left"> <img src="./images/meat.png" class="food"><br><br> <table class="food"> <tr> <td><p class="form2"><?php echo $_POST["checkbox"]; ?></p></td> </tr> <tr> <td><p class="form2"></p></td> </tr> </table> </div> <div id="content-right"> <img src="./images/veg.png" class="food"><br><br> <table class="food"> <tr> <td><p class="form2"></p></td> </tr> <tr> <td><p class="form2"></p></td> </tr> </table> </div><br> </div> </div> <div id="bottom"> <div id="build"></div> <div id="backbutt"><a href="step2.html"><img src="./images/prevbutt.png"></a></div> <div id="nextbutt"><input type="image" src="./images/nextbutt.png"></div> </form> </div> </div> <div id="footer"> <p class="footer">Mistrys Catering | 01204 527 139 | info@mistryscatering.com</p> </div> </div> </body> </html>
  8. I am not adequate at PHP at all, I mostly dabble in HTML and CSS. The problem here is that I have a form which has been assigned unique variables via database. The user would select a checkbox and the value associated with it based on its name and id, would display the appropriate value on the next page. For whatever reason when I active my form it just comes up with the word "Array". Below is the code for both pages and I would be greatly appreciated if you could help me resolve this error and point me in the right direction to achieve my goal. FORM WITH UNIQUE VARIABLES <code> <?php $con = mysql_connect("database details"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("webnw_catering", $con); $result= mysql_query("SELECT * FROM starters WHERE category='meat'"); while($row = mysql_fetch_array($result)) { $nameid = $row['nameid']; $amountid = $row['amountid']; $title = $row['title']; $checkbox = $_POST['checkbox']; echo"<tr>"; echo"<td>"; echo"<p class=\"form2\">"; echo $row["title"]; echo " - £"; echo $row["price"]; echo"<br>"; echo"<span class=\"subtext\">". $row['subtext'] . "</span>"; echo"</p>"; echo"</td>"; echo"<td class=\"addon\">"; echo"<input type=\"checkbox\" class=\"largecheckbox\" name=\"checkbox[{$row['title']}]\" id =\"$nameid\" value=\"$title\">"; echo"</td>"; echo"<td class=\"addon\">"; echo"<input type=\"text\" class=\"amount\" name=\"amount[]\" id =\"$amountid\">"; echo"</td>"; echo"</tr>"; } echo ""; mysql_close($con); ?> </code> RESPONSE PAGE <code> <div id="middle"> <div id="stepcontent" class="form"> <div id="content-left"> <img src="./images/meat.png" class="food"><br><br> <table class="food"> <tr> <td><p class="form2"><?php echo $_POST["checkbox"]; ?></p></td> </tr> <tr> <td><p class="form2"></p></td> </tr> </table> </div> </code>
  9. How would I go about taking the values randomly generated and get them to be an actual name value, so that the information typed into the form can be passed properly from one form to the next, I have tried variables and sessions and im getting no errors, but nothing displays results wise, so I dont know what im doing wrong.
  10. Hi, Im at a standstill. I have a MYSQL database which has a name and amount field that automatically generates a random number when the details get uploaded via form and submitted. The information is then displayed on another and the values generated are assigned to the <name> parameter in the form so that each field generated has a unique value, you with me so far? So to confirm I have a form that the user fills out and it has two hidden fields that are automatically given random values when submitted to the database. This is then retrieved on another page and the random values are assigned to the name value in another form. I want the user to fill out this form and have each value submitted to another page and shown. I shall post my code and if anyone could help me with this issue I would be most grateful. Thank you! Form in which the data from the database is assigned to the name tag: <form method="post" action="step4.php"> <table class="food"> <?php $con = mysql_connect("database details"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("catering", $con); $result= mysql_query("SELECT * FROM starters WHERE category='meat'"); while($row = mysql_fetch_array($result)) { echo"<tr>"; echo"<td>"; echo"<p class=\"form2\">"; echo $row["title"]; echo " - £"; echo $row["price"]; echo"<br>"; echo"<span class=\"subtext\">". $row['subtext'] . "</span>"; echo"</p>"; echo"</td>"; echo"<td class=\"addon\">"; echo"<input type=\"checkbox\" class=\"largecheckbox\" name=". $row['nameid'] .">"; echo"</td>"; echo"<td class=\"addon\">"; echo"<input type=\"text\" class=\"amount\" name=". $row['amountid'] .">"; echo"</td>"; echo"</tr>"; } echo ""; mysql_close($con); ?> </table> </div> <div id="bottom"> <div id="build"></div> <div id="backbutt"><a href="step2.html"><img src="./images/prevbutt.png"></a></div> <div id="nextbutt"><input type="image" src="./images/nextbutt.png"></div> </form> </div> </div> <div id="footer"> <p class="footer">Mistrys Catering | 01204 527 139 | info@mistryscatering.com</p> </div> </div> </body> </html>
×
×
  • 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.