Jump to content

fbm

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Everything posted by fbm

  1. cheers huggiebear got there through trial and error lol
  2. solved i was selecting my clients table on the invoice list rather than my invoice table changed $result to $result = mysql_query("SELECT * FROM invoices WHERE `id` = '".$_SESSION['id']."'"); now pulls invoices from the DB which have the ID = to the client session ID
  3. would i need some form of Javascript to reload the page after selecting a client from the drop down box? I'm thinking about the second option having the first page set to select the client then pass it to the next page where the invoice is then created. If it is possible to do it on 1 pge with a reload happenign after a client is selected that would be better but dont want to get involved with Javascript just yet Cheers
  4. Hi, I have 2 tables in my DB [clients] [invoices] Clients table has an ID field set to primary key so each client has a unique ID. On invoice table i pass the unique ID by selecting the client from a drop down list when creating the invoice. The ID is added to the DB correclty. I'm now trying to pull out data which is relevent to the ID stored in the session. Clients login ID is added to session. At the moment my code just pulls out all teh invoices listed and not ID specific rows My code is <?php session_start();?> <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Clients Invoices</h1> <div id="client_list_table"> <table width="860" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="id">ID</td> <td class="company">Company</td> <td class="contact">Contact Name</td> <td class="email">Email</td> <td class="phone">Phone</td> <td class="actions">Actions</td> </tr> <?php $result = mysql_query("SELECT * FROM invoices ORDER BY id ASC"); while($row = mysql_fetch_array($result)) { echo "<tr>\n"; echo "<td class='row_id'>".$row['id']."</td>\n"; echo "<td class='row'>".$row['date']."</td>\n"; echo "<td class='row'>".$row['invoice_number']."</td>\n"; echo "<td class='row'>".$row['title']."</td>\n"; echo "<td class='row'>".$row['value']."</td>\n"; echo "<td class='row'>".$row['pdf']."</td>\n"; echo "<td class='row'>".$row['status']."</td>\n"; echo "</tr>\n"; } ?> </table> </div> </div> </div> <?php include "includes/footer.php"; ?> Any ideas?
  5. hi, I have a DB with 2 tables [clients] [invoices] My clients table is populated with a bunch of data and the primary key is set to an ID field. Now im trying to create the page where i create an invoice but getting a bit stuck. I want the invoice im creating to know which client ID to be stored against so i added a drop down list option in my form which allows me to select my client and it works great the invoice is added using the below code and the ID is pulled from the drop down selection. My question is how do i get more info out of the drop down list, i want the ID and Company name to be pulled from the client table whilst im creating an invoice. here is the code i use for creating an invoice <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Invoices</h1> <form name="form" method="POST" action="process_add_invoice.php"> <div id="add_client_box"> <h1> </h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Select : </td> <td class="right"> <select name="id" style="vertical-align:middle; width:180px;"> <?php $result = mysql_query("SELECT * FROM clients ORDER BY company ASC"); while($row = mysql_fetch_array($result)) { echo "<option value=".$row['id'].">".$row['company']."</option>"; } ?> </select> </td> </tr> <tr> <td height="34" class="left"> </td> <td class="right"> </td> </tr> <tr> <td class="left">date : </td> <td class="right"><input class="field" type="text" name="date" /></td> </tr> </table> </div> <div id="add_client_box"> <h1> </h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">company : </td> <td class="right"> </td> </tr> <tr> <td class="left">invoice number : </td> <td class="right"><input class="field" type="text" name="invoice_number" /></td> </tr> <tr> <td class="left">title : </td> <td class="right"><input class="field" type="text" name="title" /></td> </tr> <tr> <td class="left">value : </td> <td class="right"><input class="field" type="text" name="value" /></td> </tr> <tr> <td class="left">status : </td> <td class="right"><input class="field" type="text" name="status" /></td> </tr> </table> </div> <div id="add_client_box"> <h1> </h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">pdf : </td> <td class="right"><input class="field" type="text" name="pdf" /></td> </tr> <tr> <td class="left"> </td> <td class="right"> </td> </tr> <tr> <td class="left"> </td> <td class="right"> </td> </tr> </table> </div> <div id="add_account_box"><input class="button" value="ADD INVOICE" type="submit" /></div> </form> </div> </div> <?php include "includes/footer.php"; ?> and here is the code which processes the invoice <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <?php $id = $_POST['id']; $date = $_POST['date']; $invoice_number = $_POST['invoice_number']; $title = $_POST['title']; $value = $_POST['value']; $pdf = $_POST['pdf']; $status = $_POST['status']; $query = "INSERT INTO `invoices`(`id`,`date`,`invoice_number`,`title`,`value`,`pdf`,`status`)VALUES('".$id."','".$date."','".$invoice_number."','".$title."','".$value."','".$pdf."','".$status."')"; mysql_query($query) or die(mysql_error()); echo "<center>"; echo "<h1>Adding Invoice to Database, Please Wait</h1>"; echo "<META HTTP-EQUIV=Refresh CONTENT='5; URL=invoices.php'> "; echo "</center>"; ?> </div> <?php include "includes/footer.php"; ?> any ideas how to add more data to the form without having multiple drop downs. all i need is the drop down to support both ID and Company name so that these 2 fields are passed into the invoice table. Cheers
  6. SOLVED : i changed the $_GET to $_SESSION in teh query and it gets the correct details based on teh ID which is passed in the session. Woohooo!!!! thank you very much
  7. now trying to get the full client info from teh DB on teh landing page. Here is the full landing page <?php session_start();?> <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Welcome back <?php echo $_SESSION['username'];?></h1> <?php $result = mysql_query("SELECT * FROM clients WHERE `id` = '".$_GET['id']."'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { ?> <div id="add_client_box"> <h1>Account Details</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Company : </td> <td class="right"><?php echo $row['company'];?></td> </tr> <tr> <td class="left">Account No : </td> <td class="right"><?php echo $row['account_number'];?></td> </tr> <tr> <td class="left">Website : </td> <td class="right"><?php echo $row['website'];?></td> </tr> </table> </div> <div id="add_client_box"> <h1>Company Address</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Building Number : </td> <td class="right"><?php echo $row['building_number'];?></td> </tr> <tr> <td class="left">Street : </td> <td class="right"><?php echo $row['street'];?></td> </tr> <tr> <td class="left">City : </td> <td class="right"><?php echo $row['city'];?></td> </tr> <tr> <td class="left">County : </td> <td class="right"><?php echo $row['county'];?></td> </tr> <tr> <td class="left">Post Code : </td> <td class="right"><?php echo $row['post_code'];?></td> </tr> </table> </div> <div id="add_client_box"> <h1>Primary Contact</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Primary Contact : </td> <td class="right"><?php echo $row['primary_contact'];?></td> </tr> <tr> <td class="left">Primary Email : </td> <td class="right"><?php echo $row['primary_email'];?></td> </tr> <tr> <td class="left">Primary Phone : </td> <td class="right"><?php echo $row['primary_phone'];?></td> </tr> </table> </div> <div id="add_client_box"> <h1>Billing Contact</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Billing Contact : </td> <td class="right"><?php echo $row['billing_contact'];?></td> </tr> <tr> <td class="left">Billing Email : </td> <td class="right"><?php echo $row['billing_email'];?></td> </tr> <tr> <td class="left">Billing Phone : </td> <td class="right"><?php echo $row['billing_phone'];?></td> </tr> </table> </div> <div id="add_client_box"> <h1>User Credentials</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Username : </td> <td class="right"><?php echo $row['username'];?></td> </tr> <tr> <td class="left">Password : </td> <td class="right"><?php echo $row['password'];?></td> </tr> </table> </div> <div id="add_account_box"></div> </div> </div> <?php } ?> </div> </div> <?php include "includes/footer.php"; ?> I now get an undefined index again which i assume is because query is wrong or i need to add the ID from teh session somewhere on teh page so it knows what the ID is in the query. Any ideas? Cheers again
  8. cool thanks, now works and shows the Username on login now how do i add other Client data to the session such as the client id?
  9. hi, I am working on a login page for my system. I have a DB all setup which holds client details including the Username and Password. I have this on my login page <?php session_start();?> <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Welcome</h1> <form action="processlogin.php" method="POST"> <table cellspacing="10"> <tr><td><p>User ID:</td><td><input class="box" type="text" name="username"></td></tr> <tr><td><p>Password:</td><td><input class="box" type="password" name="password"></td></tr> <tr><td colspan="2"><input type="submit" value="Login"></td></tr> </table> </form> </div> </div> <?php include "includes/footer.php"; ?> header includes the config.php file and DB connection is all workign fine I then have this on my processlogin.php page <?php $username = $_POST["username"]; $password = $_POST["password"]; include "includes/config.php"; $sql="SELECT * FROM clients WHERE username='$username' and password='$password'"; $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ echo "<p>The username or password you have entered is incorrect!</p>"; echo "<META HTTP-EQUIV=Refresh CONTENT='4; URL=index.php'> "; exit(); } else{ $_SESSION["username"] = $username; echo "<div align='center'><h5>Logging In</h5></div>"; echo "<META HTTP-EQUIV=Refresh CONTENT='2; URL=client_home.php'> "; } ?> i then have this on my landing page after log in is processed <?php session_start();?> <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Welcome back <?php echo $_SESSION['username'];?></h1> </div> </div> <?php include "includes/footer.php"; ?> after logging in i get the following error Notice: Undefined index: username in C:\wamp\www\fbmcrm\clients\client_home.php on line 6 i think the username is not being passed properly in the session. I am trying to acheive a landing page which simply generates a welcome message saying welcome back (username) to start with and the username is specific to the login details used. Any ideas?
  10. Cheers dragon for confirming my DB structure and plans. I have created my client directory and index.php page with login form. Can anyone offer any guidance on how to process the login for and create the session? Cheers Rick
  11. Hi, I have been creating a few posts today but i hope by me creating new ones with new relevent titles is the correct way of doing things. Once one post has been solved i mark it as solved and post my thank you comments. I then move onto another area of my project which has a new issue and really requires a new post title which is relevent to the new question so being new here i hope creating a new relevent post is the best way to do things. Now onto my next question So i am developing my first PHP application and basing it around a CRM application which i plan to use with my clients. I want it to be simple but expandable as my first project i don't want to attempt anything hugely out of my reach as a begginer to PHP. I have my first steps completed - I have a DB with a table of clients info. - I have the ability to add, edit, delete my clients from an admin area. Next Step is to understand how to handle client specific information I want to create an invoice section on my backend. This will be a simple form which i should be able to manage with my current skills. The form will consist of, client dropdown list to select a client, then the following fields, [date], [invoice number], [invoice title], [invoice value], [status] and a browse button to upload a PDF copy of the invoice which i create from another system external to this CRM. So my questions 1. Creating the invoice table the right way? the end result will be an admin area where i login into and add invoices and a front end where my clients can login to view invoices relevent to them. 2. How do i tie the invoice data to the client account. In my client table i have setup the primary key as the ID and i am assuming by selecting my client from a drop down list when creating the invoice i will be able to add the clients ID into the invoice table making the client ID still the primary key. Does this sound like the best way to do it? everythign client specific should be linked to the client ID. 3. So once i complete the backend invoice tables and have the ebility to add invoices i will be moving onto the front end for the first tests. I have read that sessions are the best way to handle users logging in. After logging in i will want to show invoices relevent to there ID. Does my above plans cover this ability or should i change my plans now to avoid any problems? 4. I would like to create my first front end test which will be a login form and after logging in it just lists the clients info which is populated in the clients table relevent to the login details used. Where is a good place to start with this? i am thinkign by lookign at the frotn end approach now it may help me understand the process better and allow me to cater for future plans in the DB structure. Cheers
  12. Another outstanding and fast response which has solved the issue. woohoo view, edit and delete buttons now all works wonderfully. Hmm now the easy bit is all sorted need to move onto more advanced stuff, yikes!!! Thanks for the fix guys. Anyone use Skype and interested in working with me on a small CRM system. I really want to build the system myself and learn alot abotu PHP but small questions liek above will always pop up which it would be good to have a contact available to me who is interested in challenges. The CRM system is not a commercial product. I am building it for my own customers and am hoping to offer it as an open source system once its all finished.
  13. Hi Again I am now trying to edit data already stored in my DB. My data is populated on a page called client_list.php and code looks like this <table width="860" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="id">ID</td> <td class="company">Company</td> <td class="contact">Contact Name</td> <td class="email">Email</td> <td class="phone">Phone</td> <td class="actions">Actions</td> </tr> <?php $result = mysql_query("SELECT * FROM clients ORDER BY id ASC"); while($row = mysql_fetch_array($result)) { echo "<tr>\n"; echo "<td class='row_id'>".$row['id']."</td>\n"; echo "<td class='row'>".$row['company']."</td>\n"; echo "<td class='row'>".$row['primary_contact']."</td>\n"; echo "<td class='row'><a href='mailto:".$row['primary_email']."'>".$row['primary_email']."</a></td>\n"; echo "<td class='row'>".$row['primary_phone']."</td>\n"; echo "<td class='row'>\n"; echo "<ul>\n"; echo "<li class='view'><a href='clients_view.php?id=".$row['id']."'><span>view</span></a></li>\n"; echo "<li class='edit'><a href='clients_edit.php?id=".$row['id']."'><span>edit</span></a></li>\n"; echo "<li class='delete'><a href='process_delete_client.php?id=".$row['id']."'><span>delete</span></a></li>\n"; echo "</ul>\n"; echo "</td>\n"; echo "</tr>\n"; } ?> </table> Using the edit button which you can see at the bottom of the above code it links me to http://localhost/fbmcrm/manage/clients_edit.php?id=4 clients_edit.php looks like this <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Add Clients</h1> <?php $result = mysql_query("SELECT * FROM clients WHERE `id` = '".$_GET['id']."'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { ?> <form name="form" method="POST" action="process_edit_client.php"> <div id="add_client_box"> <h1>Account Details</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Company : </td> <td class="right"><input class="field" type="text" name="company" value="<?php echo $row['company'];?>" /></td> </tr> <tr> <td class="left">Account No : </td> <td class="right"><input class="field" type="text" name="account_number" value="<?php echo $row['account_number'];?>"/></td> </tr> <tr> <td class="left">Website : </td> <td class="right"><input class="field" type="text" name="website" value="<?php echo $row['website'];?>" /></td> </tr> </table> </div> <div id="add_client_box"> <h1>Company Address</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Building Number : </td> <td class="right"><input class="field" type="text" name="building_number" value="<?php echo $row['building_number'];?>" /></td> </tr> <tr> <td class="left">Street : </td> <td class="right"><input class="field" type="text" name="street" value="<?php echo $row['street'];?>" /></td> </tr> <tr> <td class="left">City : </td> <td class="right"><input class="field" type="text" name="city" value="<?php echo $row['city'];?>" /></td> </tr> <tr> <td class="left">County : </td> <td class="right"><input class="field" type="text" name="county" value="<?php echo $row['county'];?>" /></td> </tr> <tr> <td class="left">Post Code : </td> <td class="right"><input class="field" type="text" name="post_code" value="<?php echo $row['post_code'];?>" /></td> </tr> </table> </div> <div id="add_client_box"> <h1>Primary Contact</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Primary Contact : </td> <td class="right"><input class="field" type="text" name="primary_contact" value="<?php echo $row['primary_contact'];?>" /></td> </tr> <tr> <td class="left">Primary Email : </td> <td class="right"><input class="field" type="text" name="primary_email" value="<?php echo $row['primary_email'];?>" /></td> </tr> <tr> <td class="left">Primary Phone : </td> <td class="right"><input class="field" type="text" name="primary_phone" value="<?php echo $row['primary_phone'];?>" /></td> </tr> </table> </div> <div id="add_client_box"> <h1>Billing Contact</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Billing Contact : </td> <td class="right"><input class="field" type="text" name="billing_contact" value="<?php echo $row['billing_contact'];?>" /></td> </tr> <tr> <td class="left">Billing Email : </td> <td class="right"><input class="field" type="text" name="billing_email" value="<?php echo $row['billing_email'];?>" /></td> </tr> <tr> <td class="left">Billing Phone : </td> <td class="right"><input class="field" type="text" name="billing_phone" value="<?php echo $row['billing_phone'];?>" /></td> </tr> </table> </div> <div id="add_client_box"> <h1>User Credentials</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Username : </td> <td class="right"><input class="field" type="text" name="username" value="<?php echo $row['username'];?>" /></td> </tr> <tr> <td class="left">Password : </td> <td class="right"><input class="field" type="text" name="password" value="<?php echo $row['password'];?>" /></td> </tr> </table> </div> <div id="add_account_box"><input class="button" value="UPDATE" type="submit" /></div> </form> </div> </div> <?php include "includes/footer.php"; ?> I basically copied the form i use to add a client but grabbed the ID and give the form fields the value set to populate the form. the form action is set to go too process_edit_client.php and this page contains <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <?php $id = $_GET['id']; $company = $_POST['company']; $account_number = $_POST['account_number']; $website = $_POST['website']; $building_number = $_POST['building_number']; $street = $_POST['street']; $city = $_POST['city']; $county = $_POST['county']; $post_code = $_POST['post_code']; $primary_contact = $_POST['primary_contact']; $primary_email = $_POST['primary_email']; $primary_phone = $_POST['primary_phone']; $billing_contact = $_POST['billing_contact']; $billing_email = $_POST['billing_email']; $billing_phone = $_POST['billing_phone']; $username = $_POST['username']; $password = $_POST['password']; $query = "UPDATE `clients` SET `company` = '$company', `account_number` = '$account_number', `website` = '$website', `building_number` = '$building_number', `street` = '$street', `city` = '$city', `county` = '$county', `post_code` = '$post_code', `primary_contact` = '$primary_contact', `primary_email` = '$primary_email', `primary_phone` = '$primary_phone', `billing_contact` = '$billing_contact', `billing_email` = '$billing_email', `billing_phone` = '$billing_phone', `username` = '$username', `password` = '$password' WHERE `id` = '$id'"; mysql_query($query) or die(mysql_error()); } echo "<center>"; echo "<h1>Updating Client Details, Please Wait</h1>"; echo "<META HTTP-EQUIV=Refresh CONTENT='5; URL=clients_list.php'> "; echo "</center>"; ?> </div> <?php include "includes/footer.php"; ?> So now when i click the edit button from my table list of clients i get a parse error Parse error: parse error in C:\wamp\www\fbmcrm\manage\clients_edit.php on line 107 Line 107 was the include footer line but when i remove this the line number just goes to the previous line so not sure where i'm going wrong.
  14. thanks guys, now working Onto the edit and view pages now
  15. Hi, I am trying to pass an ID from one page to another but getting into problems. I have a page which generates a table of all my clients i have added to the DB <?php $result = mysql_query("SELECT * FROM clients ORDER BY id ASC"); while($row = mysql_fetch_array($result)) { echo "<tr>\n"; echo "<td class='row_id'>".$row['id']."</td>\n"; echo "<td class='row'>".$row['company']."</td>\n"; echo "<td class='row'>".$row['primary_contact']."</td>\n"; echo "<td class='row'><a href='mailto:".$row['primary_email']."'>".$row['primary_email']."</a></td>\n"; echo "<td class='row'>".$row['primary_phone']."</td>\n"; echo "<td class='row'>\n"; echo "<ul>\n"; echo "<li class='view'><a href='clients_view.php&id=".$row['id']."'><span>view</span></a></li>\n"; echo "<li class='edit'><a href='clients_edit.php&id=".$row['id']."'><span>edit</span></a></li>\n"; echo "<li class='delete'><a href='process_delete_client&id=".$row['id']."'><span>delete</span></a></li>\n"; echo "</ul>\n"; echo "</td>\n"; echo "</tr>\n"; } ?> At the bottom of this code there is 3 links, view, edit, delete. I want to use these links to link to a new page and pass the Row ID to the next page. With the code above my link appears as this in HTML http://localhost/fbmcrm/manage/process_delete_client&id=2 i have also tried it with .php before the $id= but get the same problem. I have a page called process_delete_client.php which contains this <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <?php mysql_query("DELETE FROM clients WHERE id='".$_GET['id']."'")or die(mysql_error()); echo "<div align='center'>"; echo "Client sucessfully removed from the database"; echo "<META HTTP-EQUIV=Refresh CONTENT='5; URL=clients_list.php'> "; echo "</div>"; ?> </div> </div> <?php include "includes/footer.php"; ?> But when i click the links in my client list table i get error page not found because the URL has the $id= on the end. How do i pass the ID to the next page for processing? Cheers Rick
  16. thanks rich, here is the code which is generating the pagination links echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; or the entire script looks like this <?php // database connection info $conn = mysql_connect('localhost','dbusername','dbpass') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('dbname',$conn) or trigger_error("SQL", E_USER_ERROR); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM clients"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 2; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT client_id, client_name FROM clients LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['client_id'] . " : " . $list['client_name'] . "<br />"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?>
  17. Hi I am building my first system with PHP and MySQL. The system is going to help me manage my clients and projects. I have read teh pagination guide found here http://www.phpfreaks.com/tutorial/basic-pagination and the data is being being populated but i am getting problems because of my page title/URL's My system is built in the below structure index.php includes/ pages/ images/ css/ index.php looks like this <?php include "includes/config.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo "$sitetitle";?></title> <link href="css/master.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrap"> <div id="header"><img src="images/banner_1.jpg" width="900" height="130" alt="Fine Box Media - CRM" /></div> <div id="menu"><?php include "pages/main_menu.php"; ?></div> <div id="page_content"> <?php if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = "home"; } include "pages/".$page.".php"; ?> </div> </div> </body> </html> includes/config.php looks like this <?php //DB settings and connection $dbhost = "localhost"; $dbname = "#######"; $dbuser = "########"; $dbpass = "########"; $db = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db("$dbname",$db); ?> <?php //Admin site Settings $sitetitle = "Fine Box Media - CRM"; ?> So my config.php file handles the DB connection as it is included at the top of every page and then within index.php i use this to include my menu <?php include "pages/main_menu.php"; ?> main_menu.php is this <ul> <li><a href="?page=home">home</a></li> <li><a href="?page=clients">clients</a></li> <li><a href="?page=invoices">invoices</a></li> <li><a href="?page=projects">projects</a></li> <li><a href="?page=support">support</a></li> </ul> and finnally i call each page from the page directory with this <?php if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = "home"; } include "pages/".$page.".php"; ?> So my URL ends up like this when i am on home page for example http://localhost/index.php?page=home Sorry for such a long description of my code but i thought it would be best to show you what i have so far in order to get the best help. So now for the questions. 1. Is my code a common way of doing things? I am questioning the way i have learnt to link to other pages as my page URL is not very friendly. 2. SEO friendly URL's is it possible with my chosen method to make SEO friendly URL's such as http://localhost/home 3. Because of my page URL's the pagination work i have done from the tutorial does not work, the first page of results is populated but then the next and previous buttons have URL's like this http://localhost/index.php?currentpage=2 when in fact the code is not just on the index.php page it is on this URL http://localhost/index.php?page=client_list Sorry very long winded way of explaining but hopefully i have given good info for you guys to offer any advice. Thanks in advance.
  18. Hi, First few days with PHP have gone ok with some small speed bumps along my way. I have some code which outputs a list of customer information, the code which generates this looks like this: <?php $result = mysql_query("SELECT * FROM clients ORDER BY client_name ASC"); while($row = mysql_fetch_array($result)) { echo "<tr style='padding:0px 0px 0px 10px';>\n"; echo "<td id='cl_row'><p>".$row['client_name']."</p></td>\n"; echo "<td id='cl_row'><p>".$row['client_email']."</p></td>\n"; echo "<td id='cl_row'><p>".$row['client_phone']."</p></td>\n"; echo "<td style='text-align:center;' height='35'><div id='button_view'><a alt='view' href='?page=process_view_client&id=".$row['client_id']."'><i>view</i></a></div><div id='button_edit'><a href='?page=process_edit_client&id=".$row['client_id']."'><i>edit</i></a></div><div id='button_delete'><a href='?page=process_delete_client&id=".$row['client_id']."'><i>delete</i></a></div></td>\n"; echo "</tr>\n"; } ?> Maybe a bit messy but im still learning It generates this <tr style='padding:0px 0px 0px 10px';> <td id='cl_row'><p>Mr Google</p></td> <td id='cl_row'><p>support@google.com</p></td> <td id='cl_row'><p>01232545444</p></td> <td style='text-align:center;' height='35'><div id='button_view'><a alt='view' href='?page=process_view_client&id=10'><i>view</i></a></div><div id='button_edit'><a href='?page=process_edit_client&id=10'><i>edit</i></a></div><div id='button_delete'><a href='?page=process_delete_client&id=10'><i>delete</i></a></div></td> </tr> And looks good in browsers so i'm happy with it so far. Any pointers on making my code cleaner would be appreciated but my main question is how to paginate my results. I want to display a maximum of 10 rows on a page and use pagination to view the rest of the rows. Any Advice? Cheers
  19. WOW 3 fast responses. I checked over my code and all was lookign good against your comments so i checked my DB and silly me mispelt the DB name in PMA so corrected that and all workign fine now As for the comments about the form action beign correct or not, I am using a variable for my page links and the action i had in my code does post correctly not sure how it all works lol just getting code from tutorials and guides on teh web and putting it all together Thanks guys, working now. How do i changed the forum post to solved? im new here
  20. Hi I am trying to submit some very simple data to my DB but it returns an error saying no DB selected. my submit page is simple <form name="form" method="POST" action="?page=processclient"> <input name="client_name" type="text" value="client name" /> <input name="client_email" type="text" value="client email" /> <input name="add" type="submit"/> </form> it gets passed to processclient.php which looks like this <?php include "includes/config.php"; $client_name = $_POST['client_name']; $client_email = $_POST['client_email']; $query = "INSERT INTO `clients`(`client_name`,`client_email`)VALUES('".$client_name."','".$client_email."')"; mysql_query($query) or die(mysql_error()); echo "<center>"; echo "Please Wait ... Client being added"; echo "<META HTTP-EQUIV=Refresh CONTENT='5; URL=?page=manage'> "; echo "</center>"; ?> and my config file looks like this <?php $dbhost = "localhost"; $dbname = "hidden"; $dbuser = "hidden"; $dbpass = "hidden"; //connect to MySQL database $db = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db("$dbname",$db); ?> I have removed my DB login details, i'm sure i get connected to the DB as i don't get an error saying cant connect. I'm new to PHP but have a few years HTML/CSS knowledge so be easy in your response if its something sillly Any ideas? Cheers
  21. Hi, Ill try to keep this short and sweet. I'm new to PHP but have 3 years programming experience with HTML/CSS. I have become reliant on PHP programmers to develop any dynamic aspects to my websites and have decided to take the plunge into PHP myself in order to offer a better service to my clients direct from myself. I have worked with many open source systems such as wordpress, drupal, oscommerce ect so i have some understanding of PHP. I'd go as far as understanding the basic syntax. The biggest thing i have written my self in PHP is a small newsletter sign up form which stores the emails submitted in a MySQL DB and then i created a page in which my client could view the emails in a list. The code for this is probably not the best or cleanest way and i am now dedicating the next 4 weeks of my time to learning some of the crucial parts of PHP. My goals are big but i need to start small so firstly a few of my end goal targets are G1. A bespoke CMS which i can maintain and expand on myself as my knowledge improves. G2. A bespoke Client Area which allows my clients to login to my site and view invoices or submit a support ticket. These are my 2 main goals but i have broken them down into bite size chunks for me to learn step by step and pull them all together at the end to create my first dynamic system. 1. DB connection, is below the correct way stored in includes/config.php file? Example : <?php $dbhost = "localhost"; $dbname = "dbname"; $dbuser = "dbuser"; $dbpass = "dbpass"; $db = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db("$dbname",$db); ?> 2. DB structure, i need to plan my DB table structure here, any helpful guides or advice in doing this this the correct way? 3. Create the admin area which will allow me to add simple text data using forms to start with no WYSIWYG editors yet Any guides or advice on where to start with using an admin area to import data. 4. Secure the admin area, now would be a good time to secure my admin area so need to know how to secure the admin area with a Username and Password. Further down the line i would look at multiple users with different permissions but to start with just a simple login form to secure my admin area. Again any advice or guides on where to start with this. 5. So now i have a DB i can connect too. I have a secure admin page which allows me to add simple data into the DB, now its time to pull that data out into a page readable to visitors. any advice or guides on pulling the data back out? I think that should do me for now, i don't want to try running before i can walk Thank you for reading my post. I have looked at many guides and read many tutorials but at some point during the guides i have read things start to fall apart so i want to learn the basics above first and move forward from there. All the best Rick
×
×
  • 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.