Jump to content

lauren_etherington

Members
  • Posts

    55
  • Joined

  • Last visited

Everything posted by lauren_etherington

  1. Okay so good news!!! I have removed all the errors from the script all on my lonesome However, I am unable to view the Event Button that should display on top of the correct date. It would be helpful if I could actually edit my original post Is there any reason why the button would not be showing up? Code is basically the same with a few ammendments to the calendar_start.php <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); $showmonth = $_POST['showmonth']; $showyear = $_POST['showyear']; $showmonth= preg_replace('#[^0-9]#i', '', $showmonth); $showyear= preg_replace('#[^0-9]#i', '', $showyear); $day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear); $pre_days = date('w', mktime(0,0,0, $showmonth, 1, $showyear)); $post_days = (6-(date('w', mktime(0,0,0, $showmonth, $day_count, $showyear)))); echo '<div id="calendar-wrap">'; echo '<div class="title-bar">'; echo '<div class="previous-month"><input name="button" type="submit" value="Previous Month" onClick="javascript:last_month();"></div>'; echo '<div class="show-month">' . date('F', mktime(0, 0, 0, $showmonth)) . ' ' . $showyear . '</div>'; echo '<div class="next-month"><input name="button" type="submit" value="Next Month" onClick="javascript:next_month();"></div>'; echo '</div>'; echo '<div class="week_days">'; echo '<div class="days-of-week">Sun</div>'; echo '<div class="days-of-week">Mon</div>'; echo '<div class="days-of-week">Tues</div>'; echo '<div class="days-of-week">Wed</div>'; echo '<div class="days-of-week">Thur</div>'; echo '<div class="days-of-week">Fri</div>'; echo '<div class="days-of-week">Sat</div>'; echo '<div class="clear"></div>'; echo '</div>'; //Previous Month days if ($pre_days != 0) { for($i=1; $i<=$pre_days; $i++) { echo '<div class="non-cal-days"></div>'; } } //Current Month Days $conn = mysqli_connect("Database Connection") or die ("Could not connect to the Database"); for ($i=1; $i<= $day_count; $i++) { //get event logic $date = $i.'/'.$showmonth.'/'.$showyear; $query = mysqli_query($conn, 'SELECT calid FROM calendar WHERE caldate = "'.$date.'"') or trigger_error("Query Failed! SQL: $query - Error: ".mysqli_error($conn), E_USER_ERROR); $num_rows = mysqli_num_rows($query); if($num_rows > 0) { $event = "<input name='$date' type='submit' value='Details' id='$date' onClick='javascript:show_details(this);'>"; } echo '<div class="cal-days">'; echo '<div class="day-heading">' . $i . '</div>'; if($num_rows != 0) { echo "<div class='opening'><br/>" . $event . "</div>";} echo '</div>'; } //Next Months Days if ($post_days !=0) { for($i=1; $i<=$post_days; $i++) { echo '<div class="non-cal-days"></div>'; } } echo '</div>'; ?> I do wonder if there is anything to do with the $deets variable? I don't know. I have never built a calendar before I just need a bit of advice..... Thanks
  2. I found a tutorial on youtube that would allow me to create a calendar of events. We have the calendar html page: This includes the onload="initialCalendar();" function <script type="text/javascript"> /* <![CDATA[ */ function initialCalendar(){ var hr = new XMLHttpRequest(); var url = "calendar/calendar_start.php"; var currentTime = new Date (); var month = currentTime.getMonth() + 1; var year = currentTime.getFullYear(); showmonth = month; showyear = year; var vars= "showmonth="+showmonth+"&showyear="+showyear; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if (hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("showCalendar").innerHTML = return_data; } } hr.send(vars); document.getElementById("showCalendar"). innerHTML = "processing..."; } /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ function next_month() { var nextmonth = showmonth + 1; if(nextmonth > 12) { nextmonth = 1; showyear = showyear+1; } showmonth = nextmonth; var hr = new XMLHttpRequest(); var url = "calendar/calendar_start.php"; var vars= "showmonth="+showmonth+"&showyear="+showyear; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if (hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("showCalendar").innerHTML = return_data; } } hr.send(vars); document.getElementById("showCalendar"). innerHTML = "processing..."; } /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ function last_month() { var lastmonth = showmonth - 1; if(lastmonth < 1 ) { lastmonth = 12; showyear = showyear-1; } showmonth = lastmonth; var hr = new XMLHttpRequest(); var url = "calendar/calendar_start.php"; var vars= "showmonth="+showmonth+"&showyear="+showyear; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if (hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("showCalendar").innerHTML = return_data; } } hr.send(vars); document.getElementById("showCalendar"). innerHTML = "processing..."; } /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ function overlay() { el = document.getElementById("overlay"); el.style.display = (el.style.display == "block") ? "none" : "block"; el = document.getElementById("events"); el.style.display = (el.style.display == "block") ? "none" : "block"; el = document.getElementById("eventsBody"); el.style.display = (el.style.display == "block") ? "none" : "block"; } /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ function show_details(theId) { var deets = (theId.id); el = document.getElementById("overlay"); el.style.display = (el.style.display == "block") ? "none" : "block"; el = document.getElementById("events"); el.style.display = (el.style.display == "block") ? "none" : "block"; var hr = new XMLHttpRequest(); var url = "calendar/events_fns.php"; var vars = "deets="+deets; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange= function() { if (hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("events").innerHTML = return_data; } } hr.send(vars); document.get ElementById("events").innerHTML = "processing..."; } /* ]]> */ </script> The script to show to actual calendar is called from here.... calendar_start.php <?php $showmonth = $_POST['showmonth']; $showyear = $_POST['showyear']; $showmonth= preg_replace('#[^0-9]#i', '', $showmonth); $showyear= preg_replace('#[^0-9]#i', '', $showyear); $day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear); $pre_days = date('w', mktime(0,0,0, $showmonth, 1, $showyear)); $post_days = (6-(date('w', mktime(0,0,0, $showmonth, $day_count, $showyear)))); echo '<div id="calendar-wrap">'; echo '<div class="title-bar">'; echo '<div class="previous-month"><input name="button" type="submit" value="Previous Month" onClick="javascript:last_month();"></div>'; echo '<div class="show-month">' . date('F', mktime(0, 0, 0, $showmonth)) . ' ' . $showyear . '</div>'; echo '<div class="next-month"><input name="button" type="submit" value="Next Month" onClick="javascript:next_month();"></div>'; echo '</div>'; echo '<div class="week_days">'; echo '<div class="days-of-week">Sun</div>'; echo '<div class="days-of-week">Mon</div>'; echo '<div class="days-of-week">Tues</div>'; echo '<div class="days-of-week">Wed</div>'; echo '<div class="days-of-week">Thur</div>'; echo '<div class="days-of-week">Fri</div>'; echo '<div class="days-of-week">Sat</div>'; echo '<div class="clear"></div>'; echo '</div>'; //Previous Month days if ($pre_days != 0) { for($i=1; $i<=$pre_days; $i++) { echo '<div class="non-cal-days"></div>'; } } //Current Month Days $conn = mysqli_connect('Databaseconnection Things') or die ("Could not connect to the Database"); for ($i=1; $i<= $day_count; $i++) { //get event logic $date = $i.'/'.$showmonth.'/'.$showyear; $query = mysqli_query('SELECT calid FROM calendar WHERE caldate = "'.$date.'"') or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($query), E_USER_ERROR); $num_rows = mysqli_num_rows($conn, $query); if($num_rows > 0) { $event = "<input name='$date' type='submit' value='Details' id='$date' onClick='javascript:show_details(this);'>"; } echo '<div class="cal-days">'; echo '<div class="day-heading">' . $i . '</div>'; if($num_rows != 0) { echo "<div class='opening'><br/>" . $event . "</div>";} echo '</div>'; } //Next Months Days if ($post_days !=0) { for($i=1; $i<=$post_days; $i++) { echo '<div class="non-cal-days"></div>'; } } echo '</div>'; ?> And events_fns. <?php $deets = $_POST['deets']; $deets = preg_replace('#[^0-9/]#i', '', $deets); $conn = mysqli_connect("Database Connection") or die ("Could not connect to the Database"); $events = ''; $query = mysqli_query('SELECT calid FROM calendar WHERE caldate = "'.$deets.'"') or die ("Error:".mysqli_errno()); //echo "$query"; $num_rows=0; if ($result = mysqli_query($query,$conn)) { $num_rows = mysqli_num_rows($result); } if ($num_rows > 0) { $events .= '<div id="eventsControl"><button onMouseDown="overlay()">Close</button><br /><br />'.$deets.'<br /><br /></div>'; while ($row = mysqli_fetch_array($query)) { $title = $row['eventtitle']; $desc = $row['description']; $loc = $row['eventlocation']; $events .='<div id="eventsBody">'.$title.'<br />'.$desc.'<br />'.$loc.'<hr /></div>'; } } echo $events; ?> I have posted all the code so you can see how it fits together ect ect however the issue I am having is an error message that repeats across the page. it reads: Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /home/sites/agile-cms.co.uk/public_html/mfcf/calendar/calendar_start.php on line 49 Fatal error: Query Failed! SQL: - Error: in /home/sites/agile-cms.co.uk/public_html/mfcf/calendar/calendar_start.php on line 49 for ($i=1; $i<= $day_count; $i++) { //get event logic $date = $i.'/'.$showmonth.'/'.$showyear; $query = mysqli_query($conn, 'SELECT eventid FROM events WHERE eventdate = "'.$date.'"') or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($query), E_USER_ERROR); $num_rows = mysqli_num_rows($query); if($num_rows > 0) { $event = "<input name='$date' type='submit' value='Details' id='$date' onClick='javascript:show_details(this);'>"; } echo '<div class="cal-days">'; echo '<div class="day-heading">' . $i . '</div>'; if($num_rows != 0) { echo "<div class='opening'><br/>" . $event . "</div>";} echo '</div>'; } I think I have missed something being so close to it and I think I need an outside P.O.V to look at it and point me in the right direction.... Any help would be much appreciated....
  3. Okay so I have attempted to use Abrahams OAuth plugin. I have added in my Consumer and Secret Key however I have received the precoded message "You need a consumer key and secret to test the sample code. Get one from dev.twitter.com/apps" Obviously this looks like there is something up the the keys, Is there anyway to trouble shoot as to why the keys are not "active"
  4. Please also bear in mind I do have twitteroauth.php and oauth.php in a separate directory. These have remained untouched and the twitteroauth.php file points to Twitters 1.1 not 1.0 API
  5. Good day Campers! Having spent the better part of my day trawling the internet for an answer I have gotten nowhere so have come to you lovely people for help. I found a nice little tutorial on PHP gang that would allow me to update my twitter feed from my website using PHP and OAuth. I set up my twitter app with no issues and generated the API keys. Set the App to 'read/write' permissions and then regenerated the keys The app is marked to "Allow this application to be used to Sign in with Twitter" The issue is that when I click the little button to sign in to twitter, the page redirects but displays the generic "Cannot connect to Twitter" error message that has been defined in the code. I do not get asked to "Allow" the script to connect to twitter like it seems to do in the demo. The PHPGang solution has 4 bits of script so I'm wondering if it has something to do with this as I understand the Abrahams script has slightly more so I do wonder if something is missing. I'm not sure. One of the main problems I am facing is that I have never actually done this before so I don't know where I have gone wrong or what I am even looking for help wise...... I have the following scripts: callback.php <?php /** * Take the user when they return from Twitter. Get access tokens. * Verify credentials and redirect to based on response from Twitter. */ session_start(); require_once('oauth/twitteroauth.php'); require_once('config.php'); if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) { $_SESSION['oauth_status'] = 'oldtoken'; header('Location: ./destroysessions.php'); } $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); //save new access tocken array in session $_SESSION['access_token'] = $access_token; unset($_SESSION['oauth_token']); unset($_SESSION['oauth_token_secret']); if (200 == $connection->http_code) { $_SESSION['status'] = 'verified'; header('Location: ./index.php'); } else { header('Location: ./destroysessions.php'); } ?> config.php <?php /** * @file * A single location to store configuration. */ define('CONSUMER_KEY', 'MY CONSUMER KEY'); define('CONSUMER_SECRET', 'MY SECRECT CONSUMER KEY'); define('OAUTH_CALLBACK', 'URL OF WHERE I AM REDIRECTING TO'); ?> destroysessions.php <?php /** * @file * Clears PHP sessions and redirects to the connect page. */ /* Load and clear sessions */ session_start(); session_destroy(); /* Redirect to page with the connect to Twitter option. */ header('Location: ../index.php'); ?> index.php <?php require_once('oauth/twitteroauth.php'); require_once('config.php'); if(isset($_POST["status"])) { $status = $_POST["status"]; if(strlen($status)>=130) { $status = substr($status,0,130); } $access_token = $_SESSION['access_token']; $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $connection->post('statuses/update', array('status' => "$status")); $message = "Tweeted Sucessfully!!"; } if(isset($_GET["redirect"])) { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); $request_token = $connection->getRequestToken(OAUTH_CALLBACK); $_SESSION['oauth_token'] = $token = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; switch ($connection->http_code) { case 200: $url = $connection->getAuthorizeURL($token); header('Location: ' . $url); break; default: echo '<div class="par">Could not connect to Twitter. Refresh the page or try again later.</div>'; } exit; } if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) { echo '<a href="./index.php?redirect=true"><img src="./images/lighter.png" alt="Sign in with Twitter"/></a>'; } else { echo "<a href='destroysessions.php'>Logout</a><br>"; echo '<div class="par">'.$message.'<div> <form action="index.php" method="post"> <input type="text" name="status" id="status" placeholder="Write a comment...."> <input type="submit" value="Post On My Wall!" style="padding: 5px;"> </form>'; } ?> Now, I am unsure if there is anything wrong with the API keys I have generated or if there is something missing. Is there anyone who can point me in the right direction or offer some advice on where to turn? Thanks!
  6. I've been browsing the internets, would I need Java/Jquery to get this to behave and hash the password on submit??
  7. Hi Mr Psycho! Thank you for that!!! I've tried that code you wrote and unfortunaltely it is not hashing the password, I just get this error message: Debug: Password does not match. Submitted PW: "unhashed version of password", PW Hash: "hashed version of password", DB Hash: So it is still not hashing the password before comparing it.... I have moved this $passwordHash = hash('sha256', $user['userpassword']."$password"); so it is now above the query but hasn't made a difference (taking into account Ginerjms advice... I think(hope)?) It's authenticating the username fine though So at least I know one bits working haha!
  8. I am sorry, But like I said, This isn't something I have come accross before. So I want to 100% fully understand what do to with it. Which hash line? Would it be this one before the query? $hash = hash('sha256', $userData['userpassword']."$password"); So the password will be hashed on submit? And then this hashed password will be compared to the one in the database?
  9. Like I said earlier, I have never wrote a log in script with hashed passwords ect before so rather than comparing the two would it look something more like this? So if the user is found it would do the compare? :S Maybe? session_start(); $username = $_POST['username']; $password = $_POST['password']; $conn = mysqli_connect("Connection String"); $username = mysqli_real_escape_string($conn, $username); $query="SELECT * FROM users WHERE username='$username' AND userpassword='$password'"; $result = mysqli_query($conn, $query); if(mysqli_num_rows($result) == 1) { $userData = mysqli_fetch_array($result); $hash = hash('sha256', $userData['userpassword']."$password"); //echo "$hash"; if($hash != $userData['userpassword']) // Incorrect password. So, redirect to login_form again. { $conn->close(); header('Location: ../login.php?e=Incorrect login details'); exit(); } } else{ // Redirect to home page after successful login. $_SESSION['username'] = $username; $_SESSION['user'] = $userData['userid']; $_SESSION['sp'] = $userData['cmspassword']; $conn->close(); header('Location: index.php'); exit(); } EDIT -- Sorry, I posted this just as you posted that comment.... So I need to sumbit the password and hash it in order it compare it to the stored password?? and if it matches then redirect to the index page?
  10. Process where the password is originally stored at your request $un = $_POST['uname']; $em = $_POST['mail']; $ap = $_POST['apass']; $cp = $_POST['cpass']; $pw = hash('sha256', "$ap$cp"); //connect to Database $conn = mysqli_connect("connection string"); if(!$conn || $conn->connect_errno){ echo "Connection error " . $conn->connect_errno . " " . $conn->connect_error; } //define Query $avquery = "INSERT INTO users (username,useremail,userpassword,cmspassword) VALUES ('$un','$em','$pw','$cp')"; //run query $result = mysqli_query($conn, $avquery); if($result){ echo "Entered data successfully"; echo "<BR />"; echo "click <a href='http:///admin/users.php'>here</a> to return to Users"; } else { echo "Oh No! Something has gone wrong and the data could not be uploaded"; echo "<BR />"; echo "click <a href='http:///admin/users.php'>here</a> to return to Users"; } $conn-> close();
  11. Well is this bit of the code not checking the password? :S $userData = mysqli_fetch_array($result); $hash = hash('sha256', $userData['userpassword']."$password"); if($hash != $userData['userpassword']) // Incorrect password. So, redirect to login_form again. :S?
  12. Probably, It's in 4 separate modules because they are the bits at the top of the pages to start the sessions and the form snippet was there just in case I'd cocked up a variable name. So when the password is entered how do I get it to look for the hashed version in the database? They aren't going to enter the encrypted password obviously so how would I match them up as it where? I have found and modified a tutorial on this forum not long after I posted this question actually and it is doing the same thing. I know it's a lot of questions but I've not actually wrote a log in script before - it seems to be another large gap in my university education!
  13. They do have file names sorry, but I don't get that attached to my code to name it There is login.php <?php session_start(); $err = $_GET['e']; ?> login.php body: <form id="form1" name="form1" method="post" action="functions/loginprocess.php"> <table> <tr> </tr> <tr> <td>Username:</td> <td><input type="text" name="username" id="username" /></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password" id="password" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="button" id="button" value="Login" /></td> </tr> </table> </form> index.php <?php session_start(); $l=6; $a="out"; if(isset($_SESSION['username'])) { $l=$_SESSION['username']; $a="in"; } else { header('Location: login.php?e=Login to use the administration functions'); } $err = $_GET['e']; ?> And finally loginprocess.php: <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; $conn = mysqli_connect("Connection String"); $username = mysqli_real_escape_string($conn, $username); $query="SELECT * FROM users WHERE username='$username' AND userpassword='$password'"; $result = mysqli_query($conn, $query); if(mysqli_num_rows($result) == 0) // User not found. So, redirect to login_form again. { $conn->close(); header('Location: ../login.php?e=User not found'); exit(); } $userData = mysqli_fetch_array($result); $hash = hash('sha256', $userData['cmspassword']."$password"); //echo "$hash"; if($hash != $userData['userpassword']) // Incorrect password. So, redirect to login_form again. { $conn->close(); header('Location: ../login.php?e=Incorrect login details'); exit(); } else{ // Redirect to home page after successful login. $_SESSION['username'] = $username; $_SESSION['user'] = $userData['userid']; $_SESSION['sp'] = $userData['cmspassword']; $conn->close(); header('Location: ../index.php'); exit(); } ?>
  14. I need my user to log in to use their "admin panel" functions. I have this bit of html for them to enter their username/password: <form id="form1" name="form1" method="post" action="functions/loginprocess.php"> <table> <tr> </tr> <tr> <td>Username:</td> <td><input type="text" name="username" id="username" /></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password" id="password" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="button" id="button" value="Login" /></td> </tr> </table> </form> This bit of code at the top of the html to start the session: <?php session_start(); $err = $_GET['e']; ?> This bit of code at the top of the index page to redirect to the login screen <?php session_start(); $l=6; $a="out"; if(isset($_SESSION['username'])) { $l=$_SESSION['username']; $a="in"; } else { header('Location: login.php?e=Login to use the administration functions'); } $err = $_GET['e']; ?> And this code to perform the log in functions: <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; $conn = mysqli_connect("Connection String"); $username = mysqli_real_escape_string($conn, $username); $query="SELECT * FROM users WHERE username='$username' AND userpassword='$password'"; $result = mysqli_query($conn, $query); if(mysqli_num_rows($result) == 0) // User not found. So, redirect to login_form again. { $conn->close(); header('Location: ../login.php?e=User not found'); exit(); } $userData = mysqli_fetch_array($result); $hash = hash('sha256', $userData['cmspassword']."$password"); //echo "$hash"; if($hash != $userData['userpassword']) // Incorrect password. So, redirect to login_form again. { $conn->close(); header('Location: ../login.php?e=Incorrect login details'); exit(); } else{ // Redirect to home page after successful login. $_SESSION['username'] = $username; $_SESSION['user'] = $userData['userid']; $_SESSION['sp'] = $userData['cmspassword']; $conn->close(); header('Location: ../index.php'); exit(); } ?> And the database table is called 'users' with the following columns: userid username useremail userpassword cmspassword However, as stated in the title of this post, I appear to be stuck in a loop where whenever I enter the user credentials it just keeps looping round the "user not found" message on line 16. Can anyone help me, I am well and truly stuck on how to get out of this loop? I know I've gone wrong somewhere, just can't see where
  15. Hello, I'm having a bit of a problem with some code of mine. I need to save an image file however I'm not sure where I have gone wrong. So as a bit of background, in my public_html folder I have the 'Add News' file where the user will fill in a form and upload it to the database and a folder called 'news' where the images will be stored... the script to add the article (along with the image) is stored in a folder called functions. Okay so now for the code: This is the form to add the article: <form id="form" action="functions/newsadd.php" method="post"> <table class="input"> <tr><td>News Title</td><td><textarea name="title" cols="80" rows="1"></textarea></td></tr> <tr><td>Author</td><td><textarea name="author" cols="80" rows="1"></textarea></td></tr> <tr><td>Status</td><td><select name="stat"><option>Enabled</option><option>Disabled</option></select></td></tr> <tr><td>Snippet Text</td><td><textarea name="snip" cols="80" rows="6"></textarea></td></tr> <tr><td>News Story</td><td><textarea name="stry" cols="80" rows="15"></textarea></td></tr> <tr><td>Image</td><td><input type='file' name='file'></td></tr> <tr><td><input type="submit" value="submit"/></td></tr> </table> </form> AND this is the code stored in "functions/newsadd.php" <?php $t = $_POST['title']; $a = $_POST['author']; $st = $_POST['stat']; $sn = $_POST['snip']; $s = $_POST['stry']; $conn = mysqli_connect("blah" "blah "blah" "blah") or die ("Could not connect to database"); if(!is_uploaded_file($_FILES['file']['tmp_name'])) { $query = "INSERT INTO news (newstitle,newsauthor,newsdate,newsstatus,newssnippet,newsarticle) VALUES ('$t','$a',CURDATE(),'$st','$sn','$s')"; } 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 news (newstitle,newsauthor,newsdate,newsstatus,newssnippet,newsarticle) VALUES ('$t','$a',CURDATE(),'$st','$sn','$s')"; } else { $finame = $_FILES["file"]["name"]; $result = move_uploaded_file($_FILES['file']['tmp_name'], "../news/$finame"); if ($result == 1) { $query = "INSERT INTO news (newstitle,newsauthor,newsdate,newsstatus,newssnippet,newsarticle,newsimage) VALUES ('$t','$a',CURDATE(),'$st','$sn','$s','$finame')"; } else { $query = "INSERT INTO news (newstitle,newsauthor,newsdate,newsstatus,newssnippet,newsarticle) VALUES ('$t','$a',CURDATE(),'$st','$sn','$s')"; } } } $result = mysqli_query($conn, $query); if($result){ echo "Entered data successfully"; echo "<BR />"; echo "click <a href='sitepath.php'>here</a> to return to News"; } else { echo "Oh No! Something has gone wrong and your article could not be uploaded"; echo "<BR />"; echo "click <a href='http://sitepath.php'>here</a> to return to News"; } mysqli_close($conn); ?> Now I am perfectly able to upload the information in the form into the database, that is fine. My problem is that I am unable to save an image to the server and I'm not sure where I have gone wrong. I know it has something to do with this part of the code: $finame = $_FILES["file"]["name"]; $result = move_uploaded_file($_FILES['file']['tmp_name'], "../news/$finame"); if ($result == 1) { $query = "INSERT INTO news (newstitle,newsauthor,newsdate,newsstatus,newssnippet,newsarticle,newsimage) VALUES ('$t','$a',CURDATE(),'$st','$sn','$s','$finame')"; } I am just unsure on what it is..... Any help would be appreciated, thanks
  16. Okay so I have an update for anyone else who has this problem. I actually have the query working now and pulling the info based on the ID thanks to changing an i to an s. So when the user clicks Edit on the list of news articles it runs this code: function editnews($i) { ini_set('display_errors',1); error_reporting(E_ALL); $conn = mysqli_connect("mysqli connection string"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $enquery = "SELECT * FROM news WHERE newsid='$i'"; $enresult = mysqli_query($conn, $enquery) or trigger_error($enquery . ' - has encountered an error at:<br />'); if ($enresult) { while ($enrow = mysqli_fetch_array($enresult)) { echo " <form enctype='multipart/form-data' action='functions/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['newsstatus'] == "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> "; } } else { echo "Oh noes, an error!"; } } ?> This directs to the HTML page where the form will be displayed with this code (This code is disaplyed at the very top of the document - above the doc type: <?php include_once("functions/newseditform.php"); $s = $_GET['i']; ?> While this little bit of code sits somewhere in the body. <?php editnews($s) ?> -- Thanks for all the help guys!!!
  17. Yes I have included an "i" parameter. When you click on 'Edit' the link in the php is <a href='editnews.php?i=" . $gnrow['newsid'] . "'>Edit</a> So when I click on 'Edit' it should find the newsid and pull that information out but I can't fathom out why which is why I came to the forum. The error message as shown in the post you have linked to didn't actually show me anything on the screen, just a blank page. However, since my last post - the query is now working to some extent. the URL is finding 'News Id' and populating with the correct id number after the .php?i= So it is performing the query just displaying a white screen.
  18. Okay So I have managed to fix the two errors that I was originally having problems with. I now have this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in..... I have updated my code and it now looks like this: function editnews($i) { ini_set('display_errors',1); error_reporting(E_ALL); $conn = mysqli_connect("super duper connection to my DB"); $enquery = "SELECT * FROM news WHERE newsid=$i"; $enresult = mysqli_query($conn, $enquery) or trigger_error($enquery . ' - has encountered an error at:<br />'); if ($enresult) { 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> "; } } else { echo "Oh noes, an error!"; } } The 'trigger_error' code has quite helpfully pointed out a notice. More specifically this notice: Notice: SELECT * FROM news WHERE newsid= - has encountered an error at: ...... in /home/sites/agile-cms.co.uk/public_html/admin/functions/newseditform.php on line 11 I have done a google search on it to no avail. I have changed the query to read: $enquery = "SELECT * FROM news WHERE newsid=1"; SO now when I click 'Edit' no matter what row it will always display the results for the row with id=1 which works quite happily so it must be something to do with the $i but I can't see what. Can someone please point me in the right direction with this?
  19. Good News! I've managed to get rid of the 'undefined index' error by changing this in the 'Edit News' page from this: <?php session_start(); include('functions/newseditform.php'); $i = $_GET['i']; ?> To this: <?php session_start(); include('functions/newseditform.php'); $i = $_GET['newsid']; ?> However if anyone can please help with the second error I would be very appreciative!
  20. Okay so having followed the advice on here the code now looks like this: function editnews($i) { ini_set('display_errors',1); error_reporting(E_ALL); $i = $_GET['newsid']; $conn = mysqli_connect("connection string"); $enquery = "SELECT * FROM news WHERE newsid=$i"; $enresult = mysqli_query($conn, $enquery); if (!mysqli_query($conn, "SELECT * FROM news WHERE newsid=$i")) { echo("Error description: " . mysqli_error($conn)); } 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> "; } } ?> And i now have errors which read: Notice: Undefined index: newsid in pathway on line 9 Error description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1. Now I can't quite understand the second error as line one literally contains <?php Although the first error is also confusing me as well because I am declaring $i as get 'newsid' which is the name of the id field in the news table.....
  21. Sorry it actually reads $enresult = mysqli_query($conn, $enquery); I am not sure why I took it out of this :S
  22. Okay so this is what the code looks like now. function editnews($i) { $i = $_GET['newsid']; //newsid is the name of the unique id field. $conn = mysqli_connect("connection string") or die("could not connect"); $enquery = "SELECT * FROM news WHERE newsid=$i"; $enresult = mysqli_query($enquery); if ($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> "; } else { printf("Errormessage: %s\n", mysqli_error($conn)); } } However I'm still not getting anything, not even an error. I have ran the debugger on my IDE and got nothing, I have uploaded the file to my test url and there is nothing. I have taken $conn out of the variable and put it back in, I have put it in the wrong way round. I have changed the query to say that newsid = 1 so no matter what article I click on to edit it should pull the info from the row where the id is 1. I have also added ini_set('display_errors',1); error_reporting(E_ALL); to the top of the page with no luck.
  23. The thing is I have used this code before in a similar context. It pretty much my go to code. If you look at this one there aren't really any major differences that I can see yet this one works and actually displays the form populated by the database information for the user to edit. function editnews($i) { $conn = mysqli_connect("Connection string where the same functions work"); $enquery = "SELECT * FROM newsitem WHERE niid=$i"; $enresult = mysqli_query($conn, $enquery); while ($enrow = mysqli_fetch_array($enresult)) { echo" <form enctype='multipart/form-data' action='functions/newsedit.php' method='post'> <table> <tr> <td>News Ref:</td> <td>" . $i . "<input type='hidden' name='nid' value='" . $i . "' /><input type='hidden' name='oldim' value='" . $enrow['newsimage'] . "' /></td> </tr> <tr> <td>Author:</td> <td><input type='text' name='auth' value='" . $enrow['newsauthor'] . "' size='100' /></td> </tr> <tr> <td>Title:</td> <td><input type='text' name='tit' value='" . $enrow['newstitle'] . "' size='100' /></td> </tr> <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='cont' rows='20' cols='80'>" . $enrow['newscontent'] . "</textarea></td> </tr> <tr> <td>Keywords:</td> <td><input type='text' name='kw' value='" . $enrow['keywords'] . "' size='100' /></td> </tr> <tr> <td>Current image:</td> <td>" . $enrow['newsimage'] . " - <a href='news/" . $enrow['newsimage'] . "' target='_blank'>View Image</a></td> </tr> <tr> <td colspan='2'><input type='submit' name='submit' value='Edit' /></td> </tr> </table> </form> "; } } I am really at a loss as to why the code in this post does as it is told but when I have modified it to fit this purpose, in the first post, has just decided that it doesn't want to play along, when I have followed the same "template" as it where..... Baffling my brain!!
×
×
  • 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.