Jump to content

neogemima

Members
  • Posts

    72
  • Joined

  • Last visited

    Never

Everything posted by neogemima

  1. to center the page in explorer, do body text align center. That sometimes solves it if the page is in one large div tag.
  2. This is common for response emails. I haven't used one before, but you need what's called an HTML Filter. Sorry I couldn't be of more help.
  3. This looks like a textbook case of addslashes not working. Whats your code for the entry look like in your form?
  4. Premiso, that worked perfectly with one or two tweaks. Thank you much, I was able to have them list in reverse by saying "ORDER BY -id". Thanks much.
  5. Unfortunately I've tried it with the "&&" and the "AND" and they both act the same way. Are there any other ideas? Perhaps an if statement that says if the type is equal to 'General Laboratory' then echo the line, else, skip? If that might work, how do I say in code "else skip". Thanks.
  6. hello, I am using php to access my database and return rows that meet two different parameters. This one happens to return a number of articles in a list with links to each article's content. The problem I am having is that when I query the database for rows that meet two different criteria (id number and field['type']) it returns blank rows where the row in the database doesn't meet both. Here is my code: <?php //begin recent news doc @ $db = mysqli_connect('xxxxxx', 'xxxxxxx', 'xxxxxxx', 'xxxxxxx'); if (mysqli_connect_errno($db)) { echo 'Error: Could not connect to database. Please try again later.'; } mysqli_select_db($db, 'xxxxxxxxx'); $result = mysqli_query($db, "SELECT id, title, price FROM Equipmentposting"); $num_rows = mysqli_num_rows($result); $i = $num_rows; for($i = $num_rows; $i >= 1; $i--) { $sql = "SELECT id, date, type, title, price FROM Equipmentposting WHERE id = $i && type = 'General Laboratory'"; $queryresult = mysqli_query($db, $sql); $rowresult = mysqli_fetch_array($queryresult, MYSQLI_ASSOC); $id = $rowresult['id']; echo '<a href="equiparticle.php?id='.$id.'">'.$rowresult['date'].' '.$rowresult['title'].' '.$rowresult['price'].'</a>'; echo "<br>"; } ?> my output looks something like this: "//blank line active link because article meets both criteria //blank line //blank line //blank line active link because article meets both criteria" The blank lines are the rows in the table that have the id, but not type 'General Laboratory'. How do I make it that it does not display the blank lines? Oh, and I am using the id part as well so that postings with larger id numbers are displayed first (they are more recent posts).
  7. revraz, that did it for me. When I echoed the mysqli_error it said I made a stupid mistake and didn't autoincrement my row id. This whole time I've been getting false because of a duplicate entry in the id column. I feel like an idiot, thank you all for the help.
  8. I've been tearing my hair out over this one for two days. I have an html form that takes the user's input and inserts it into a database. The form also takes three images of their choosing and uploads them into an upload folder on GoDaddy's Server. For some reason the uploads work just fine to the upload folder, but the query is returning false. I can't for the life of me figure this out. Here is a snippet of my code: <?php $date= date("Y-m-d"); $title=$_POST['title']; $type=$_POST['type']; $email=$_POST['email']; $price=$_POST['price']; $equipmentcontent= str_replace("\n", "<br>", $_POST['equipmentcontent']); $img1=time().$_FILES['img1']['name']; $img2=time().$_FILES['img2']['name']; $img3=time().$_FILES['img3']['name']; if (!$title || !equipmentcontent || !$type || !$email) { echo "Please fill out the title, type of equipment, email, and the content of your post before proceeding.<br>"; exit; } if (!get_magic_quotes_gpc()) { $title = addslashes($title); $equipmentcontent = addslashes($equipmentcontent); $type = addslashes($type); $email = addslashes($email); $price = addslashes($price); } @ $db = mysqli_connect('xxxxx', 'xxxx', 'xxxxx', 'xxxxxx'); if ((($_FILES['img1']['type'] == "image/gif") || ($_FILES['img1']['type'] == "image/jpeg") || ($_FILES['img1']['type'] == "image/pjpeg")) && (($_FILES['img2']['type'] == "image/gif") || ($_FILES['img2']['type'] == "image/jpeg") || ($_FILES['img2']['type'] == "image/pjpeg")) && (($_FILES['img3']['type'] == "image/gif") || ($_FILES['img3']['type'] == "image/jpeg") || ($_FILES['img3']['type'] == "image/pjpeg")) && ($_FILES['img1']['size'] <= 150000) && ($_FILES['img2']['size'] <= 150000) && ($_FILES['img3']['size'] <= 150000)) { if (mysqli_connect_errno()) { echo "Error: Could not connect to database. Please try again later."; exit; } if (($_FILES['img1']['error'] || $_FILES['img2']['error'] || $_FILES['img3']['error']) > 0) { echo "Error: ".$_FILES['img1']['error']."<br> ".$_FILES['img2']['error']."<br>".$_FILES['img3']['error']."."; } else { move_uploaded_file($_FILES['img1']['tmp_name'], "uploads/".time().$_FILES['img1']['name']); move_uploaded_file($_FILES['img2']['tmp_name'], "uploads/".time().$_FILES['img2']['name']); move_uploaded_file($_FILES['img3']['tmp_name'], "uploads/".time().$_FILES['img3']['name']); } //I assume this is where everything goes wrong. $query = "INSERT INTO Equipmentposting (date, type, title, price, email, content, img1, img2, img3) VALUES ('$date', '$type', '$title', '$price', '$email', '$equipmentcontent', '$img1', '$img2', '$img3')"; $result = mysqli_query($db, $query); if ($result) { echo '<font color="#666666">'; echo 'Thank you.<br><br>'; echo '<font color="#000000">'.mysqli_affected_rows($db).'</font> posting has been uploaded to the site.<br><br>'; echo 'This posting will remain on the site for 30 days and can be seen in our <a href="http://www.biotechposting.com/pages/equipment.html" target="_parent">Equipment Classifieds</a> section.'; echo '<br><br>'; echo '<font size="-1">'; echo 'This service will remain free for the first few months of activity on BioTechPosting after which it will be a flat fee of $20 to post regardless of your location. Accompanying a post of this kind, you will also be able to post free industry news, a regular $20 value.<br>'; echo '</font></font>'; echo '<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>'; } else { echo "An error has occurred. Your post was not added.<br>"; echo "".$query."<br>."; } mysqli_close($db); } else { echo "Image files exceed maximum upload size of 150K or are an invalid format.<br>"; } ?> My echo statement comes out like this: An error has occurred. Your post was not added. INSERT INTO Equipmentposting (date, type, title, price, email, content, img1, img2, img3) VALUES ('2009-04-23', 'General Laboratory', 'asdf', 'asdf', 'asdf', 'asdf', '1240517000BETA-UNDER-CONSTRUCTION.jpg', '1240517000discussion.jpg', '1240517000reviews.jpg') I echoed the $query to see exactly what it was trying to pass and everything appears to be fine. What am I doing wrong here?
  9. So I have a site hosted on godaddy that allows users to post different things (i.e. news, lab equipment classifieds, etc.) I would like my users to be able to upload three images with their classified post, but I keep getting the error that my $file_get_contents function is failing because the string is broken. In other words, the path to the file is invalid because the server trying to follow it is across the internet. How can I get around this? Effectively, how can I upload a blob over the internet?
  10. If there are multiple keyword matches, you can add up the number of rows it calls from your database and use a for loop. It would be helpful if your table or database had an id number for each row Something like: for(i=0; i <= &numrows; i++) { ...code to call results from a row and move onto the next... } This doesn't answer your complete question, but I used something similar to call results from a table where my output was a list of News Titles with keyword pulled out.
  11. Are we to assume that the user has the opportunity to choose a team to try out for earlier in the code? If so, why not include a statement in the code that looks something like this: if($_POST['team_tryout'] == "null"){ echo "Please select a team to try out for." } else{ //continue code here } If you would like to achieve the same effect without leaving your initial form that we are getting these posts from, include some javascript in the header that tests to see if there is a selection. <script language="Javascript"> function validate(form) { var elem = form.elements; if (elem.team_tryout.value == null) { alert ('Please check your team tryout selection.'); return false; } else { return true; } } </script> Then put in your form onsubmit="return validate(this);" I'm making a few assumptions here, but I hope this helps.
  12. I think I have narrowed down my problem. Because the file path that is uploaded to the server (hosted by GoDaddy) is not local to the computer uploading the files over the internet, the file paths are invalid. How can I get around this? Or, how in general can I upload a BLOB over the internet?
  13. I am getting this error: Warning: file_get_contents(BETA-UNDER-CONSTRUCTION.jpg) [function.file-get-contents]: failed to open stream: No such file or directory for each image. I am reading many tutorials that use different methods. Can I not get the file and encode it directly into my mysql table of field type blob? Or do I need to create an upload file on my server to house the images and access them that way. If so, can someone elaborate on how this is done? Thanks.
  14. I am trying to upload 3 images to accompany a user's post, and keep getting returned my else statement for the mysqli query failing. I can't figure what is going wrong. Here is my code: <?php //create short variable names $maxfilesize= 150000; $date= date("Y/m/d"); $title=$_POST['title']; $type=$_POST['type']; $email=$_POST['email']; $price=$_POST['price']; $equipmentcontent= str_replace("\n", "<br>", $_POST['equipmentcontent']); if (!$title || !equipmentcontent || !$type || !$email) { echo "Please fill out the title, type of equipment, email, and the content of your post before proceeding.<br>"; exit; } if (!get_magic_quotes_gpc()) { $title = addslashes($title); $equipmentcontent = addslashes($equipmentcontent); $type = addslashes($type); $email = addslashes($email); $price = addslashes($price); $img1 = addslashes (file_get_contents($_FILES['img1']['tmp_name'])); $img2 = addslashes (file_get_contents($_FILES['img2']['tmp_name'])); $img3 = addslashes (file_get_contents($_FILES['img3']['tmp_name'])); } if ((($_FILES['img1']['type'] == "image/gif") || ($_FILES['img1']['type'] == "image/jpeg") || ($_FILES['img1']['type'] == "image/pjpeg")) && (($_FILES['img2']['type'] == "image/gif") || ($_FILES['img2']['type'] == "image/jpeg") || ($_FILES['img2']['type'] == "image/pjpeg")) && (($_FILES['img3']['type'] == "image/gif") || ($_FILES['img3']['type'] == "image/jpeg") || ($_FILES['img3']['type'] == "image/pjpeg")) && ($_FILES['img1']['size'] <= 150000) && ($_FILES['img2']['size'] <= 150000) && ($_FILES['img3']['size'] <= 150000)) { @ $db = mysqli_connect('xxxxxxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxxxx'); if (mysqli_connect_errno()) { echo "Error: Could not connect to database. Please try again later."; exit; } $query = "INSERT INTO Equipmentposting (date, type, title, price, email, content, img1, img2, img3) VALUES ('$date', '$type', '$title', '$price', '$email', '$equipmentcontent', '$img1', '$img2', '$img3')"; $result = mysqli_query($db, $query); if ($result) { echo '<font color="#666666">'; echo 'Thank you.<br><br>'; echo '<font color="#000000">'.mysqli_affected_rows($db).'</font> posting has been uploaded to the site.<br><br>'; echo 'This posting will remain on the site for 30 days and can be seen in our <a href="http://www.biotechposting.com/pages/equipment.html" target="_parent">Equipment Classifieds</a> section.'; echo '<br><br>'; echo '<font size="-1">'; echo 'This service will remain free for the first few months of activity on BioTechPosting after which it will be a flat fee of $20 to post regardless of your location. Accompanying a post of this kind, you will also be able to post free industry news, a regular $20 value.<br>'; echo '</font></font>'; echo '<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>'; } else { echo "An error has occured. Your post was not added."; } mysqli_close($db); } else { echo "Image files exceed maximum upload size of 150K or are an invalid format.<br>"; } ?> The return is the "An error has occured. Your post was not added." The only part of the images I want to upload to the database is the content itself so that I can call it to a web page and display the images. Does anyone know why the query is failing?
  15. That worked perfectly. I did need to reference the year as well. This is the code I used for April: for($i = $num_rows; $i >= 0; $i--) { $sql = "SELECT id, date, title FROM Newsposting WHERE EXTRACT(YEAR_MONTH FROM date) = 200905 AND id = $i"; $queryresult = mysqli_query($db, $sql); $rowresult = mysqli_fetch_array($queryresult, MYSQLI_ASSOC); //printf ("<u>(%s) %s</u>\n", $rowresult["date"], $rowresult["title"]); $id = $rowresult['id']; echo '<a href="article.php?id='.$id.'">'.$rowresult['date'].' '.$rowresult['title'].'</a>'; echo "<br>"; } Thanks for the help.
  16. Hello, I need help searching and displaying results from a database with a date field in the format YYYY-MM-DD. I have a database where anyone can post News at any time and is kept track of by a unique id and the date in the above format. I would like to query the database to return only the rows with a specific month (i.e. only news from month of April for ex.). How would I go about doing this? Here is my incorrect sample code: <?php //begin may09 news doc @ $db = mysqli_connect('database', 'xxxxx', 'xxxxx', 'xxxxx'); if (mysqli_connect_errno($db)) { echo 'Error: Could not connect to database. Please try again later.'; } mysqli_select_db($db, 'xxxxx'); $result = mysqli_query($db, "SELECT date FROM Newsposting"); //I think this is where I am having trouble. I don't know what kind of loop, if any, to use to display each row. $i = $result; while($i = date("Y-04-d")) { $sql = "SELECT id, date, title FROM Newsposting WHERE date = date('Y-04-d')"; $queryresult = mysqli_query($db, $sql); $rowresult = mysqli_fetch_array($queryresult, MYSQLI_ASSOC); //printf ("<u>(%s) %s</u>\n", $rowresult["date"], $rowresult["title"]); $id = $rowresult['id']; echo '<a href="article.php?id='.$id.'">'.$rowresult['date'].' '.$rowresult['title'].'</a>'; echo "<br>"; } ?> I am definitely a noob at this and appreciate the help.
  17. That's a good idea. I am new to PHP, so I imagine my code is a bit roundabout using code I am familiar with. Any thoughts on making each link connect to its own page?
  18. Hello, so here is my dilemma. I have managed, thanks to your help here on the forums to create a page that accepts input from users to create "News" postings to my website and get that news to display in order on the home page using a generic php file I named "recentnews.php". Now I would like to get each posting to link to its unique content, i.e. a page displaying the title and contents of that particular post. Right now, to get recentnews.php to post the articles I am using this for loop: $i = $num_rows; for($i = $num_rows; $i >= ($num_rows - 31); $i--) { $sql = "SELECT id, date, title FROM Newsposting WHERE id = $i"; $queryresult = mysqli_query($db, $sql); $rowresult = mysqli_fetch_array($queryresult, MYSQLI_ASSOC); //printf ("<u>(%s) %s</u>\n", $rowresult["date"], $rowresult["title"]); echo '<a href="article.php">'.$rowresult['date'].' '.$rowresult['title'].'</a>'; echo "<br>"; } I want only the most recent 31 posts to display. I know that "<a href="article.php">" is not correct. Anyone have any suggestions? The site is: www.biotechposting.com and these news posts can be seen on the home page, right now they are just tests with random titles. Thanks in advance.
  19. I am pretty new to PHP and MySQL and some code is making me tear my hair out. I have a form, and just need to upload the data to my table that is already made in my database. Here is my code: <?php //create short variable names $title=$_POST['title']; $newscontent=$_POST['newscontent']; if (!$title || !newscontent) { echo "Please fill out both the title of the posting and the content.<br>"; exit; } if (!get_magic_quotes_gpc()) { $title = addslashes($title); $newscontent = addslashes($newscontent); } @ $db = mysqli_connect('hostname', 'user', 'pass', 'database'); if (mysqli_connect_errno()) { echo "Error: Could not connect to database. Please try again later."; exit; } $query = "INSERT INTO NEWSPOSTING (title, content) VALUES ('$title', '$content')"; $result = mysqli_query($query); if ($result) { echo mysqli_affected_rows.' posting added to database.'; } else { echo "An error has occured. The item was not added."; } mysqli_close($db); ?> The lines: $query = "INSERT INTO NEWSPOSTING (title, content) VALUES ('$title', '$content')"; $result = mysqli_query($query); keep returning an error no matter what I do. Here is the error: Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/content/b/i/o/biotechposting/html/pages/forms/insert_news.php on line 37 An error has occured. The item was not added. Does anyone have any suggestions? Much appreciated.
×
×
  • 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.