Jump to content

Raz3rt

Members
  • Posts

    16
  • Joined

  • Last visited

Raz3rt's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. As i found searching over the internet : "You do not use relative paths in a loop body. Of course this always produces the same (i.e. the absolute) result." What you can try is put your path of your XML values into an variable first and then INSERT INTO your sql with these variables i.e something like that (maybe you will find allot on the internet (xpath absolute value xml). $player_id = $player->xpath("./player_id/value"); Ik also ran into this : http://php.net/manual/en/domxpath.query.php It looks like this is a better (finer way) to do these xml gets!
  2. Maybe an example wil help you out? function myFunction($myVariable = array()){ //$myVariable represends the array you have created when calling the function (Note: You can also do this with all values into a different $variable but learn working with arrays that means less code <=> faster! $Firstvariable = $myVariable[0]; // So blue wil be added to $Firstvariable $Secondvariable = $myVariable[1]; // green wil be added to $Secondvariable $Thirthvariable = $myVariable[2]; // yellow wil be added to $Secondvariable $Fourthvariable = $myVariable[3]; // white wil be added to $Secondvariable echo "my favorite colors are $Firstvariable and $Secondvariable also $Thirthvariable and especially $Fourthvariable"; } myFunction(array("blue", "green", "yellow", "white")); // outputs "my favorite colors are blue and green also yellow and especially white" There are however much better ways to do this. Try working with for and foreach loops to iterate (run over/through) an array. But maybe when you just started to work you better write the code this way! Good luck! Took me 2 years to almost fully understand the code...
  3. I'm sorry to have bothered you for such a stupid fault... It really was just that! Thank you for the help anyway and hope to come with better questions in the future!
  4. here you have all of the code : session_start(); if (!isset($_SESSION['k_name']) && !isset($_SESSION['c_firstname'])){ header('Location: index.php?pagina=login'); } if ($_SERVER['REQUEST_METHOD'] == 'POST'){ require('incl/functions.php'); $date = date("Y-m-d"); $datestrip = str_replace("-", "", $date); if(!empty($_POST['discipline']) && !empty($_POST['article'])) { $article = $_POST['article']; $serialnr = $_POST['serialnumber']; $error = $_POST['errorinput']; $discipline = $_POST['discipline']; $issue = $_POST['issue']; $new_rma_query = "INSERT INTO rma (r_datum, r_klantid, r_contactid) VALUES (:rdatum, :rklantid, :rcontactid)"; $new_rma_stmt = $dbh->prepare($new_rma_query); $new_rma_stmt->execute(array( ':rdatum'=>$date, ':rklantid'=>$_SESSION['k_id'], ':rcontactid'=>$_SESSION['c_id'] )); $lastid = $dbh->lastInsertId(); $new_rma_det_query = "INSERT INTO rma_detail (rd_rma_id, rd_artikel_code, rd_rma_aard, rd_serienr, rd_foutomschr, rd_typerma) VALUES (:rmaid, :articlecode, :rmaaard, :serialnr, :error, :typerma)"; $new_rma_det_stmt = $dbh->prepare($new_rma_det_query); $new_rma_det_stmt->execute(array( ':rmaid'=>$lastid, ':articlecode'=>$article, ':rmaaard'=>$discipline, ':serialnr'=>$serialnr, ':error'=>$error, ':typerma'=>$issue )); $lastdetid = $dbh->lastInsertId(); if(!isset($_SESSION['rmamr'])){ $rmanr = $datestrip; $rmanr .= $lastdetid; $_SESSION['rmanr'] = $rmanr; } else { $rmanr = $_SESSION['rmanr']; } $up_rma_stmt = $dbh->prepare("UPDATE rma SET r_nr = '$rmanr' WHERE r_id = ?"); $up_rma_stmt->bindParam(1, $lastid); $up_rma_stmt->execute(); header('Location: index.php?pagina=rma-new'); } } and under my form i made this to fill in a table that HAVE to contain the submitted rma's with the same number and that is why it is important to use the same number if the person stays on the same page <?php if (!empty($_SESSION['rmanr'])){ $get_rma_rows = $dbh->prepare("SELECT rma_detail.rd_artikel_code, rma_detail.rd_rma_aard, rma_detail.rd_serienr, rma_detail.rd_typerma FROM rma LEFT JOIN rma_detail ON rma_detail.rd_rma_id=rma.r_id WHERE r_nr = ?"); $get_rma_rows->bindparam(1, $_SESSION['rmanr']); $get_rma_rows->execute(); while($get_rma_rows_row = $get_rma_rows->fetch(PDO::FETCH_ASSOC)){ ?> <td><?php echo $get_rma_rows_row['rd_artikel_code']; ?></td> <td><?php echo $get_rma_rows_row['rd_rma_aard']; ?></td> <td><?php echo $get_rma_rows_row['rd_serienr']; ?></td> <td><?php echo $get_rma_rows_row['rd_typerma']; ?></td> <?php } }?>
  5. Yes i started with session_start() and the reason why i did it that way in my date string is because i use $date to input with the "-" into my database and after that i replace the "-" with nothing to make the beginning of my id
  6. Well i have a session['rmanr'] a have set after a submit containing the date and unique id. I have to be able to do multiple submits on that same form but if they submit multiple times the same rmanr have to be used... I tried the following: $date = date("Y-m-d"); $datestrip = str_replace("-", "", $date); $lastdetid = $dbh->lastInsertId(); if(!isset($_SESSION['rmamr'])){ $rmanr = $datestrip; $rmanr .= $lastdetid; $_SESSION['rmanr'] = $rmanr; } else { $rmanr = $_SESSION['rmanr']; } $uprmastmt = $dbh->prepare("UPDATE rma SET r_nr = '$rmanr' WHERE r_id = ?"); $uprmastmt->bindParam(1, $lastid); $uprmastmt->execute(); But i keep getting a new rmanr every time i submit... Could it be that my form submit reset my SESSION?
  7. Edit: I just tried it on an other demo host and there it works! So no problem with the code... it's a pitty it doesn't support changing the headers
  8. Hello, thank you for the answers. Here is my full code copy pasted fram my project (it's in Dutch language, sorry for that!) if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if (!empty($_POST['email'])) { $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING); $firstname = filter_input(INPUT_POST, 'firstname', FILTER_SANITIZE_STRING); $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); $info = filter_input(INPUT_POST, 'info', FILTER_SANITIZE_STRING); $message = '<html><head>'; $message .= '<title>Vraag vanaf de website</title>'; $message .= '<style type="text/css">body {background-color: #ffffff; font-family: verdana;}hr {color: #333;}div {width: 800px; margin: 25px auto;}h1 {color: #FFC421; font-size: 17px;}p {color: 2a2a2a; font-size: 15px;}</style>'; $message .= '</head>'; $message .= '<body>'; $message .= '<div>'; $message .= '<p><img src="imgs/tsc-logo.png"/></p>'; $message .= '<hr />'; $message .= '<h2 style="color: #FFC421;">Klant heeft een vraag gesteld via de website</h2>'; $message .= '<br />'; $message .= '<table style="width:800px">'; $message .= '<tr><th style="width:250px"><h1>Gegevens klant:</h1></th><td></td></tr>'; $message .= '<tr><th>Naam:</th><td>' . $name . '</td></tr>'; $message .= '<tr><th>Voornaam:</th><td>' . $firstname . '</td></tr>'; $message .= '<tr><th>E-mail:</th><td>' . $email . '</td></tr>'; $message .= '<tr><th>Bericht:</th><td>' . $info . '</td></tr>'; $message .= '</table>'; $message .= '</div>'; $message .= '</body></html>'; $to = 'someone@telenet.be'; $subject = 'Vraag vanop de website'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html;charset=UTF-8' . "\r\n"; $headers .= 'From: ' . $email . "\r\n"; if (mail($to, $subject, $message, $headers)){ $_SESSION['email'] = $email; header ('Location: index.php?pagina=send'); } else { header ('Location: index.php?pagina=404'); } } } Could it be a problem with the host where the website is hosted?
  9. I have a strange problem with my headers in my mail function. This is how it looks like in my code: $to = 'someone@email.com'; $subject = 'Question from website'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html;charset=UTF-8' . "\r\n"; $headers .= 'From: ' . $email . "\r\n"; When i send this i got the following message in my mailbox: Content-type: text/html;charset=UTF-8 From: web@somecompany.com Message-Id: <20140620142808.93D11A147@apache11.hostbasket.com> Date: Fri, 20 Jun 2014 16:28:08 +0200 (CEST) <html><head><title>Question from web</title><style type="text/css">body {background-color: #ffffff; font-family: verdana;}hr {color: #333;}div {width: 800px; margin: 25px auto;}h1 {color: #FFC421; font-size: 17px;}p {color: 2a2a2a; font-size: 15px;}</style></head><body><div><p><img src="imgs/tsc-logo.png"/></p><hr /><h2 style="color: #FFC421;">This customer asked a question</h2><br /><table style="width:800px"><tr><th style="width:250px"><h1>Customer:</h1></th><td></td></tr><tr><th>Name:</th><td>testname</td></tr><tr><th>Firstname:</th><td>testfirstname</td></tr><tr><th>E-mail:</th><td>testperson@company.be</td></tr><tr><th>Bericht:</th><td>This is a test</td></tr></table></div></body></html> I have allready found that the space between "Content-type" and "From" is not normal that indicates that a rule between MIME and Content-type is also present. But in my code there isn't any rule... How can this be possible? Thanks for the help!
  10. Well thank you for the answer! @ginerjm: I thought that allready but i think it cannot do any harm to do it that way? It's just how do you call it a habit to write it this way @Jacques1: Yes indeed the CSV is actually in UCS-2 format so there is my problem! I changed it using Notepad++ now i got a whole other issue but one that i can solve i think just by looking at it. (Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '00-SBN2' for key 'a_code'') Thanks for the help i glad i've learned something!
  11. Hello, I am trying to import a CSV file into an existing mysql table but it doesn't seem to work well. Here is how my mysql is looking like: 1 a_id int(11) AUTO_INCREMENT 2 a_lobecoid int(7) 3 a_code varchar(30) utf8_general_ci 4 a_omschint varchar(60) utf8_general_ci 5 a_beveiligingniv int(5) 6 a_type varchar(5) utf8_general_ci 7 a_assortiment int(5) 8 a_discipline varchar(30) utf8_general_ci 9 a_brutoprijs varchar(50) utf8_general_ci 10 a_status varchar(5) utf8_general_ci 11 a_levcode varchar(10) utf8_general_ci 12 a_omschr_nl varchar(60) utf8_general_ci 13 a_omschr_fr varchar(60) utf8_general_ci these are some lines from my CSV file 16158|-H|Factory installed heater|10|S|400|CCTV|45.0|E| 1829|Factory installed heater|Factory installed heater 16159|-IR|Factory installed IR LED ring|10|S|400|CCTV|50.0|E| 1829|Factory installed IR LED ring|Factory installed IR LED ring 9001|00-SBN2|Smoke box niet geaspireerd,230VAC|10|S|267|BRAND|1587.03|D| 642|Smoke box niet geaspireerd,230VAC|Smoke box pas aspiré,230VCA 9003|00-TP1|Telescopische verlengstok voor Smoke box,2,4-4,6m|10|S|267|BRAND|644.09000000000003|D| 642|Telescopische verlengstok voor Smoke box,2,4-4,6m|Rallonge téléscopique pour Smoke box,2,4-4,6m 9004|00-TP2|Telescopische verlengstok voor Smoke box,2,4-9,2m|10|S|267|BRAND|944.64999999999998|D| 642|Telescopische verlengstok voor Smoke box,2,4-9,2m|Rallonge téléscopique pour Smoke box,2,4-9,2m 12161|001-0081|Thermistor probe,rood, high temp. 0-+150°C|10|S|52|INBRAAK|136.91|D| 1731|Thermistor probe,rood, high temp. 0-+150°C|Sonde température,rouge,high temp. 0-+150°C Here you have the code for the import: $upload_article_query = "LOAD DATA INFILE 'ARTIKELS.CSV' INTO TABLE artikelen FIELDS TERMINATED BY '|' LINES TERMINATED BY '\\r\\n' (a_lobecoid, a_code, a_omschint, a_beveiligingniv, a_type, a_assortiment, a_discipline, a_brutoprijs, a_status, a_levcode, a_omschr_nl, a_omschr_fr)"; $upload_article_stmt = $dbh->prepare($upload_article_query); $upload_article_stmt->execute(); If i use the code then in the MYSQL table the first line is filled in but where the second line has to start it just writes it into the last column and doesn't start a new line. Also if i edit that first line it shows a lot of "?" (questionmarks) into a window symbol. Anyone has an idea what i am doing wrong? In attachment some printscreens of my table after the insert. Apologies for the Dutch language. Thanks in advance
  12. I'm sorry i didn't want to be unclear! Well maybe it is better to show my whole code so you got a better idea of what i would like to have? Anyway here you have the code: 1. The select: $selectrmadetail = $dbh->prepare ("SELECT rd_rma_nr, rd_artikel_code, rd_serienr, rd_ontvangenklant, rd_onder_waarborg, rd_omr_rep, rd_teruggestuurdklant, rd_afgehandelklant FROM rma_detail LEFT JOIN rma ON rma_detail.rd_rma_id=rma.r_id LEFT JOIN klanten ON rma.r_klantid=klanten.k_id WHERE k_id = ?"); $selectrmadetail->bindParam(1, $_SESSION['k_id']); $selectrmadetail->execute(); 2. Publish it <?php foreach ($selectrmadetail as $selectrmadetailrow){ foreach ($selectrmadetailrow as $k => $v){ //var_dump($selectrmadetailrow); echo "<td>$v</td>" } } ?> So now when i execute this i got 3 problems 1. I want to have all of the rows nicely on the screen (row per row) 2. Now i have all of the value's 2 times on my screen. When i do var_dump i got this: array(16) { ["rd_rma_nr"]=> string(9) "201405022" [0]=> string(9) "201405022" ["rd_artikel_code"]=> string(7) "34-CXN3" [1]=> string(7) "34-CXN3" ["rd_serienr"]=> string(13) "5411284116133" [2]=> string(13) "5411284116133" ["rd_ontvangenklant"]=> string(1) "1" [3]=> string(1) "1" ["rd_onder_waarborg"]=> NULL [4]=> NULL ["rd_omr_rep"]=> NULL [5]=> NULL ["rd_teruggestuurdklant"]=> NULL [6]=> NULL ["rd_afgehandelklant"]=> NULL [7]=> NULL } array(16) { ["rd_rma_nr"]=> string(9) "201405022" [0]=> string(9) "201405022" ["rd_artikel_code"]=> string(7) "34-CXN3" [1]=> string(7) "34-CXN3" ["rd_serienr"]=> string(13) "5411284116133" [2]=> string(13) "5411284116133" ["rd_ontvangenklant"]=> string(1) "1" [3]=> string(1) "1" ["rd_onder_waarborg"]=> NULL [4]=> NULL ["rd_omr_rep"]=> NULL [5]=> NULL ["rd_teruggestuurdklant"]=> NULL [6]=> NULL ["rd_afgehandelklant"]=> NULL [7]=> NULL } 3. I want the rd_rma_nr to have a link wrapped arround it so when i click on it i can navigate to a detail page where in the header the rd_rma_number is send with (index.php?page=rma-detail&id=201405022). All that is possible with a WHILE loop exept in a while loop i didn't knew what to do to change the value 1 to "YES". Now you where saying i could better use a foreach so my first question isn't really an issue anymore. But now i could use some help because this will be the first time i am doing a fetch with a foreach.
  13. Whow, i dont know why i didn't know that before! The only thing i see now is that the foreach does the same as a fethall() so i have every value 2 times in the array ... How can i solve this? Sorry for all the questions but i am still learning.
  14. Hi, In my code i am fetching row per row out of my database through ->fetch(PDO::FETCH_ASSOC) this fetch have i put in a WHILE loop to fetch all the rows, one at a time while($select_rma_row = $select_rma_detail->fetch(PDO::FETCH_ASSOC)){ In my array $select_rma_row there are a lot of value's that are (int) 1 and i really want to echo them as "YES" (1 = YES) What is the best way to change every (int) 1 to "YES" in that array? also is there a whay i can call every $key inside that array? Like you do with a foreach i.e. : if $select_rma_row[$key] == 1 { $select_rma_row[$key] == "YES"; } Thank you!
  15. Thanks IanA for you reply! As i remember it is not nessesary to specify the date type, i never did it before though. After a long search i've manage to find my "stupid" fold i have made. My problem only appears when the foreach wanted to loop through a select from my form & my first rule in the select was: <option value="$nbsp;" selected></option>. As you may notice the value is a space so the person cannot make a wrong entry. Changing the to 0 fixed the problem. Sorry i had to bother for such a small thing.
×
×
  • 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.