Jump to content

LiamH

Members
  • Posts

    54
  • Joined

  • Last visited

    Never

Everything posted by LiamH

  1. It's at the top of the page. The two sections use the same query and the article body area works. I've tried it with a separate query and still get the same result
  2. Hi all. I have one bit of code that isn't working, and I have no idea why. It's for some reason not publishing the results from the table. It's basically an article page. The article details publish with no problem in the main content area. But the content div to the left of it, for some reason won't publish the results from the table. Any ideas why? <?php //this bit works // see if any rows were returned if (mysql_num_rows($result) > 0) { // if rows are returned, print them while($row = mysql_fetch_assoc($result)) { echo stripslashes("<div class='headline_text' id='headline_text'>".$row['Headline']."</div>"); echo stripslashes("<div class='headline_preview' id='headline_preview'>".$row['ReviewPreview']."</div>"); echo stripslashes("<div class='date_author' id='date_author'>".$row['Date']." by ".$row['Name']."</div>"); echo stripslashes("<div class='article_image' id='article_image'><img src=".$row['ReviewImage']." alt=".$row['Headline']." width='550px' height='280px'></div>"); echo stripslashes("<div class='article_text' id='article_text'>".$row['ReviewBody']."</div>"); } } echo "</div>"; echo "<div class='game_info' id='game_info'>"; echo "<div class='more_holder' id='more_holder'>"; // but this bit doesn't work for some reason // see if any rows were returned from the headline only query if (mysql_num_rows($result) > 0) { // if rows are returned while($row = mysql_fetch_assoc($result)) { echo stripslashes("".$row['Title'].""); } echo "</div>"; } ?> </div> Any ideas where I have gone wrong? It renders the page, but just doesn't display the data like it can't find anything
  3. Thanks, got it sorted. Using phpMyAdmin it appears you can't turn it off. Using stripslashes in my code resolves the issues
  4. I'm using phpMyAdmin, what is the best way to block Magic Quotes?
  5. Hi all. For some reason when I submit a form and it contains " or ' or I think even /, and then check the form data once submitted, I am noticing that a \ is appearing in the data. Anyone know why this is happening?
  6. Thanks very much. There was one problem with the code for anyone else experiencing an issue like this, the code should read; foreach ($_POST['ArticleID'] as $id){ $query="DELETE FROM tblArticle WHERE ArticleID = '$id'"; mysql_query($query);
  7. Hi all. I have a page that has a list of data with checkboxes next to it. The idea is that when selected, the data is deleted from the table. It works in a way, but only one of the records are actually deleting. The system consists of 2 pages, one with the listed data and checkboxes and when the form is submitted, taken to another page that has the sql in the background to perform the action. This is the code I have; //page 1 // if rows are returned, print them one after another echo "<form action='delete.php' method='post'>"; echo "<table class='articlecreate'>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td><a href='edit.php?ArticleID=".$row['ArticleID']."'>".$row['Headline']."</a></td>"; // the line of code below is for the delete checkboxes echo "<td><input name='ArticleID' type='checkbox' value='".$row['ArticleID']."'></td>"; echo "</tr>"; } echo "<tr>"; echo "<td><input type='submit' name='delete' value='Delete'></td>"; echo "</tr>"; echo "</table>"; echo "</form>"; //page 2 // variable names defined for delete query $articleID=$_POST['ArticleID']; // create and execute query. Query states the information received from the previous page needs to be deleted from the table $query="DELETE FROM tblName WHERE ArticleID='$articleID'"; mysql_query($query); // check for errors or process query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // state record has been deleted echo "<td class='content'>Record deleted!</td>"; // close connection mysql_close($connection); What am I missing from this, can anyone help please? Thanks
  8. I'm not sure where I went wrong but I used echo "<td><img src=".$row['ImageLocation'].">Image</td>"; which worked
  9. Hi all. My server has a separate images folder that holds any images to be used on the site. I have a table that contains a column that holds image data for that row. So it has the location of the image, with an example being /images/newimage.jpeg. How can I display this image using that location stored in the database?
  10. When the query was printed and it didn't show the ArticleID I thought that was the issue. I went through a few times and couldn't see it. Went through again and found the variable had a lower case id instead of ID. So stupid. Thank you all for your help!
  11. Ok to make things more legible for myself and of course everyone helping, AID has been changed to ArticleID. So they're now all changed. Using the echo "$query"; I noticed that the Article ID was not showing, neither was the preview or body text. So have gone through all my code and found two lines that were incorrect due to the case. So changed them and now get this; UPDATE tblname SET Headline='Test Article number 1', Date='2009-02-22', Preview='This is a test article', Body='The rest of the information goes in here' WHERE ArticleID='' so when I change the information and submit it, the changes show up in the printed query on the page, but when checking the DB no changes are made.
  12. This is the first page. All of the data appears correctly <?php // checks to see if user logged in. If not, redirects user to login page located at admin.php session_start(); if(!session_is_registered(username)){ header("location:admin.php"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> </head> <body> <?php if(empty($_GET['AID'])) { echo "<p class='error'>No ID supplied.</p>\n"; } else if(!$_POST['AID']) { //include config file $headline = ($_POST['Headline']); //needed? $query = "SELECT Headline, Date, Preview, Body FROM tblname WHERE AID=".$_GET['AID']; $result = mysql_query($query) or die("Query failed: ".mysql_error()); if(mysql_num_rows($result)) // found something { $row = mysql_fetch_assoc($result); echo "<form action='update.php' method='post'>"; echo "<table width='750px' border='0' align='center' cellpadding='0' cellspacing='1'>"; echo "<tr>"; echo "<td><input type='hidden' name='AID' value='".$_GET['AID']."'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Title:</td>"; echo"<td><input name='Headline' type='text' size='100' value='".$row['Headline']."'></td>"; echo"</tr>"; echo"<tr>"; echo "<td>Date:</td>"; echo"<td><input name='Date' type='text' value='".$row['Date']."'</td>"; echo"</tr>"; echo"<tr>"; echo "<td>Preview:</td>"; echo"<td> <textarea name='preview' cols='65' rows='15'>".$row['Preview']."</textarea></td>"; echo"</tr>"; echo"<tr>"; echo "<td>Body:</td>"; echo"<td><textarea name='body' cols='65' rows='15'>".$row['Body']."</textarea></td>"; echo"</tr>"; echo"<tr>"; echo"<td><input type='submit' name='submit' value='Submit'></td>"; echo"</tr>"; echo"</table>"; echo "</form>"; } else { echo "<p class='error'>Invalid article ID.</p>\n"; } } ?> </body> </html> And this is the code from the update page ?php // checks to see if user logged in. If not, redirects user to login page located at admin.php session_start(); if(!session_is_registered(username)){ header("location:admin.php"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Update page</title> </head> <body> <?php include ".php"; $aid=$_POST['AID']; $headline=$_POST['Headline']; $date=$_POST['Date']; $preview=$_POST['Preview']; $body=$_POST['Body']; $query="UPDATE tblname SET Headline='$headline', Date='$date', Preview='$preview', Body='$body' WHERE AID='$AID'"; mysql_query($query); //echo "Record Updated"; //previous code above - starting from mysql_query $result = mysql_query($query); if($result) { echo "yes"; }else{ echo "no"; } echo mysql_error(); mysql_close(); ?> </body> </html> This is a project I stopped doing some time ago and have picked it up again, I could have sworn this was all working fine. You might be able to tell I'm not the most advanced with PHP as well, so I'm trying to remember everything again
  13. Came up with yes and no errors. I have a feeling I am meant to have something in the header. Is that correct? To get the data from one page to another. Should $aid=$_POST['AID']; $headline=$_POST['Headline']; $date=$_POST['Date']; $preview=$_POST['Preview']; $body=$_POST['Body']; this appear in the header?
  14. Hi all. I have a form which pulls database data for a specific file when its hyperlink is selected. The form is filled correctly with the correct data. The page gives the user the option of editing this data and submitting the changes, which will update the database with the made changes. When the user clicks submit it will take the user to a new page called update.php where the changes take place. This is where my problems are happening. The message advising the updates have taken place, but when checking the DB, no changes have happened. <body> <?php include "configfile"; $aid=$_POST['AID']; $headline=$_POST['Headline']; $date=$_POST['Date']; $preview=$_POST['Preview']; $body=$_POST['Body']; $query="UPDATE tblname SET Headline='$headline', Date='$date', Preview='$preview', Body='$body' WHERE AID='$AID'"; mysql_query($query); echo "Record Updated"; mysql_close(); ?> </body> Where have I gone wrong?
  15. Right I've realised it was a JOIN that was required. And in a way have it working. I have the two tables that are joined. Table A contains article information with just an id number for a category. Table B contains category information, with the id from table a corasponding to a category name in table b. So for example categoryid 1 in table A would link with categoryid 1 in table b which would be general interest. The result I get I wasn't really expecting. I am getting a double copy of the category name, so it's printing general interest general interest. I'm not sure why, I've played around with the code but the only change I have managed is for it to print the category name 3 times instead of 2. Is it possible to just print it once? $query = "SELECT a.CategoryID, b.CategoryName FROM tblA a LEFT JOIN tblB b ON a.CategoryID = b.CategoryID"; //I have also tried //$query = "SELECT a.CategoryID, b.CategoryName FROM tblA a LEFT JOIN tblB b ON a.CategoryID = b.CategoryName"; $result = mysql_query($query) or die("Query failed: ".mysql_error()); if (mysql_num_rows($result) > 0) { echo "<table>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>".$row['CategoryName']."</td>"; //Also tried .$row['CategoryID'] echo "</tr>"; } echo "</table>"; } else { // no // print status message echo "No rows found!"; } Could anybody point me in the direction I have gone wrong? Is it even possible for it to just return the result once?
  16. If anyone can point me in the direction of an article as well, that would be great. I don't know what I'm looking for which is the problem I'm having more than anything!
  17. Not a good night for me tonight. I have two tables in my DB. One contains article data another contains category data. I have a create article page which has a drop down list displaying all of the categories stored in the DB. When the user submits the article it looks at what category was selected and stores the ID for that category in the articles table. That works fine. The problem I am having is when it comes to viewing the data in a page. I have a table that brings up all of the article information. I want to display the category that was selected for the article, which means translating the id stored in the articles table into the actual category name stored in the category table. How do I do this? Thanks
  18. Thanks for your help, it helped me figure it out. I didn't need the print line, but on the testindex page it was the lower case id that caused the issue. I had a feeling it would be something simple! Cheers!
  19. Hi all. I have a bit of a problem and can't figure out where I have gone wrong. I have 2 pages. 1 page displays an articles headline as a hyperlink and when selected takes the user to another page which displays all of the information for the selected article. The url of the article shows the articles id number, so if article 1 is selected for example, the url would be /article.php?id=1 for example. The first page works fine. Displays the article headlines in order with the headline acting as a hyperlink. The code is below; <?php //include config file //call query $query = "SELECT Headline, Preview, Body, ID FROM tbl ORDER BY ID DESC LIMIT 0,11"; //call result $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another echo "<table cellpadding=10 border=1>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td><a href='article.php?id=".$row['ID']."'>".$row['Headline']."</a></td>"; echo "<td>".$row['Preview']."</td>"; echo "</tr>"; } echo "</table>"; } else { // no // print status message echo "No rows found!"; } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> The second page doesn't work. It displays the error message that no article id was supplied, even though the URL has the article ID in it. The code is here; <?php if(empty($_GET['ID'])) { echo "<p class='error'>No article ID supplied.</p>\n"; } else if(!$_POST['ID']) { //include config file $title = ($_POST['Headline']); $query = "SELECT Headline, Body FROM tbl WHERE ID=".$_GET['ID']; $result = mysql_query($query) or die("Query failed: ".mysql_error()); if (mysql_num_rows($result) > 0) { // yes // print them one after another echo "<table cellpadding=10 border=1>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>".$row['Headline']."</a></td>"; echo "<td>".$row['Body']."</td>"; echo "</tr>"; } echo "</table>"; } else { // no // print status message echo "No rows found!"; } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); } ?> I can't figure out why it's not displaying the data. I've triple checked it. It's been a long day so I have a feeling it's going to be a tiny mistake. Can anyone spot where I have gone wrong? Thanks
  20. Managed to sort this out. PHP needed to come before the HTML code.
  21. Hi all. I'm following a tutorial on how to create a login page - it's something I've not done before and the tutorial can be found here - http://****/workshopview.php?id=6 I'm getting the following error thought; I have no idea why. This is the code for the checklogin.php page <html> <head> </head> <body> <?php //Include config file include "config.php"; // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> </body> </html> Looking around on the internet it appears white space could be the issue. However I cannot find any white space in this file or the config.php file. So I'm royally confused. Anyone push me in the right direction? Thanks
  22. Thanks a lot. I thought there would be something, but the books I have for some reason don't mention REFERENCE
  23. Hi again all. In SQL Server for example, if you have 2 tables that have a relationship together, you use Reference to make this relationship. Is there anything in MySQL that does the same thing? I am aware of JOIN, but I understand this is just for joining data when running a SELECT statement? Thanks
  24. LiamH

    [SOLVED] Unique

    That's what I thought. Thanks a lot
×
×
  • 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.