Jump to content

johnnys

Members
  • Posts

    42
  • Joined

  • Last visited

Everything posted by johnnys

  1. Got it working. I have to rename my model file from adminarea_model.php to simply admin_model.php Not sure why this made a difference though but it's worked
  2. I am quite new to php and the mvc setup, I am developing a library app however starting at the very basics so as not to become overwhelmed! I am trying to do a basic insert to my book table, this is the code I have so far alsong with the error I am presented with. Model (models > adminarea_model.php) adminarea_model.php public function create($title_text) { $title_text = strip_tags($title_text); $sql = "INSERT INTO book (title) VALUES (:title)"; $query = $this->db->prepare($sql); $query->execute(array(':title' => $title_text)); $count = $query->rowCount(); if ($count == 1) { return true; } else { $_SESSION["feedback_negative"][] = FEEDBACK_NOTE_CREATION_FAILED; } return false; } View (views > admin > addBook.php) addBook.php <form method="post" action="<?php echo URL;?>admin/create"> <label>Text of new note: </label><input type="text" name="title" /> <input type="submit" value='Create this note' autocomplete="off" /> </form> Controller (controllers > admin.php) admin.php public function create() { if (isset($_POST['title']) AND !empty($_POST['title'])) { $book_model = $this->loadModel('Admin'); $book_model->create($_POST['title']); } header('location: ' . URL . 'admin/addBook'); } When I am on admin/addBook and I try to submit the form I receive the following error; Fatal error: Call to a member function create() on a non-object in C:\xampp\htdocs\logintest\application\controllers\admin.php on line 43 Any ideas where I am going wrong? Line 43 contains the following $book_model->create($_POST['title']); Thanks J
  3. Good advice @Barand I was hoping for an easier solution however your suggestion makes sense for future amendments. Thanks
  4. I have two tables book and category, book id title author category isbn 1 fun times Joe 1 16161514 (new record) 2 fishing trip Jim Juvenile Science 88771615 (old record) 3 beach hunt Sam 3 81009991 (new record) 4 day out John 3 81009991 (new record) 5 farm fun Jim Classic Kids 88771615 (old record) category id cat_name 1 horror 2 science 3 kids I use the join query below to display a list of all book info, works fine. SELECT b.id, b.title, b.category, b.author, b.isbn, b.publicationYear c.cat_name FROM book AS b INNER JOIN category AS c ON b.category = c.id The problem I am facing is that all some of the books (1000's actually) in the db have been imported from a previous db, and instead of containing an integer for the category they contain a string such as 'General Fiction' or 'Popular Classics' etc. Must I import all of these categories into the 'category' table and assign an integer to them, or is there a way of simply displaying the string that is contained within the 'book' table as it stands? I use the code below to display the html table of results; while($row = $res->fetch_array()) { echo '<tr>'; echo '<td>' . $row['id'] . '</td>'; echo '<td>' . $row['title'] . '</td>'; echo '<td>' . $row['author'] . '</td>'; echo '<td>' . $row['cat_name'] . '</td>'; echo '<td>' . $row['isbn'] . '</td>'; echo '<td>' . $row['publicationYear'] . '</td>'; echo '</tr>'; echo '</tbody>'; }; Still teaching myself php/mysql so I appreciate the patience and thanks in advance.
  5. Thanks @Ch0cu3r and @Barand - perfect
  6. @Barand if you read the question carefully you will see that it's actually different. The post in the MySql forum has been answered. However if you feel this is a double post then feel free to delete it.
  7. I have two tables 'book' and 'category'. They look like the following in phpmyadmin; book id title author category isbn ---- ------- ---------- ---------- ------- 1 Treasure Chest Jim Jones 1 14252637 2 Pirates Boat Sue Smith 2 88447737 3 Adventure Land Harry Jo 3 01918273 4 Winter Week Sam Dill 3 00999337 5 The Twite Roald Dahl Fiction 87873366 category id cat_name ---- ------- 1 Horror 2 Kids 3 Fiction 4 Science Users have the option of adding books into the library via an online form, or via a Google Booka api method (user enters isbn, searches, is presented with book info and then clicks 'add to library', done.). This is handled via ajax. The online form works fine, and successfully adds the book info. However my problem is with the Google Books method, it successfully adds the data to the db however the category column is in text format (i.e 'Juvenile Science' or 'Scary Fiction') as opposed to the manual form which adds categories as 1, 2 or 3 (1 =Horror, 2 = Kids, 3 = Fiction). Is there any way I can add the Google Book category data to my table and convert it to an integer or similar? Not sure what I need to do. Suggestions appreciated! Should I add the Google entries to another table (i.e googleCategory)? My HTML only outputs the numbered category entries and ignored the text format entries. my php $sql = "SELECT b.id, b.title, b.author, b.isbn, b.publicationYear, c.cat_name FROM book AS b INNER JOIN category AS c ON b.category = c.id WHERE status != 'Archive' ORDER BY id DESC LIMIT $startrow, 15 "; $res = $conn->query($sql) or trigger_error($conn->error."[$sql]"); while($row = $res->fetch_array()) { echo '<tbody>'; echo '<tr>'; echo '<td>' . $row['id'] . '</td>'; echo '<td>' . $row['title'] . '</td>'; echo '<td>' . $row['author'] . '</td>'; echo '<td>' . $row['cat_name'] . '</td>'; echo '<td>' . $row['isbn'] . '</td>'; echo '<td>' . $row['publicationYear'] . '</td>'; echo '</tr>'; echo '</tbody>'; }; Apologies if this is all a bit confusing I am very new to php and mysql. Thanks, J
  8. I figured it out I should have had echo '<td>' . $row['cat_name'] . '</td>'; Instead of echo '<td>' . $row['category'] . '</td>'; Thanks again @Ch0cu3r for the excellent answer!
  9. Thanks @Ch0cu3r - I can now see a full table of info however my 'Category' field in the table is completely empty. I'm getting a notice regarding line 104 (marked below). Notice: Undefined index: category in C:\xampp\htdocs\sslib\books.php on line 104 I have provided my complete code below, thanks. $sql = "SELECT b.id, b.title, b.author, b.isbn, b.publicationYear, c.cat_name FROM book AS b INNER JOIN category AS c ON b.category = c.id WHERE status != 'Archive' ORDER BY id DESC LIMIT $startrow, 15 "; $res = $conn->query($sql) or trigger_error($conn->error."[$sql]"); while($row = $res->fetch_array()) { echo '<tbody>'; echo '<tr>'; echo '<td>' . $row['id'] . '</td>'; echo '<td>' . $row['title'] . '</td>'; echo '<td>' . $row['author'] . '</td>'; echo '<td>' . $row['category'] . '</td>'; // <--line 104 echo '<td>' . $row['isbn'] . '</td>'; echo '<td>' . $row['publicationYear'] . '</td>'; echo '</tr>'; echo '</tbody>'; }; Any ideas why?
  10. I am creating a library app for personal development and would like to further my knowledge of MySql. I currently have two tables 'book' and 'category' book id title author category isbn ---- ------- ---------- ---------- ------- 1 Treasure Chest Jim Jones 1 14252637 2 Pirates Boat Sue Smith 2 88447737 3 Adventure Land Harry Jo 3 01918273 4 Winter Week Sam Dill 3 00999337 category id cat_name ---- ------- 1 Horror 2 Kids 3 Fiction 4 Science I am doing a simple search where I want to display all books (select * from book) and I would like to display all the books with their corresponding categories. This works but displays the category number instead of the category name. How can I alter these tables in such a way that the cat_name and category are joined? I tried to run a command in phpmyadmin as below however it returned an error; ALTER TABLE book ADD FOREIGN KEY (category) REFERENCES category(cat_name); error #1452 - Cannot add or update a child row: a foreign key constraint fails (`sslib`.`#sql-1ab4_1dae`, CONSTRAINT `#sql-1ab4_1dae_ibfk_1` FOREIGN KEY (`category`) REFERENCES `category` (`cat_name`)) I have been looking at foreign keys and indexes however I can't seem to make any sense of them. I am quite new to this so any help is much appreciated. Regards, J
  11. Ah figured it out <?php echo '?isbn='.str_replace ('-', '', $row['isbn']); ?>
  12. Firstly I'm sure the answer is simple however due to my inexperience I am unable to figure it out! I am executing a simple query to retrieve all ISBN numbers within my db and display these in a table. In my db some of the ISBN numbers contain hyphens and some don't. I would like to display then in my table without hyphens. I'm grateful of any assistance and advice. I know I can remove all the hyphens from the db by executing a separate query however I'd like to strip them if possibly. My Code; $query = "SELECT * FROM book WHERE status != 'Archive' ORDER BY id"; while($row = mysqli_fetch_array($query)){ ?> <tr> <td><a href="itemView.php<?php echo '?isbn='.$row['isbn']; ?>" </a></td> <td>...</td> <td>...</td> <td>...</td> <td>...</td> </tr> <?php } ?> J
  13. Actually figured it out, pretty simple. I just had to change my code as follows; 'title' : entry.volumeInfo.title
  14. I am retrieving Google Books info in JSON format and displaying it inside a div. I would like to send the contents of this div (name, title, description) to my database using Ajax. Currently only the ISBN field sends because I have it declared as a variable. However my question is, how do I send the other fields (name, title, author). How do I declare these also, I'm not sure what format they need to be in etc. My JS $(document).ready(function() { $('#submit').click(function(ev) { ev.preventDefault(); var isbn = $('#isbn_search').val(); //get isbn direct from input var url='https://www.googleapis.com/books/v1/volumes?q='+isbn; $.getJSON(url,function(data){ $.each(data.items, function(entryIndex, entry){ var html = '<div class="results well">'; html += '<h3>' + entry.volumeInfo.title + '</h3>'; html += '<div class="author">' + entry.volumeInfo.authors + '</div>'; html += '<div class="description">' + entry.volumeInfo.description + '</div>'; }); }); }); }); My Ajax; $.ajax({ type: 'POST', url: 'addIsbnScript.php', data: { 'isbn' : isbn, 'title' : title 'subtitle' : subtitle, 'authors' : authors, 'description' : description }, success: function () { $.growl({ message: " Record added" }); } }); Note, if i manually set the vars like below they all do successfully send to my database, so I know my query is working ok var title = "some text", var author = "some text", Var description = "some text" Thanks in advance for any help, newbie here (incase it wasn't obvious!). J
  15. I am creating a library app (personal dev) and have ran into some trouble. I'm very new to Ajax and Php I have a page named addEntryISBN which shows the results of a user search in a div named #results. I want to post the contents of #results to my database. The contents of #results comes from a page named searchISBN. What is the most effective way of doing this? My code so far is aas follows; addEntryISBN.php $(document).ready(function() { $('form').on('submit', function (e) { e.preventDefault(); $.ajax({ type: 'post', url: 'searchIsbn.php', data: $('form').serialize(), success: function (result) { $('.result').html(result); } }); return true; }); }); <div class="result"</div> searchISBN.php <?php echo '<table class="table">'; echo '<tr>'; echo '<h3>Book Info</h3>'; echo '</tr>'; echo '<tr>'; echo '<td> Title </td>'; echo '<td>' . $title . '</td>'; echo '</tr>'; echo '<tr>'; echo '<td> Page Count </td>'; echo '<td>' . $pageCount . '</td>'; echo '</tr>'; echo '<tr>'; echo '<td> Publish Date </td>'; echo '<td>' . $publishDate . '</td>'; echo '</tr>'; echo '<tr>'; echo '<td> Description </td>'; echo '<td>' . $description . '</td>'; echo '</tr>'; echo '</table>'; echo '<form><input id="add_isbn" method="post" type="submit" value="Add This Book" /></form>'; } ?> I hope this makes sense! Any help is much appreciated. J
  16. Thanks again kicken, That's a great help to me. I was planning on running this as an offline app on each of the client laptops (there being only 3). I completely overlooked that fact that the php won't work unless this app is hosted on a server (which we won't have access to unless we change the IP settings - making the app pointless!). I realise I could install a local server on each laptop but not ideal. Plan B..! Thanks
  17. Thank you kicken, I now have a rough idea of what I should be doing. So, I would require 50 x netsh commands for each of the 50 different network configs. Can I add all these commands in the same batch file, and call them individually within my php? The reason I want to change them is because I work as a network tech, and this involves working in various physical locations/buildings. Each location has a different router/switch and each has it's own network configs. Due to network security, IPs need to be entered static in order to access some of the switch configs. If I could get this working it would be a great help for our team, and I think it would be a nice way to better my understanding of PHP. I basically want to design a single html page, with a search large bar. User enters the location of where they are working, and the IP settings they shoud be using pops up. They then click 'confirm' to set these on their machine. I'd also like a 'reset' button, Do you think this is achievable, or is there a better/more efficient way? Thanks again, J
  18. Hi, I'm not sure if this is possible, however I'm sure somebody will be able to point me in the right direction. Relativley new to php here. I would like to write a small app that will change my IP/Subnet Mask/Gateway depending on a selection made from a dropdown list. I will have a tota; of 50 different IP settings & drop downs (each drop down will represent a different location) I have yet to start writing the app, just on paper so far - can this be done? I have seen examples of batch scripts like the one below that work, would I need to incorporate something like this into my php? netsh int ipv4 set address name="Local Area Connection" source=static address=10.127.86.25 mask=255.255.255.240 gateway=10.127.86.30 This is just a personal project, I'm trying to further my knowledge! Thanks J
  19. Hi Guys, I'm just starting to work with Fabrik & Joomla, and need help with a some custom calculation. Quick question regarding two drop down boxes I am creating a form for past pupils of a school. First drop down box is called 'Year of Leaving' {member_app_year_out} and offers options from '1930' right through to '2014' (lots!). Second drop down box is called 'Membership Type' {member_app_type} and offers two options 'Full Membership £20' and 'Reduced Membership £10'. I want the second drop down box (Membership Type) to be dependant on the selection from the first drop down box. The rule is that 'If you have left the school within the past 7 years, you qualify for a Reduced Membership of £10'. So I want users to select e.g. 2008 and only see 'Reduced Membership', and users who select e.g. 2001 to only see 'Full Membership'. This also needs to update each year. How can I do this? Something like if {member_app_year_out} = '(now)' - 7 Apologies for my lack of programming knowledge, I'm learning. Thanks in advance, J
  20. Thanks for that advice, I was thinking I probably shouldn't make it easy for people to guess! Currently my log file says 2013-10-11 14:34:28 Cron Job - INFO --> Login Failed for: xxxxxxxxxxxx from IP xxx.xxx.xxx.xxx How can I make this more detailed? I was searching alreday, but if anybody can point me in the right direction that would be great.
  21. Hi Guys, I have created an application that has a login page and authenticates users based on Active Directory info. It works fine for some users, however some are complaining of not being able to login. Currently when login fails, I have output 'Login Incorrect, please try again'. This is also sent to a log file which I can access, I want to be able to troubleshoot this better, what would be the best way of doing this? All new to me im afraid! Would it be an idea to create a custom message saying USERNAME incorrect and PASSWORD incorrect, narrowing it down for user? Thanks in advance, J
  22. thanks ill try that now, again I'm still teaching myself this language so don't be surprised if it's incorrect.
  23. Thanks for the tips guys, apologies for the code, still teaching myself This is the actual code below; - I hope it makes sense if(isset($_REQUEST["submit"])){ try{ $make=f::getValue("make"); $model=f::getValue("model"); $qub_id=f::getValue("inventory_number"); $mac=f::getValue("mac_address"); $arrSymbols=array(":","-"," ",";","."); $mac=substr(strtoupper(str_replace($arrSymbols, "", $mac)),0,12); $dnsname=f::getValue("dnsname"); $sql="INSERT INTO ip_requests (make,model,qub_id,mac,dnsname,) VALUES ('".$make."', '".$model."', '".$qub_id."','".$mac."','".$dnsname."')"; $id = mysql_insert_id(); echo $id; $objLog->logDebug('New Request: '.$sql); $stmt = DB::exec($sql); if(sendQf22Email($make, $model, $qub_id, $mac,$dnsname,)){ $boolMailSent = true; }else{ $boolMailSent = false; } $objDisplay->getHeader($pagetitle); echo "<h1>Request Submitted - Order Number Below</h1> "; echo $id; $objDisplay->getFooter(); exit; }catch(PDOException $e){ $objLog->logError('Error inserting: '.$sql); echo $e->getMessage(); } } Thanks in advance, J
  24. Hi, Firstly apologies I'm still new to php. I have a form that submits data to my DB successfully (name, dept etc..). What I want to do is, once the form is submitted a message will appear saying 'Thank you - your order number is xxx' (xxx being the auto-increment id) I have been researching the mysql_insert_id but I can't seem to get it working, currently it returns '0' My current code $sql="INSERT INTO ip_requests (make,model,qub_id,mac,dnsname,) VALUES ('".$make."', '".$model."', '".$qub_id."','".$mac."','".$dnsname."') $id = mysql_insert_id(); echo $id; $objLog->logDebug('New Request: '.$sql); $stmt = DB::exec($sql); Then It displays this (well a zero!) echo "<h1>Request Submitted - Order Number below</h1> "; echo $id; Any help is much appreciated, J
×
×
  • 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.