Jump to content

gskurski

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gskurski's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. This might not matter, but I thought the proper syntax for mysql_query was: $sql = "SELECT * FROM table"; $result = mysql_query($sql, $connection); You have the connection listed first and then then sql string. Perhaps that is causing a problem?
  2. Ideally, what I'm looking to do is display results from my database in an html table like this: Result 1 Result 2 Result 3 Result 4 Result 5 Result 6 Result 7 Result 8 Result 9 Result 10 Result 11 Result 12 Page 1 - 2 - 3 - 4 or however many pages would be generated by the amount of records in the table. Right now I can get it to display the results in a table such as the one I just described, but it would just keep creating new rows of 3 beyond the 12th result. I want to paginate it but I am having trouble implementing any code for pagination that I've found with the loop I use to make the table appear the way it does. Can anyone help?
  3. It's all of the PHP code that's on the page. There is some HTML before it that has some menu code, as well as the code that starts the actual table that's being produced. I also didn't include the code for the show.php page that the img tag refers to. The code for that is : <?php $username = "xxxx"; $password = "xxxxx"; $host = "localhost"; $database = "images"; $conn = mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error()); $db = mysql_select_db($database) or die("Can not select the database: ".mysql_error()); $id = $_GET['id']; $table = $_GET['table']; if(!isset($id) || empty($id)){ die("Please select your image!"); }else{ $sql = "SELECT * FROM $table WHERE id=" . $id; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $row = mysql_fetch_array($result); $content = $row['image']; header('Content-type: image/jpg'); echo $content; } ?> Again, thanks for the help!
  4. Hello! I have a database of small image / names that I want to pull into a 3 x 4 table. My current code works perfectly if I have 12 images or less, but I will have more than 12 images. Currently the code is set up to retrieve and display the images in a table, three per table row. I want it so that when it reaches the 4th row in a page it generates a link to another page that has the next 3 x 4 (12 total images) page. I tried to follow the code on http://www.phpfreaks.com/tutorial/basic-pagination, but after I get it to what I think it should be, my page is blank -- but not due to an error, it's just blank. My code so far is: <?php $username = "xxxx"; $password = "xxxxx"; $host = "localhost"; $database = "images"; $conn = mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error()); $db = mysql_select_db($database) or die("Can not select the database: ".mysql_error()); $sql = "SELECT * FROM block_work ORDER BY Name"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); header('Content-type: image/jpg'); $counter = 0; while ($row = mysql_fetch_array($result)) { if($counter==0) print "<tr align='center'>"; ++$counter; print "<td align='center' width='179' height='200'><img src='/management/show.php?id=" . $row['id'] . "&table=block_work' alt='" . $row['name'] . "' /><br/>"; print "<b>" . $row['name'] . "</b></td>"; if($counter==3) { $counter=0; print "</tr>"; }; }; while ($counter>0) { ++$counter; print " <td> </td>"; if($counter==3) { $counter=0; print "</tr>"; } } print "</table>"; mysql_close($con); ?> Thanks very much for any help! -Gerry
  5. I was able to solve my problem. I didn't end up using Ajax, but here's my code if anyone is interested: PHP file with the button: <?php $user_id = check_input($_SESSION['user_id']); $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db_liquors", $con); $result = mysql_query("SELECT * FROM Bourbons WHERE user_id='$user_id'"); $num_rows = mysql_num_rows($result); if ($num_rows==0){ echo "<h3>You have not submitted any Bourbon reviews.</h3>"; }else{ echo "<table border='1'> <tr> <th>Date</th> <th>Name</th> <th>Region</th> <th>Years Aged</th> <th>Proof</th> <th>Price</th> <th>Review</th> <th>Ratings</th> <th>Avg Rating</th> <th>Delete?</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Date'] . "</td>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td>" . $row['Region'] . "</td>"; echo "<td>" . $row['Years Aged'] . "</td>"; echo "<td>" . $row['Proof'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Review'] . "</td>"; echo "<td>" . $row['Smoothness'] ."/". $row['Taste'] ."/". $row['Value'] . "</td>"; echo "<td>" . $row['Rating'] . "</td>"; echo "<td>" . "<form action='deleterev.php' method='post' onsubmit='return confirmSubmit()'>" . "<input type='hidden' value='" . $row['review_id'] . "' name='record'>" . "<input type='hidden' value='Bourbons' name='table'>" . "<input type='submit' value='Delete?'>" . "</form>" . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); } ?> The simple javascript confirmation script: <script LANGUAGE="JavaScript"> <!-- function confirmSubmit() { var agree=confirm("Are you sure you wish to delete this review?"); if (agree) return true ; else return false ; } // --> </script> Then the "deleterev.php" file: <?php $record_id = $_POST['record']; $table = $_POST['table']; $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db_liquors", $con); $record_id = $_POST['record']; $table = $_POST['table']; $sql = mysql_query("DELETE FROM $table WHERE review_id='$record_id'"); mysql_close($con); ?> <html> <body> <head> <link rel="stylesheet" href="style.css" /> <meta http-equiv="Refresh" content="0;url=http://locahost.com/myreviews.php"> </head> </html> The "bourbons" table is just one out of many. The original PHP script is repeated several times for the different types of liquors and each time the delete button submits a hidden value with the table name so it knows which table to delete from. Hope this helps for anyone else who wants a similar function!
  6. So I've looked into Ajax and this is what I've come up with so far, can someone please let me know how far off I am? I've added the button to each row and when you click it, it does ask whether or not you want to delete the record. However, nothing happens if you click okay. Here is the coding: I've added this to my original php file: echo "<td><input type=\"button\" onclick=\"delete_item('". $row['record_id']. "')\" value=\"Delete\" id="id" /></td>"; Here is the javascript/Ajax I have implemented: <script language="javascript"> // javascript code function delete_item(item) { var agree = confirm("Are you sure you would like to delete this review?"); if (agree == true) { ajax_delete_item(item); } } function ajax_delete_item(item) { var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.myForm.time.value = ajaxRequest.responseText; } } var record = document.getElementById('id').value; var queryString = "?record=" + record; ajaxRequest.open("GET", "deleterev.php" + queryString, true); ajaxRequest.send(null); } </script> And here is the PHP file it refers to: <?php $record_id = $_GET['record_id']; $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("localhost_mydb", $con); $sql = mysql_query("DELETE FROM Bourbons WHERE record_id='".$record_id."'"); mysql_close($con); ?> Again, any help is really appreciated.
  7. Thanks for replying! I'm not very familiar with Ajax yet -- do you know of a good website that would have examples/tutorials of the type of script I would need to do the query I need? Also, in this line: echo "<td><input type=\"button\" onclick=\"delete_item('". $row['unique_id']. "')" value="Delete" /> Should there be a "; at the end? Thanks again~~
  8. Currently I have a page in my members area that queries all the entries the logged in user has made and displays the results. The code for that is as follows: <?php $user_id = check_input($_SESSION['user_id']); $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("localhost_db", $con); $result = mysql_query("SELECT * FROM Bourbons WHERE user_id='$user_id'"); $num_rows = mysql_num_rows($result); if ($num_rows==0){ echo "<h3>You have not submitted any Bourbon reviews.</h3>"; }else{ echo "<table border='1'> <tr> <th>Date</th> <th>Name</th> <th>Region</th> <th>Years Aged</th> <th>Proof</th> <th>Price</th> <th>Review</th> <th>Ratings</th> <th>Avg Rating</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Date'] . "</td>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td>" . $row['Region'] . "</td>"; echo "<td>" . $row['Years Aged'] . "</td>"; echo "<td>" . $row['Proof'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Review'] . "</td>"; echo "<td>" . $row['Smoothness'] ."/". $row['Taste'] ."/". $row['Value'] . "</td>"; echo "<td>" . $row['Rating'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); } ?> This part works perfectly. What I want to be able to do is to have each record that is displayed also have a Delete button, that when clicked will remove that record from the database. Ideally I would like to have it prompt the user to verify the action, but that's secondary to the first part. Any help is really appreciated! Thanks~~ Gerry
  9. That worked perfectly, thanks so much!
  10. I forgot to mention the problem, which is simply that when I click "Go!", it won't load to any of the specified pages.
  11. I'm having a problem which I'm sure will take a simple fix, but I can't seem to figure it out. I have a form now that lets you pick from six different options and then submit it to a redirect php file. In the php file I have an if, else if statement that is suppose to redirect to different pages corresponding to the original value selected in the form. Here is my code. <form action="subredirect.php" method="post" target="index"> <select name="redirect"> <option value="vodka">Vodkas</option> <option value="bourbons">Bourbons</option> <option value="rum">Rums</option> <option value="gin">Gins</option> <option value="brandy">Brandy</option> <option value="tequila">Tequila</option> <option value="whiskey">Whiskey</option> </select> <input type="submit" value="Go!"> </form> And here is my php file <?php if ($_POST(['redirect'])== "vodka"){ header("Location: http://www.website.com/vodkasubmit.php"); exit (); } elseif ($_POST(['redirect'])== "bourbon"){ header("Location: http://www.website.com/bourbonsubmit.php"); exit (); } elseif ($_POST(['redirect'])== "rum"){ header("_POST(['redirect']): http://www.website.com/rumsubmit.php"); exit (); } elseif ($_POST(['redirect'])== "gins"){ header("Location: http://www.website.com/ginsubmit.php"); exit (); } elseif ($_POST(['redirect'])== "brandy"){ header("Location: http://www.website.com/brandysubmit.php"); exit (); } elseif ($_POST(['redirect'])== "tequila"){ header("Location: http://www.website.com/tequilasubmit.php"); exit (); } elseif ($_POST(['redirect'])== "whiskey"){ header("Location: http://www.website.com/whiskeysubmit.php"); exit (); } ?> Any help is really appreciated! Thanks -Gerry
  12. Hello, I'm brand new to this forum so forgive me if I'm not following protocol, but I was hoping to get some help with some of my code. I am trying to create a login page that asks for a username and password, posts it to a php file, which connects to mysql database and verifies the username and password, and then either goes to the member page, or denies access. This is what I have so far. From the login page: <form action="login.php" method="post"> Username: <input type="text" name="username" /> Password: <input type="password" name="password" /> <input type="submit" /> </form> login.php --- <?php $con = mysql_connect("host","admin","adminpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database_users", $con); $result = mysql_query("SELECT `Username` FROM users WHERE Username='$_POST["username"]' AND Password='$_POST["password"]'"); if ($result='$_POST["username"]') header("Location: http://www.website.com/members.html"); else echo "Incorrect username and/or password"; ?> I changed the relevant variables to make it anonymous for the forum, but they're correct in my original source. Any help would be appreciated! Thanks, Gerry
×
×
  • 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.