Jump to content

dbk

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dbk's Achievements

Member

Member (2/5)

0

Reputation

  1. Well, you can catch the country_id with the $_GET['country_id'] and put it into a variable. Then you can use it in the query to get the wanted data! Hope this is what your asking for!
  2. Thanks Pikachu2000! Your absolutely right, I have to prevent injections with the stripslashes and mysql_real_escape_string (the ones I know). The ALTER TABLE is used because users will be deleted and new made, and with ALTER I kind of reset the primary key to start from the highest key number. In that way I try to prevent to big "holes" in the sequence of primary key. The application is mostly for "in house" use, but the plan is to make it accessible from the web later on!
  3. Hi guys I've been working on learning php for a month now and I'm very surprised with the progress . How I'm find my self standing at a crossroad - should I try understand how a framework works to separate php from html or .. should I just try to organise my code as much as possible?? To see how I structure my code here is an example of a application to my own little architectural company: <?php require_once '..\functions\func_access_db.php'; require_once '..\functions\func_doctype.php'; require_once '..\functions\functions.php'; //Get required data from url $action = $_GET['action']; $form_action = $_GET['form_action']; $user_id = $_GET['user_id']; //Get data from database if exists switch ($action) { case "user_edit": case "user_call": //Find user_id if no user is selected if ($user_id == "") { $user_db = "SELECT * FROM user ORDER BY user_title"; $user_result = mysql_query($user_db) or die("Invalid query: " . mysql_error()); $row = mysql_fetch_array($user_result); $user_id = $row['user_id']; } $usersql = "SELECT * FROM user WHERE user_id = $user_id"; $user_result = mysql_query($usersql) or die("Invalid query: " . mysql_error()); $row = mysql_fetch_array($user_result); $user_name = $row['user_name']; $existing_user_password = $row['user_password']; $user_title = $row['user_title']; $user_first_names = $row['user_first_names']; $user_surname = $row['user_surname']; $user_initials = $row['user_initials']; $user_direct_phone = $row['user_direct_phone']; $user_cellphone = $row['user_cellphone']; $user_mail = $row['user_mail']; $user_permissions = $row['user_permissions']; break; case "user_add": $user_name = ""; $user_password = ""; $user_title = ""; $user_first_names = ""; $user_surname = ""; $user_initials = ""; $user_direct_phone = ""; $user_cellphone = ""; $user_mail = ""; $user_permissions = ""; break; } //Evaluate form and handle data if($form_action == "commit"){ //Get form data $user_name = $_POST['user_name']; $user_password = $_POST['user_password']; $user_title = $_POST['user_title']; $user_first_names = ucwords(strtolower($_POST['user_first_names'])); $user_surname = ucwords(strtolower($_POST['user_surname'])); $user_initials = strtoupper($_POST['user_initials']);//convert alle letters to uppercast $user_direct_phone = $_POST['user_direct_phone']; $user_cellphone = $_POST['user_cellphone']; $user_mail = $_POST['user_mail']; $user_permissions = $_POST['user_permissions']; $new_user_password = $_POST['new_user_password']; $confirm_new_user_password = $_POST['confirm_new_user_password']; //eveluate user_name if (($user_name == "") OR ((strlen($user_name)) < 3)){ $user_name_error = "Brugernavnet skal være på mindst 3 tegn!"; } elseif((strlen($user_name)) >= 3){ // //Check if user_name is stored in the database // //Use this query if action == user_add if($action == "user_add"){ $check_user_name = "SELECT user_name FROM user"; } //Use this query if action == user_edit if($action == "user_edit"){ $check_user_name = "SELECT user_name FROM user WHERE user_id!=$user_id"; } $search_result = mysql_query($check_user_name); //Evaluate user_name $temp_array = array(); while ($user_row = mysql_fetch_array($search_result)) { $temp_array[] = $user_row['user_name']; } $search = in_array($user_name, $temp_array); if ($search == 1){ $user_name_error = "Brugernavnet findes allerede i databasen!"; } }//end evaluate user_name // //eveluate user_password // //use this evaluation user_password if action == user_add if ($action == "user_add"){ if (($user_password == "") OR ((strlen($user_password)) < 4)){ $user_password_error = "Password skal være på mindst 4 tegn!"; } } //use this evaluation user_password if action == user_edit if ($action == "user_edit"){ if (!empty($new_user_password)){ if (((strlen($new_user_password)) < 4)){ $new_user_password_error = "Password skal være på mindst 4 tegn!"; } if ($confirm_new_user_password != $new_user_password){ $user_password_error = "De indtastede password skal være ens!"; } } } //eveluate user_title if ($user_title == ""){ $user_title_error = "Brugeren skal have en titel!"; } //eveluate user_names if (($user_first_names == "") OR ((strlen($user_first_names)) < 2)){ $user_first_names_error = "Fornavn(e) skal være på mindst 2 tegn!"; } //eveluate user_surname if (($user_surname == "") OR ((strlen($user_surname)) < 2)){ $user_surname_error = "Efternavn skal være på mindst 2 tegn!"; } //eveluate user_initials if (($user_initials == "") OR ((strlen($user_initials)) < 2)){ $user_initials_error = "Initialer skal være på mindst 2 tegn!"; } //eveluate user_direct_phone if exitst if(!empty($user_direct_phone)){ if ((!is_numeric($user_direct_phone)) OR ((strlen($user_direct_phone)) != ) { $user_direct_phone_error = "Direkte nummer skal være på 8 tal!"; } } //eveluate user_cellphone if ((!is_numeric($user_cellphone)) OR ((strlen($user_cellphone)) != ){ $user_cellphone_error = "Mobil nummer skal være på 8 tal!"; } //eveluate user_mail if (eval_mail($user_mail)){ $user_mail_error = "Ikke en gyldig mailadresse!"; } // //start database handeling if no error is set // if(!isset($user_name_error) && !isset($user_password_error) && !isset($user_title_error) && !isset($user_first_names_error) && !isset($user_surname_error) && !isset($user_initials_error) && !isset($user_direct_phone_error) && !isset($user_cellphone_error) && !isset($user_mail_error) && !isset($new_user_password_error)) { // //use this query if a new user is added if($action == "user_add"){ $order_user_id = "ALTER TABLE user AUTO_INCREMENT = 1"; mysql_query($order_user_id); $sql = "INSERT INTO user (user_name, user_password, user_title, user_first_names, user_surname, user_initials, user_direct_phone, user_cellphone, user_mail, user_permissions) VALUES ('" . $user_name . "', '" . $encrypt_user_password = md5($user_password) . "', '" . $user_title . "', '" . $user_first_names . "', '" . $user_surname . "', '" . $user_initials . "', '" . $user_direct_phone . "', '" . $user_cellphone . "', '" . $user_mail . "', '" . $user_permissions . "')"; } // //use this query if a user is edited if($action == "user_edit"){ //if a new password is submitted //the new password gets encrypted and passed to new variable if(!empty($new_user_password)){ $user_password = md5($new_user_password); } else { $user_password = $existing_user_password; } $sql = "UPDATE user SET user_name = '$user_name', user_password = '$user_password', user_title = '$user_title', user_first_names = '$user_first_names', user_surname = '$user_surname', user_initials = '$user_initials', user_direct_phone = '$user_direct_phone', user_cellphone = '$user_cellphone', user_mail = '$user_mail', user_permissions = '$user_permissions' WHERE user_id = '$user_id'"; } // //check if query is set and not empty and sent query to database if (isset($sql) && !empty($sql)) { mysql_query($sql) or die("Invalid query: " . mysql_error()); //get user_id from last query if action == user_add if($action == "user_add") { $user_id = mysql_insert_id(); } ?> <html> <head> <script type="text/javascript"> window.onload = function() { // Reload the parent window window.top.location.href = "users.php?action=user_call&user_id=<?php echo $user_id; ?>"; } </script> </head> </html> <?php } } } ?> <!-- Print data to screen --> <?php echo $doctype; ?> <html> <head> <title>user call</title> <link rel="stylesheet" type="text/css" media="screen" href="../css/main_css.css"> </head> <body> <div id="framedocs"> <?php if($action != "user_call") { ?> <form action="<?php $_SERVER['PHP_SELF']?>?action=<?php echo $action; ?>&form_action=commit&user_id=<?php echo $user_id; ?>" method="post"> <?php } ?> <fieldset> <legend><a class="h1">BRUGEROPLYSNINGER</a></legend> <table cellspacing="0" cellpadding="3"> <tr> <td class="fade" width="35%">Titel:</td> <td width="35%"><?php if($action != "user_call"){ ?> <input class="required" type="text" name="user_title" value="<?php echo $user_title; ?>"> <?php } else {echo $user_title;} ?> </td> <td class="fade" width="20%" align="right">Initialer:</td> <td width="10%"><?php if($action != "user_call"){ ?> <input class="required" type="text" name="user_initials" value="<?php echo $user_initials; ?>"> <?php } else {echo $user_initials;} ?> </td> </tr> <?php //error if exists if(isset($user_title_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_title_error; ?></td> </tr> <?php } ?> <?php //error if exists if(isset($user_initials_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_initials_error; ?></td> </tr> <?php } ?> <tr> <td class="fade" width="35%">Fornavn(e):</td> <td width="65%" colspan="3"><?php if($action != "user_call"){ ?> <input class="required" type="text" name="user_first_names" value="<?php echo $user_first_names; ?>"> <?php } else {echo $user_first_names;} ?> </td> </tr> <?php //error if exists if(isset($user_first_names_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_first_names_error; ?></td> </tr> <?php } ?> <tr> <td class="fade" width="35%">Efternavn:</td> <td width="65%" colspan="3"><?php if($action != "user_call"){ ?> <input class="required" type="text" name="user_surname" value="<?php echo $user_surname; ?>"> <?php } else {echo $user_surname;} ?> </td> </tr> <?php //error if exists if(isset($user_surname_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_surname_error; ?></td> </tr> <?php } ?> <tr> <td class="fade" width="35%">Mobil nummer:</td> <td width="65%" colspan="3"><?php if($action != "user_call"){ ?> <input class="required" type="text" name="user_cellphone" value="<?php echo $user_cellphone; ?>"> <?php } else {echo $user_cellphone;} ?> </td> </tr> <?php //error if exists if(isset($user_cellphone_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_cellphone_error; ?></td> </tr> <?php } ?> <tr> <td class="fade" width="35%">Direkte nummer:</td> <td width="65%" colspan="3"><?php if($action != "user_call"){ ?> <input type="text" name="user_direct_phone" value="<?php echo $user_direct_phone; ?>"> <?php } else {echo $user_direct_phone;} ?> </td> </tr> <?php //error if exists if(isset($user_direct_phone_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_direct_phone_error; ?></td> </tr> <?php } ?> <tr> <td class="fade" width="35%">Mail:</td> <td width="65%" colspan="3"><?php if($action != "user_call"){ ?> <input class="required" type="text" name="user_mail" value="<?php echo $user_mail; ?>"> <?php } else {echo $user_mail;} ?> </td> </tr> <?php //error if exists if(isset($user_mail_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_mail_error; ?></td> </tr> <?php } ?> <tr> <td class="fade" width="35%">Brugernavn:</td> <td width="65%" colspan="3"><?php if($action != "user_call"){ ?> <input class="required" type="text" name="user_name" value="<?php echo $user_name; ?>"> <?php } else {echo $user_name;} ?> </td> </tr> <?php //error if exists if(isset($user_name_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_name_error; ?></td> </tr> <?php } ?> <?php if($action == "user_add"){ ?> <tr> <td class="fade" width="35%">Adgangskode:</td> <td width="65%" colspan="3"> <input class="required" type="text" name="user_password" value="<?php echo $user_password; ?>"> </td> </tr> <?php } ?> <?php if($action == "user_edit"){ ?> <tr> <td class="fade" width="35%">Ny adgangskode:</td> <td width="65%" colspan="3"> <input type="text" name="new_user_password" value="<?php echo $new_user_password; ?>"> </td> </tr> <?php //error if exists if(isset($new_user_password_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $new_user_password_error; ?></td> </tr> <?php } ?> <tr> <td class="fade" width="35%">Bekræft adgangskode:</td> <td width="65%" colspan="3"> <input type="text" name="confirm_new_user_password" value=""> </td> </tr> <?php } ?> <?php //error if exists if(isset($user_password_error)){ ?> <tr> <td width="35%"></td> <td colspan="3" class="error"><?php echo $user_password_error; ?></td> </tr> <?php } ?> <tr> <td class="fade" width="35%">Rettigheder:</td> <td width="65%" colspan="3"> <?php echo $user_permissions; ?></td> </tr> </table> </fieldset> <table cellspacing="0" cellpadding="3"> <tr> <td align="right"> <?php if($action == "user_call"){ ?> <a class="fade">rediger</a> <a href="<?php $_SERVER['PHP_SELF']?>?action=user_edit&user_id=<?php echo $user_id; ?>"> <img src="../icon/pencil.png" title="rediger" alt="" border="0"/></a> <a class="fade">slet</a> <a href="user_delete.php?action=user_delete&user_id=<?php echo $user_id; ?>" target="_top"> <img src="../icon/delete.png" title="slet bruger" alt="" border="0"/></a> <?php } if($action != "user_call") { ?> <a class="fade">accepter</a> <input type="image" title="accepter" src="../icon/accept.png" style="width:16px; background-color: transparent"> <a class="fade">anuller</a> <a href="<?php $_SERVER['PHP_SELF']?>?action=user_call&user_id=<?php echo $user_id; ?>"> <img src="../icon/cross.png" title="anuller" alt="" border="0"/></a> <?php }?> </td> </tr> </table> <?php if($action != "user_call") { ?></form><?php } ?> </div> </body> </html> I will probably never become a programmer, but I like it and like to learn it probably (with limits of cause), and therefore your advice would be most welcome! Thanks!
  4. Hi I've been struggling with adding verdana font to tcpdf - but without any luck!! Has anyone been able to convert a truetype font with the ttf2ufm.exe file?? Just can't seem to make it work!! :'(
  5. Thanks for the reply! I simply gave up on making the query I wanted! Instead I made a array to contain the one query I could use with the in_array function to check wich results from the other query I would make pass! Hope it made sens!! anyway.. it works!!
  6. Hi fenway I can't figure out where I'm missing parents? Is it to subtract one query from the other or.. is it in one of the queryes??? Each query gives the result I want, but I just want the 2. query result subtracted from the first query! I've been searching nearly all googles result to find a solution!! :'(
  7. Hi guys I'm trying to make a mysql search function in my php page. The query looks like this and works fine: $search_contact_sql = "SELECT * FROM contact INNER JOIN project_contact USING (contact_id) WHERE (contact_title LIKE '%$search_contact%' OR contact_first_names LIKE '%$search_contact%' OR contact_surname LIKE '%$search_contact%' OR contact_company_relation LIKE '%$search_contact%' OR contact_company_section LIKE '%$search_contact%' OR contact_adress LIKE '%$search_contact%' OR contact_postal_number LIKE '%$search_contact%' OR contact_city LIKE '%$search_contact%' OR contact_phone LIKE '%$search_contact%' OR contact_fax LIKE '%$search_contact%' OR contact_cellphone LIKE '%$search_contact%' OR contact_private_phone LIKE '%$search_contact%' OR contact_mail LIKE '%$search_contact%' OR contact_notes LIKE '%$search_contact%') AND project_id != $project_id ORDER BY contact_title"; But... I want to exclude the result of this query in the search result: $search_contact_sql = "SELECT * FROM contact JOIN project_contact USING (contact_id) WHERE project_id = $project_id ORDER BY contact_title"; Is that somehow possible???
  8. dbk

    Help with JOIN

    Hi mjdamato I just found out that the error was in some other code (php). The query returns the correct data! As I once was told - ALLWAYS TRY THE QUERY IN CMD!!! I'm very sorry for wasting your time!!
  9. dbk

    Help with JOIN

    Hi mjdamato Sorry for my english.. What I want is to filter using the "project_id" ! each contact can be linked to many projects and thats why I made the "project_contact" table that only contain a primary key with autoincrease, the contact_id and the project_id. Hope it makes sense! By the way.. I don't get any error using: SELECT * FROM contact JOIN project_contact USING (contact_id) WHERE project_id = 1301 The filter just don't work!!
  10. dbk

    Help with JOIN

    Hi I need some help with a query that don't work: SELECT * FROM contact JOIN project_contact USING (contact_id) WHERE project_id = 1301 I have two tables - "contact" and "project_contact". "contact" contains some information about people. "project_contact" contains information about wich projects a contact is linked to. Both tables has a column "contact_id". But the "project_contact" table has also a column "project_id" that I want to sort the contacts with!!! If you understand the explanation what am I doing wrong?
  11. Beautiful kenrbnsn!! My hero Thanks!
  12. Hi I can't seem to get the dateformat the way I want! From mysql the dateformat is yyyy-mm-dd, but I would like to display it dd-mm-yyyy in my page! How do I do this? And is it possible to display it like dd.mm.yyyy? This is a part of the code: $project_db = "SELECT * FROM $db_$db_tbl_project WHERE project_id = '" . $_SESSION['project_number'] . "' "; $project_result = mysql_query($project_db) or die("Invalid query: " . mysql_error()); $project_row = mysql_fetch_array($project_result); $project_start_date = $project_row['project_start_date'];
  13. Thanks Mchl! Any good links to some tutorials on this subject?
  14. Hi I need som help to joining two tables! Table cases and table contacts When I make a new case I want to connect some contacts by using the contact_id in the contacts table. The contact_id should be saved in a colum case_contacts in the cases table. The big problem I can't figure out is that the colum case_contacts in the cases table have to contain some contact_id's - How do I do that?? Is it possible to seperate the contact_id's some how, like with a ; ?? And how could the query look?
  15. Yes.. Thank You!! That's ofcourse the way to do it! (Why didn't I think of the include if validation passes ) Perfect!
×
×
  • 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.