Jump to content

lauren_etherington

Members
  • Posts

    55
  • Joined

  • Last visited

Everything posted by lauren_etherington

  1. Ansego It is set to post because when you click 'Submit' it posts the updated into back to the database and updates the row
  2. Well $i should be the id field of the row so it should find the id and then pull the info from that row. I use this code layout for quite a bit of work and I normally don't have any issues, The way it is now has worked in the past when I have used it in other projects (with the obvious bits changed) however despite countless comparisons and completely copying and pasting code, I just cannot fathom it. There must be something that I'm not seeing :S
  3. Nope, It doesnt display anything at all. Just the html on the page where I call the function.
  4. It has just given this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given -- on line x
  5. It sounds daft but I changed $enquery = "SELECT * FROM news WHERE newsid=$i"; to read: $enquery = "SELECT * FROM news WHERE newsid=1"; just to double check the query syntax was correct and it pulled the data, so I don't think its the connection string :S
  6. Hello Forumites!! I would like to ask a bit of advice please. I am currently writing a peice of code where my user can add content to their database and retreive it from the database when they view it live on the website. I want them to be able to edit their content and this my friends is wherein the problem lies. This is my Edit code: <?php function editnews($i) { $conn = mysqli_connect("Connection Stringy Stuff"); $enquery = "SELECT * FROM news WHERE newsid=$i"; $enresult = mysqli_query($conn, $enquery) or trigger_error("Query Failed! SQL: $conn - Error: ".mysqli_error(), E_USER_ERROR); while ($enrow = mysqli_fetch_array($enresult)) { echo " <form enctype='multipart/form-data' action='newsedit.php' method='post'> <table> <tr> <td>News Ref:</td> <td>" . $i . "<input type='hidden' name='newsid' value='" . $i . "' /><input type='hidden' name='oldim' value='" . $enrow['newsimage'] . "' /></td> </tr> <tr> <td>Title:</td> <td><input type='text' name='title' value='" . $enrow['newstitle'] . "' size='100' /></td> </tr> <tr> <td>Author:</td> <td><input type='text' name='author' value='" . $enrow['newsauthor'] . "' size='100' /></td> </tr> <tr> <td>Status:</td> <td><select name='stat'><option value='enabled' "; if ($enrow['newstatus'] == "enabled") { echo "selected='selected' "; } echo ">Enabled</option><option value='disabled' "; if ($enrow['newsstatus'] == "disabled") { echo "selected='selected' "; } echo "}>Disabled</option></select> </td> </tr> <tr> <td>Snippettext:</td> <td><textarea name='snip' rows='6' cols='80'>" . $enrow['newssnippet'] . "</textarea></td> </tr> <tr> <td>News story:</td> <td><textarea name='stry' rows='20' cols='80'>" . $enrow['newsarticle'] . "</textarea></td> </tr> <tr> <td>Current image:</td> <td>" . $enrow['newsimage'] . " - <a href='news/" . $enrow['newsimage'] . "' target='_blank'>View Image</a></td> </tr> <tr> <td>Change Image:</td> <td><input type='file' name='file'></td> </tr> <tr> <td colspan='2'><input type='submit' name='submit' value='Edit' /></td> </tr> </table> </form> "; } } ?> This code displays on the 'Edit' page using the following above the DOC type: <?php include('functions/newseditform.php'); $i = $_GET['i']; ?> AND the following in the HTML: <?php editnews($i) ?> The problem I have however is that the code at the top, does not actually display anything on the html page I have debugged the code in my IDE and received these error messages: Notice: Undefined index: i in pathway on Line 3 (This is the bit at the top of the 'Edit' page) AND Catchable fatal error: Object of class mysqli could not be converted to string in 'pathway' on line 8 this being this line of the edit code: $enresult = mysqli_query($conn, $enquery) or trigger_error("Query Failed! SQL: $conn - Error: ".mysqli_error(), E_USER_ERROR); Before I added the 'trigger_error' bit, it was displaying the "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given" error. If anyone can help point out where I went wrong I would be very appreciative. Thanks!!!
  7. I knew it was something little and stupid!!! I feel a bit silly now haha. Thank you very much.
  8. Hello PHPer's I am having a few problems with my code. I've probably missed something but could do with an outsiders opinion. Basically, I am writing a bit of code where the user can enter some information and an image into a form and save it to the mysql database. For the most part, the code works, If I don't add the image then the content is all saved. However, when I do add an image I am just given my predefined error message from the code. The php debugger is not much use as the connection is for a local host which is stored on a server and not on my PC.... This is the code: $auth = $_POST['auth']; $tit = $_POST['tit']; $band = $_POST['band']; $alb = $_POST['alname']; $rel = $_POST['release']; $stat = $_POST['stat']; $shrt = $_POST['short']; $art = $_POST['art']; $conn = mysqli_connect("localhost","") or die ("Could not connect to database"); if(!is_uploaded_file($_FILES['file']['tmp_name'])) { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } else { if ($_FILES['file']['type'] != "image/gif" && $_FILES['file']['type'] != "image/jpeg" && $_FILES['file']['type'] != "image/jpg" && $_FILES['file']['type'] != "image/x-png" && $_FILES['file']['type'] != "image/png") { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } else { $finame = $_FILES["file"]["name"]; //$ext = end(explode(".", $finame)); $result = move_uploaded_file($_FILES['file']['tmp_name'], "../includes/$finame"); if ($result == 1) { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status,image) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat''$finame'))"; //echo "$naquery"; } else { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } } } $result = mysqli_query($conn, $query); if($result){ echo "successful"; echo "<BR>"; echo "<a href='http://'>Back to Content Management </a>"; } else { echo "error could not upload article"; echo "<BR>"; echo "<a href='http://'>Back to Content Management </a>"; } mysqli_close($conn); ?> Any help on getting this to upload the image files would be much appreciated. Thanks
  9. I am having a minor problem with my code if any one can help. I have a form where the user can add a new article however on submit this error is displayed: Warning: mysqli_query() expects parameter 1 to be mysqli, object given in //public_html/admin/includes/addnews.php on line 12. This is the code: $auth = $_POST['auth']; $tit = $_POST['tit']; $stat = $_POST['stat']; $shrt = $_POST['short']; $art = $_POST['art']; $conn = mysqli_connect("localhost","db","password","db") or die ("Could not connect to database"); $query = $conn->prepare ("INSERT INTO newsitem (author,title,shortdesc,article,newsdate,status) VALUES ('$auth','$tit','$shrt','$art',CURDATE(),'$stat')"); $result = mysqli_query($query,$conn); if($result){ echo "successful"; echo "<BR>"; echo "<a href='news.php'>Back to News </a>"; } else { echo "error could not upload article"; } mysqli_close($conn); ?> I have been looking at this for the last two hours with no hope, is there anyone who can point me in the right direction please?
  10. I've managed to fix this error but thanks guys!
  11. Sooo, I could use some help. The code is needed to populate a database from the form, unfortunately, it is not populating the database. When I click submit, a white page appears <?php $a = $_POST['auth']; $t = $_POST['tit']; $st = $_POST['stat']; $sn = $_POST['short']; $c = $_POST['art']; $conn = mysqli_connect(""); if(!is_uploaded_file($_FILES['file']['tmp_name'])) { $query = "INSERT INTO newsitem (author,title,shortdesc,article,newsdate,status) VALUES ('$a','$t','$sn','$c',CURDATE(),'$st')"; } else { if ($_FILES['file']['type'] != "image/gif" && $_FILES['file']['type'] != "image/jpeg" && $_FILES['file']['type'] != "image/jpg" && $_FILES['file']['type'] != "image/x-png" && $_FILES['file']['type'] != "image/png") { $query = "INSERT INTO newsitem (author,title,shortdesc,article,newsdate,status) VALUES ('$a','$t','$sn','$c',CURDATE(),'$st')"; } else { $finame = $_FILES["file"]["name"]; $result = move_uploaded_file($_FILES['file']['tmp_name'], "../news/$finame"); if ($result == 1) { $query = "INSERT INTO newsitem (author,title,shortdesc,article,newsdate,status) VALUES ('$a','$t','$sn','$c',CURDATE(),'$st','$finame')"; } else { $query = "INSERT INTO newsitem (author,title,shortdesc,article,newsdate,status) VALUES ('$a','$t','$sn','$c',CURDATE(),'$st')"; } } } $conn->close(); ?> I cannot for the life of me see what it wrong with it, When I run the debugger it cuts off at conn with the Call to undefined function mysqli_connect() error message. If anyone could help point me in the right direction that would be great
  12. Edit: I have updated the query slightly so it now reads: $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,imageposition FROM newsitem INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid LEFT JOIN newsimage ON newsitem.niid=newsimage.niid WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' "; so the 'newsimage' does not display on the news page but when you click 'read more' it does display alongside the news article. However, it is still displaying the news title as both text and as an image...... help?
  13. Confused!

    1. Stefany93

      Stefany93

      No one would be in this forum if 90% of the users weren't.

  14. I have been developing some code that will allow my client to chose whether she wants to put an image left, right or centred on her news page. The code is working brilliantly and allows her to do so (thanks to this forum!) However - the news title is displaying twice on the page. Once as an image and once as text........ I removed 'newsimage' from the sql query however it is still displaying the title as an image even though it is no longer looking for the image? Completely confused as to why it has started doing this. Heres the code: // Show latest 10 news items function top10news($s, $t, $u, $w) { session_start(); $con = mysqli_connect("*****************", "*****************", "*****************", "*****************"); if (mysqli_connect_errno($con)) { echo "<p class='sect'>Could not connect to the database</p>"; } else { $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid LEFT JOIN newsimage ON newsitem.niid=newsimage.niid WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' "; if ($u != "Any") { $q = $q . "AND sitename='$u' "; } if ($s != "Any") { $parts = explode('-', $s); $y = $parts[0]; $m = $parts[1]; $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m "; } $q = $q . "ORDER BY newsdate DESC LIMIT 0,10"; $result = mysqli_query($con, $q); while ($tnrow = mysqli_fetch_array($result)) { echo " <div class='newssummary'>"; if ("" . $tnrow ['imageposition'] . "" == "None") { echo "<p class = 'newsmore' > <a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>"; } else if ($tnrow ['imageposition'] == 'Centre') { echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } else if ($tnrow ['imageposition'] == 'Right') { echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } else if ($tnrow ['imageposition'] == 'Left') { echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>"; echo " <p><strong>" . $tnrow['newstitle'] . "</strong></p> <p class='news'>" . $tnrow['newssnippet'] . "</p> </div> <div class='padder1'></div> <div class='rtgreengp'></div> "; } mysqli_close($con); } } It seems to display correctly if I upload an image along with an article..... so from what I can see if there is no image uploaded, it is just replacing it with the news title? if that makes any sense....... Any advice out there?
  15. You are actually a star. Thank you!!!!!
  16. I'm not getting anything from the debugger. Thank you for the help though!
  17. Cheers, I've gone through and sorted the {} out so all the formatting is now working. It just not displaying. Its a small piece of php code in the html file. <?php newsform(); top10news($s,$t,$u,$w); ?> it should display the php function - Just wondering if anything is missing in the PHP that would stop it from displaying? since the 'newsform()' function displays fine....... { $con = mysqli_connect("**********************************"); if (mysqli_connect_errno($con)) { echo "<p class='sect'>Could not connect to DB</p>"; } else { $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid LEFT JOIN newsimage ON newsitem.niid=newsimage.niid WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' "; if ("$u" == "Any") { } else { $q = $q . "AND sitename='$u' "; } if ("$s" == "Any") { } else { $parts = explode('-', $s); $y = $parts[0]; $m = $parts[1]; $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m "; } $q = $q . "ORDER BY newsdate DESC LIMIT 0,10"; $result = mysqli_query($con, $q); while ($tnrow = mysqli_fetch_array($result)) { echo " <div class='newssummary'>"; if ("" . $tnrow ['newsimage'] AND $tnrow ['imageposition'] . ""== "none") { echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>"; } else if ($tnrow ['imageposition'] == 'Centre') { echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } else if ($tnrow ['imageposition'] == 'Right') { echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } else if ($tnrow ['imageposition'] == 'Left') { echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>"; echo " <p><strong>" . $tnrow['newstitle'] . "</strong></p> <p class='news'>" . $tnrow['newssnippet'] . "</p> </div> <div class='padder1'></div> <div class='rtgreengp'></div>"; } } mysqli_close($con); } From what I can see there are now no missing ;'s or {}'s and quotation marks seem to be all in place.
  18. Oh dear..... I am in such a stress I completely forgot to erase that :S Thank you for pointing that out!
  19. I've modified my own code with your suggestions and while there is a vast improvement the page still isn't displaying quite right and it is no longer displaying the newest 10 news items. At least it's displaying something though and that is progress! thanks lol. This is the updated code: { session_start(); $con = mysqli_connect("79.170.44.78", "web78-nor586t31", "tech1758N56", "web78-nor586t31"); if (mysqli_connect_errno($con)) { echo "<p class='sect'>Could not connect to DB</p>"; } else { $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid LEFT JOIN newsimage ON newsitem.niid=newsimage.niid WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' "; if ("$u" == "Any") { } else { $q = $q . "AND sitename='$u' "; } if ("$s" == "Any") { } else { $parts = explode('-', $s); $y = $parts[0]; $m = $parts[1]; $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m "; } $q = $q . "ORDER BY newsdate DESC LIMIT 0,10"; $result = mysqli_query($con, $q); while ($tnrow = mysqli_fetch_array($result)) { echo " <div class='newssummary'>"; if ("" . $tnrow ['newsimage'] . "" == "none") { echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>"; }else if ($tnrow ['imageposition'] == 'Centre') { echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; }else if ($tnrow ['imageposition'] == 'Right') { echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; }else if ($tnrow ['imageposition'] == 'Left') { echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } } echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>"; } echo " <p><strong>" . $tnrow['newstitle'] . "</strong></p> <p class='news'>" . $tnrow['newssnippet'] . "</p> </div> <div class='padder1'></div> <div class='rtgreengp'></div> "; } mysqli_close($con); When I run the debugger it seems to think that $con is not defined and producing this warning. Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\Users\lauren.etherington\Documents\Projects\test\Group\public_html\news\news_fns.php on line 59 Could this be the reason I'm having this new problem?
  20. It was those missing quotes that was causing the white screen. Completely different error now but thankfully it's actually displaying something now!!!
  21. <?php // Show latest 10 news items function top10news($s, $t, $u, $w) { $con = mysqli_connect("connection to database"); if (mysqli_connect_errno($con)) { echo "<p class='sect'>Could not connect to DB</p>"; } else { // echo "<p class='sect'>Connected to DB</p>"; $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' "; if ("$u" == "Any") { } else { $q = $q . "AND sitename='$u' "; } if ("$s" == "Any") { } else { $parts = explode('-', $s); $y = $parts[0]; $m = $parts[1]; $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m "; } $q = $q . "ORDER BY newsdate DESC LIMIT 0,10"; $result = mysqli_query($con, $q); while ($tnrow = mysqli_fetch_array($result)) { echo " <div class='newssummary'>"; if ("" . $tnrow['newsimage'] . "" == "none") { echo <p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>; }else $radio = mysqli_query("SELECT imageposition FROM newsimage WHERE imageposition EQUALS newsitem.niid=newsimage.niid"); $radio = mysqli_query($con, $radio); while (($tnrow = mysqli_fetch_array($radio)); { if ($tnrow == 'Centre') { echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; }else if ($tnrow == 'Right') { echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; }else if ($tnrow == 'Left') { echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } } echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>"; } echo " <p><strong>" . $tnrow['newstitle'] . "</strong></p> <p class='news'>" . $tnrow['newssnippet'] . "</p> </div> <div class='padder1'></div> <div class='rtgreengp'></div> "; } } mysqli_close($con); }
×
×
  • 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.