Jump to content

simcoweb

Members
  • Posts

    1,104
  • Joined

  • Last visited

Everything posted by simcoweb

  1. Yup, the database query would pull the name from the url with a $_GET statement then use that info in a WHERE clause in the query.
  2. Honestly it's hard to tell with this limited snippet of code. For example, I don't see any database connection info. You have both a $_GET and a $_POST of the $id variable. I'm assuming you're getting the 'id' from the url to fill the $_GET which populates the checkbox name.. ? Then when they check the box it passes that 'id' on through the $_POST statement?  Also, IF they check the box then the query should run to update a specific field to an 'active' status. Is that field named 'suspended'?
  3. Well, a checkbox is a form element. It can't do anything on its own. In other words, the checkbox and submit button both need to be part of a form. Right now they aren't. Therefore the button doesn't do anything. This section here: [code]<?php   /* Display results in a table */ print ("<TABLE BORDER=1 WIDTH=\"90%\" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\n"); print ("<TR ALIGN=CENTER onmouseover=blue>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>No</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Question</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Option 1</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Option 2</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Option 3</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Answer</font></TD>\n"); print ("<TD ALIGN=CENTER ><font color=blue size=2>Del/Edit</font></TD>\n"); print ("</TR>\n"); if ($result = mysql_query($query)) {    // see if any rows were returned   if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result))  {     extract($row); print ("<TR ALIGN=CENTER >\n"); print( "<TD ALIGN=CENTER >$row[id]</TD>\n"); print ("<TD ALIGN=CENTER >$row[question]</TD>\n"); print ("<TD ALIGN=CENTER >$row[opt1]</TD>\n"); print ("<TD ALIGN=CENTER >$row[opt2]</TD>\n"); print ("<TD ALIGN=CENTER >$row[opt3]</TD>\n"); print ("<TD ALIGN=CENTER >$row[answer]</TD>\n"); print ("<TD ALIGN=CENTER ><input type=checkbox name=delete value=\"$id\"></font></TD>\n"); print ("</tr>");     }         mysql_free_result($result);         } else {         echo "Error in query: $query. ".mysql_error();  // print error message     } } print ("</TABLE>\n");    echo "<input type=submit value=Delete >&nbsp"; ?>[/code] needs to be inside a form tag. So, you'd echo the form tags ahead and at the end: [code]<?php echo "<form action='youractioninfohere.php' method='post'>";   /* Display results in a table */ print ("<TABLE BORDER=1 WIDTH=\"90%\" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\n"); print ("<TR ALIGN=CENTER onmouseover=blue>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>No</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Question</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Option 1</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Option 2</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Option 3</font></TD>\n"); print ("<TD ALIGN=CENTER ><b><font color=red>Answer</font></TD>\n"); print ("<TD ALIGN=CENTER ><font color=blue size=2>Del/Edit</font></TD>\n"); print ("</TR>\n"); if ($result = mysql_query($query)) {    // see if any rows were returned   if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result))  {     extract($row); print ("<TR ALIGN=CENTER >\n"); print( "<TD ALIGN=CENTER >$row[id]</TD>\n"); print ("<TD ALIGN=CENTER >$row[question]</TD>\n"); print ("<TD ALIGN=CENTER >$row[opt1]</TD>\n"); print ("<TD ALIGN=CENTER >$row[opt2]</TD>\n"); print ("<TD ALIGN=CENTER >$row[opt3]</TD>\n"); print ("<TD ALIGN=CENTER >$row[answer]</TD>\n"); print ("<TD ALIGN=CENTER ><input type=checkbox name=delete value=\"$id\"></font></TD>\n"); print ("</tr>");     }         mysql_free_result($result);         } else {         echo "Error in query: $query. ".mysql_error();  // print error message     } } print ("</TABLE>\n");    echo "<input type=submit value=Delete >&nbsp"; echo "</form><br>\n";[/code] By doing this the button will work. Note however that you need to have an 'action' statement that tells the form what to do.
  4. I've used both methods and both work but i've had better success with this method coming from a 'while' loop: [code]<?php while ($row = mysql_fetch_array($results)) {   echo " [i](then place all your form fields here like in a table)[/i] <input type='text' size='40' name='URL' value='" . $row['URL'] . "'> ?>[/code] Here's a full working example so you can see how the 'echo' displays everything: [code]<?php echo " <form action='update.php' method='POST' name='updateProduct'> <table width='780' border='0' bgcolor='#E1E1E1' padding='2'> <tr><td> <table width='100%' border='0'> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Product URL: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='40' name='URL' value='" . $row['URL'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Product ID: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Product_ID' value='" . $row['Product_ID'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Product Name: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Product_Name' value='" . $row['Product_Name'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Price: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Price' value='" . $row['Price'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Sale Price: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Sale_Price' value='" . $row['Sale_Price'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Description: </td><td width='60%' bgcolor='#9AC5C5'><textarea cols='50' rows='5' name='Description' >" . $row['Description'] . "</textarea></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Category: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='40' name='Category' value='" . $row['Category'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Detail Image (full url): </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='60' name='Image' value='" . $row['Image'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Postage: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Postage' value='" . $row['Postage'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Brand: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Brand' value='" . $row['Brand'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Availability: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Availability' value='" . $row['Availability'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Thumbnail Image (full url):  </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='60' name='Thumbnail' value='" . $row['Thumbnail'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Thumbnail width: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='ThumbnailWidth' value='" . $row['ThumbnailWidth'] . "'></td> </tr> <tr> <td width='40%' bgcolor='#FFFFF'> <font class='bodytextbold'>Thumbnail height: </td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='ThumbnailHeight' value='" . $row['ThumbnailHeight'] . "'></td> </tr> <tr> <td><input type='submit' name='submit' value='Add Product'> <input type='reset' name='reset' value='Clear'></td> </tr> </table> </form> </p>"; ?>[/code]
  5. That's probably because you don't have the checkbox  and query results inside a <form></form> tag. :)
  6. By using the * command you pull all the fields into an array. What you do with them is up to you. Say there's 20 fields. Using the * would summon all 20 into the array. If you want to display just 3 of them like you have then that's fine. If you want to display just 1 of them that's fine. But, that would be some lazy coding and wouldn't be very clear if you had to go back to it some day and see what you were trying to do there. If there's more than the 3 fields you might want to use the example I gave where you name the fields you want the query to pull from. No sense putting more burden on the server to pull a bunch of data you don't need :) [code]<?php $query = "SELECT Age, AgeDivision, Team FROM conflict"; ?>[/code]
  7. Just have the script run every 30 days as a cron job.
  8. The correct syntax is as follows: "SELECT [i]what[/i] FROM [i]where[/i]"; So, select what data from what table. In your case it would be like his first example: [code]<?php $query = "SELECT * (which means everything) FROM MyTable (the table name)"; ?>[/code] To expand it as an example it would be like: [code]<?php $query = "SELECT * FROM MyTable WHERE userid='Bob'"; ?>[/code] The WHERE clause specifies a precise group of data instead of just everything. And, furthermore, say you have 20 fields in your database but only wanted those 3. Instead of selecting everything using the * you could name the columns you want to extract from. Like this: [code]<?php $query = "SELECT field1, field2, field3 FROM MyTable"; ?>[/code] Make sense? Also, in your last post you had this: [quote]$query = "SELECT * FROM "conflicts;[/quote] The double quotes for your SELECT statements go on both ends. Like this [quote]$query = "SELECT * FROM conflicts";[/quote] Your query would fail using what you had.
  9. You might try changing this line in your WHILE loop: [code]<?php print ("<TD ALIGN=CENTER ><input type=checkbox name=delete value=\"$id\"></font></TD>\n"); ?>[/code] To this: [code]<?php print ("<TD ALIGN=CENTER ><input type='checkbox' name='delete' value='" . $row['id'] . "'></font></TD>\n"); ?>[/code] That should populate your checkbox with the right value. Then your delete query should point to that in the WHERE clause.
  10. http://www.hotscripts.com/PHP/Tips_and_Tutorials/File_Manipulation/index.html
  11. http://www.phpfreaks.com/tutorials/61/0.php
  12. I'm not sure if I understand the question. You can't insert a checkbox into a MySQL table. Only the value of the checkbox. Can you clarify please?
  13. Question: Instead of having an input form post the date, why don't you just set the date yourself when the form is submitted? That way you can easily pass it in a variable and into the database. Something simple like this: $date = date("F j, Y");
  14. LOL at thorpe :) 1. $$test = "0"; means you've assigned the variable $test as another variable. Example: [code]<?php $test = "bob"; ?>[/code] is the same as [code]<?php $holder = "user"; $$holder = "bob"; ?>[/code] 2. to 'encapsulate' means to enclose a string in quotes, whether single or double, and/or brackets, etc. 3. check the tutorials section
  15. I'd say you're right. I don't see how a script could magically surf to the proper page and category and start/create a new thread. But, you could have the results of the form dumped into all the necessary fields of the 'posts' database quite easily with a simple query than runs when the form is submitted. That is, as long as you have all the necessary info.
  16. Hey thorpe, could you elaborate on that method a bit for us? Thanks! :)
  17. change the $servername variable: [quote]$servername = 'localhost';[/quote] To: [quote]$servername = 'mysql2.freehostia.com';[/quote] And, i'm assuming you inserted the correct data into those other variables as well?  :P
  18. In my limited knowledge, you can pass variables in these ways: * if a variable is outside a function and you want to use it inside a function then claim it as 'global' [code]<?php $a = 1; $b = 2; function Sum() {   global $a, $b;   $b = $a + $b; } Sum(); echo $b; ?> [/code] * If you wish to pass it to another page you can use: 1. session vars 2. pass it in the URL (ex: nextpage.php?hotstuff=$hotStuff which would pass along 'Kate Bekinsdale' to be captured in a $_GET statement)
  19. You can pass the ID in the URL and snag it on the other end using the $_GET statement or, as suggested, use sessions. $id = $_GET['id']; That 'snags' the ID from your url which is passed when your form is submitted like this: <form action="parsethis.php?id=45XYZ" method="POST">
  20. Cool. I'll put ucwords in my bookmarks!
  21. Ok, this wins as my choice for the goofiest question of the week. Either that or it's a bad attempt at spamming this board with the freelancer link.
  22. I don't know about captilizing the first letters of the two words. But, you can easily snag that name by using the $_GET statement. $name = $_GET['name']; This will set that variable value for you from the 'name' segment of the URL coming to the form. Then, when they land on the form page you'd do this in that field: <input type='text' size='20' name='name' value='$name'> That will put 'dick tracy' into that spot. If you want caps for those then there may be some string code for it but I'm not aware. Might be easier to pass it with caps in the URL.
  23. Ok, so you're saying the database 'name' and the database 'password' are indeed the same text? Honestly that would be unusual but not unheard of. In regards to the fixes, did you add the commas as I pointed out?
  24. Yes, these guys rock. No doubt. Ok, here's my method. It's simple. The checkbox is really only useful if you are, in fact, thinking of modifying multiple items at once which could be dangerous. ;) I'm shooting from the hip here but it appears what you want to do is display a list of your items and have the choice to edit or delete them. If you edit them then it would naturally update your MySQL database when doing so. First, you'd run the query to get your results from the database/table. This can be simple since you want everything: [code]<?php $sql = "SELECT * FROM table_name"; $results = mysql_query($sql) or die(mysql_error()); ?>[/code] To display the results it would be something like: [code]<?php // start our table for results with table headers echo "<table width='700' border='1' align='center'><tr>"; echo "<th>Produc ID</th><th>Product Name</th><th>Update</th><th>Delete</th></tr>"; // loop through query results to display products while ($row = mysql_fetch_array($results)) {   echo "<tr><td><font class='bodytext'>" . $row['Product_ID'] . "</td><td><font class='bodytext'>" . $row['Product_Name'] . "</td><td><font class='bodytext'><a href='updateproduct.php?Product_ID=" . $row['Product_ID'] . "'>Update</a></td>   <td><font class='bodytext'><a href='delete.php?Product_ID=" . $row['Product_ID'] . "'>Delete</a></font></td></tr>"; } // close table echo "</table>\n"; ?>[/code] This would display your products in rows like this: Product ID    Product Name  Update    Delete 1001            Bozo Doll        (link)        (link) 1002            Paris Doll        (link)        (link) The 'Update' link would take you to a page where all the details are viewable about that product in a form view meaning all the form fields are prepopulated with the current data. You'd make the changes and hit the Update/Submit button which runs a script using the UPDATE function pointing to a WHERE product_id=$product_id. Now, pay close attention to this snippet. We're going to pass the product ID through the URL: [code]<?php <a href='delete.php?Product_ID=" . $row['Product_ID'] . "'>Delete</a> ?>[/code] Basically this is the hyperlink code that the 'Update' link points to. It points to my delete.php script (which, when clicked on, runs the DELETE function from the Mysql table) and passes the product ID through the URL. The delete.php script snags it via the $_GET statement as a variable: $product_ID = $_GET['product_ID']; Which sets the value of that variable which then tells the Delete or the Update script which product you're talking about. Then the queries for either of those functions uses that variable like this: "UPDATE table_name SET 'col_1', 'col_2', 'col_3', 'etc' WHERE product_ID=$product_ID"; Here's the actual code for the site that I did. This is for the UPDATE functionality only. But it illustrates how it would perform the action, identify the proper product with the $_GET function and so on. [code]<?php // insert updates into product database include 'db_config.php'; include 'header.php'; // post our variables $URL = $_POST['URL']; $Product_ID = $_POST['Product_ID']; $Product_Name = $_POST['Product_Name']; $Price = $_POST['Price']; $Sale_Price = $_POST['Sale_Price']; $Description = $_POST['Description']; $Category = $_POST['Category']; $Image = $_POST['Image']; $Postage = $_POST['Postage']; $Brand = $_POST['Brand']; $Availability = $_POST['Availability']; $Thumbnail = $_POST['Thumbnail']; $ThumbnailWidth = $_POST['ThumbnailWidth']; $ThumbnailHeight = $_POST['ThumbnailHeight']; //make connection to database mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql = "UPDATE Datafeed SET URL='$URL', Product_ID='$Product_ID', Product_Name='$Product_Name', Price='$Price', Sale_Price='$Sale_Price', Description='$Description', Category='$Category', Image='$Image', Postage='$Postage', Brand='$Brand', Availability='$Availability', Thumbnail='$Thumbnail', ThumbnailWidth='$ThumbnailWidth', ThumbnailHeight='$ThumbnailHeight' WHERE Product_ID='$Product_ID'"; $results = mysql_query($sql) or die(mysql_error()); if(! $results) {   echo "<center><h3>Results Error</h3><br>         Unable to update product.<br />\n"; } else {   echo "<h3>Product Updated</h3><br>   Product was successfully updated.<br> <a href='updateproduct.php'>Click here</a> to update another"; } include 'footer.php'; ?>[/code]
×
×
  • 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.