Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. What is the output of var_dump($youtube_link);
  2. You only told use about the latter and that is what Barand's INTO SELECT query is for. We can only suggest what you tell us, if you told us about the other fields we would of suggested something different Now that we know this we can move on to a different solution. As you have the book cover, name and pageno as hidden input fields I assume the user is not going to be editting this data? If so then there is no need to submit this. Therefor we do not insert the book name, cover and pageno in your second table. The only value that needs to be inserted is the book id (which I assume is used for assigned the book to the user?). Data should be duplicated across different tables. Data stored in the tables should relate (MySQL is a relational database). So the book id should be used as foreign key You can now use a regular insert query to insert your form data into the second table INSERT INTO table2 (firstname, lastname, address, city, state, zipcode, email, book_id) VALUES ('$firstname', '$lastname', '$address', ... etc, $book_id) On the pages where you are outputting the contents of table2 to get the book name, cover and pagno would you use a JOIN SELECT t2.firstname, t2.lastname, t2.book_id, # select these columns from table 2 t1.name, t1.cover. t1.pageno # select these column from table1 (books) FROM table2 t2 LEFT JOIN table1 t1 USING(book_id) # join the tables where the book id matches in both tables Example > SELECT * FROM table1 +-----------+----------+---------+ | firstname | lastname | book_id | +-----------+----------+---------+ | John | Doe | 1 | | Tom | Wood | NULL | # person does not have a book | Clair | Watts | 2 | | Sam | Taylor | 1 | | John | Doe | 3 | +-----------+----------+---------+ > SELECT * FROM table2 +---------+-----------------------------------+------------+--------+ | book_id | name | cover | pageno | +---------+-----------------------------------+------------+--------+ | 1 | Charlie and the Chocolate Factory | Roald Dahl | 208 | | 2 | James and the Giant Peach | Roald Dahl | 160 | | 3 | The Twits | Roald Dahl | 112 | +---------+-----------------------------------+------------+--------+ > SELECT t1.firstname, t1.lastname, t1.book_id, t2.name, t2.cover, t2.pageno FROM table1 t1 LEFT JOIN table2 t2 USING(book_id) +-----------+----------+---------+-----------------------------------+------------+--------+ | firstname | lastname | book_id | name | cover | pageno | +-----------+----------+---------+-----------------------------------+------------+--------+ | John | Doe | 1 | Charlie and the Chocolate Factory | Roald Dahl | 208 | | Tom | Wood | NULL | NULL | NULL | NULL | # null because person has no book | Clair | Watts | 2 | James and the Giant Peach | Roald Dahl | 160 | | Sam | Taylor | 1 | Charlie and the Chocolate Factory | Roald Dahl | 208 | | John | Doe | 3 | The Twits | Roald Dahl | 112 | +-----------+----------+---------+-----------------------------------+------------+--------+
  3. Not sure but maybe use PHPWord using the Template processing for opening an existing word document and replaced tag blocks in the document with your value? For example in the document you have tag blocks like this ${name}NAME HERE{/$name} Then using the template processing to replace that block with someones name you can use $templateProcessor->setValue('Name', 'John Doe');
  4. That code looks fine to me. What is the issue?
  5. PHP must be calling the cust() function from somewhere, it maybe being called as part of callback, from a function like call_user_func_array When you name the function as Cust use debug_print_backtrace() inside the function. Maybe this help you identify where it is being called from.
  6. Because that function is most likely being treated as a constructor. In OOP (using older PHP 4 sytax, which what your code uses) when a function is named the same as the class it will be called automatically when a new instance of the class is initialized (created eg $customer = new Customer()). So if you rename your class to customer you must rename the cust() function the same. This why this is happening when I click on a customer to edit that doesn't work unless the function is named Customer.
  7. Oh. This is from yesterday? You cannot do math operations with numbers which are formatted. You need to remove the number formatting so its whole number // remove number formatting $lal = str_replace(',', '', $row[0]->nodeValue); // now divide by 2 $lal2 = floatval($lal) / 2; echo $lal2; If you dont remove the formatting PHP will truncate the value before the comma, so only 4 will be divided by 2 this why the result is 2
  8. I get your expected result 2410.246 $lal = 4820.492; $lal2 = $lal/2; echo $lal2; // output 2410.246 Are your sure $lal is what you expect it is? What does var_dump($lal); return?
  9. No you are misunderstanding Barand 1. Your combobox should only be submitting the book id (not the book name). No need for the hidden input fields either. 2. The query Barand gave in this post is what you need to insert the book id, name, cover and pageno into your table. (Needs to be executed as one complete statement, not separately). $posted_id is the variable that contains the book id submitted by your combobox when the form is submitted (looking at your form code this will be $_POST['name'] - altough your should rename your combobox to bookid then use $_POST['bookid']) - this is what Barand meant by subsequent page
  10. $query = mysqli_query($bd,"SELECT ip_add FROM image_ip WHERE ip_add=$ip"); // the line above is my problem and the line below $ip in the query needs to be wrapped in quotes WHERE ip_add='$ip' if($ip !== $query){ You dont want to be comparing the ip address again as you have done that in your query. Also mysqli_query does not return the ip address from the query only the result set. What you want to be doing is checking to see if the query returned a row (a row will be returned if the ip address matches), which you will use mysqli_num_rows if(mysqli_num_rows($query) !== 0) { // query did match ip address } else { // query did not match ip address } Also note ip addresses are rarely persistent. Most ISP's isssue dynamic ip addresses where by the ip address can change at anytime, every hour, day, week, fortnightly, month etc. IP addresses can easily be spoofed too. So you cannot really trust the user ip address.
  11. You should only have the combo box submit the book id. On the page where the form is submitted to. you will query the books table to get the book name, cover and pagno where the book id matches.
  12. You are getting that error due the cartridge return and or newline whitespace characters (\r\n or \n or \r) being included when you read the username from each line in the text file. When you get the username you need to use trim
  13. Yes. PHP cannot act on events happening in the browser. PHP only runs when a (HTTP) request is made. PHP is a server side language. If you want the hidden input fields populated when you select an option from your dropdown menu then you need to use javascript. Also your code will always populate the hidden input fields with last row returned by you query. Can I ask what it is you are trying to?
  14. Because you are not using $capture in your comment_form function. Look at gizmola's code closely.
  15. It seems all td cells have the same class. You are going to need to use a much more complex xpath query using DOMDocument $doc = new DomDocument(); $doc->loadHTMLFile($url); $xpath = new DOMXpath($doc); // this xpath query first finds the <td> cell with class="listado1" and contains <b>TOTAL</b> will then return the contents of the next <td> cell $row = $xpath->query("//td/b[preceding::td[@class='listado1']/b[.='TOTAL']]"); echo $row[0]->nodeValue; Above tested with the following HTML <table> <tr> <td colspan="3" align="right" class="listado1"> <b>whatever here</b> </td> <td align="right" class="listado1"> <b>whatever here</b> </td> </tr> <tr> <tr> <td colspan="3" align="right" class="listado1"> <b>TOTAL</b> </td> <td align="right" class="listado1"> <b>4,890.20</b> " " </td> </tr> <tr> <td colspan="3" align="right" class="listado1"> <b>whatever here</b> </td> <td align="right" class="listado1"> <b>whatever here</b> </td> </tr> </table> Returns 4,890.20
  16. Remove single quotes around $url on this line $html = file_get_html('$url'); Variables in single quotes are not parsed. $html = file_get_html($url); $rows = $html->find('//td[@class="listado1"]'); foreach($rows as $row) { echo $row->plaintext; }
  17. No, (in that pseudo code example) $dns_records is only set when when $_POST['url'] exists and it contains a valid url. If either of those two checks fails then $dns_records wont exist and PHP would produce a undefined variable error message. Before validating whether the user hast entered a url we could check to see if the url provide starts with http:// if does not we would prefix http:// converting it to a url // check this post variable exists if(isset($_POST['url'])) { if(filter_input(INPUT_POST, 'url', FILTER_VALIDATE_URL)) { $url = $_POST['url']; will become // check this post variable exists if (isset($_POST['url'])) { $url = trim($_POST['url']); // if $_POST['url'] does not start with http:// if(substr($url, 0, 7) != 'http://') { // prefix with http:// $url = 'http://' . $url; } // use filter_var to validate if $url contains a valid url if(filter_var($url, FILTER_VALIDATE_URL)) { Shouldn't do. It will fail the url validation check Should still work. The code will first validate the user entered valid url, which http://youtube.com/a is. It will then call parse_url and return the hostname segment which will be youtube.com
  18. When get the contents of the textarea you would use explode on the newline whitespace character to the dates on each line. You would then use foreach to loop over each date converting them using Barands example code <?php // if dates have been submitted if(isset($_POST['dates'])) { // explode on the newline character to get the dates on each line $htmldates = explode("\n", $_POST['dates']); // loop through the dates foreach($htmldates as $htmldate) { // apply trim, to remove any whitespace $htmldate = trim($htmldate); // convert date to new format $dt = DateTime::createFromFormat('d.m.y', $htmldate); echo $dt->format('Y-m-d') . '<br />'; } } ?> <form method="post"> Dates:<br /> <textarea name="dates" cols="30" rows="10"><?php echo (isset($_POST['dates']) ? $_POST['dates'] : ''); ?></textarea><br /> <input type="submit" value="Convert" /> </form>
  19. Are you sure that is the HTML code you have in header.php. Because the HTML in header.php on your site is different (right click > view source code) is this <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-55928631-1', 'auto'); ga('send', 'pageview'); </script> <title>4x4 Submods</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="style.css" rel="stylesheet" type="text/css" /> </head> Right clicking view source on your test.php shows those 18 lines at the very top. Which indicates header.php is being loaded. If it didn't PHP would of outputted an error message
  20. $url= $_POST['url']; if(isset($url)) //did to check if url is there or not. { When checking to see if a user define variable, such as $_POST exists pass it isset. // check this post variable exists if(isset($_POST['url'])) { $_POST['url'] will only exist when you have submitted your form. You only want the code to get the dns record when the form has been submitted. Next problem you are using filter_input incorrectly if(filter_input($url, PHP_URL_HOST)) //did to check if your is valid or not { It requires three arguments, the first is the type of input you are applying the filter to. In your case INPUT_POST. The second value it needs is the input name, in your case url (this means we are filtering $_POST['url']) and the last value being the type of filter you are going to be using which should of been FILTER_VALIDATE_URL (sorry, I gave the incorrect filter in my pseudo code earlier). The above line should be written as if(filter_input(INPUT_POST, 'url', FILTER_VALIDATE_URL)) { $url = $_POST['url']; // $_POST['url'] exists and is a valid url assign to variable. No need for the foreach loop foreach($host as $hostname); // assigned $host as $hostname parse_url($url, PHP_URL_HOST); will only return the hostname from the url. Not an array You would use $host, not $hostname here $dnsinfo= dns_get_record($hostname, DNS_A);
  21. mysqli itself is not deprecated, but certain procedural functions/aliases are, which are listed here. When using mysqli you should be using the object syntax, rather than the procedural functions. For example instead of using mysqli_connect you should be doing $mysqli = new mysqli('localhost', 'user', 'password', 'database'); You are not getting any output because your have your query and looping through the query result inside a function, called RelDay() (defined on line183). However you never appear to be calling this function. In order for the code inside the function to be execute the function must be called.
  22. Who said that? Last I checked it is the mysql_ api that is deprecated not the mysqli_ api Also what is your problem/question? Your post does not make sense to me.
  23. You are calling a function called parse(), not parse_url() As the documentation for parse_url states it expects a url, not a hostname to be passed as the first argument (google.com is a hostname, http://google.com is a url). When calling parse_url with the PHP_URL_HOST component, it will only return the hostname from the url, not an array. You use $host not $host['host'] when outputting the host $url = $_GET['myname']; $host = parse($url, PHP_URL_HOST); print "The host is $host."; If you did not specify a component, then parse_url would of returned an array, $url = $_GET['myname']; $segment = parse($url); // without specifying component, returns an array print "The host is {$segment['host']}.";
  24. Could use either str_pad, sprintf or use a condition if $i less than 10 to prefix $i with a space See if you can implement either of the 3 options above into your code. NOTE: You may need to use rather than the actual space character. As web browsers tend to ignore (white)space characters.
×
×
  • 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.