-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Weird trigger_error is an internal php function, php -l does not flag up any such error here for me. . Strange it flagged the error on line 39. But you used that function on lines 8 and 20 previously I'm guessing there is some weird whitespace character used in the indentation which is causing the function name to not be recognized. Does the error persist if you remove the indentation before calling the function and/or retyping the function name?
-
Yes. Look using empty as the condition for the if. Although a better alternative would be to modify your query so it does not return values which are empty.
-
So you want us to do your homework assignment for you? Sorry we don't do that here. If you are getting any errors then post them here along with your code and we will be happy to help.
-
Passing $_POST to htmlspecialchars will never work. That is because htmlspecialchars is expecting a string value, not an array - $_POST is a superglobal array containing the values submitted by your form. If you want to apply htmlspecialchars to all the values in $_POST then use array_map. Alternatively apply htmlspecialchars to $val inside the foreach loop.
-
Your form only submits the the basket name in the form of a checkbox value <td> <input type="checkbox" name="basket[]" value="<?echo $m["basket_name"] ;?>" /> The foreach loop will be looping through the values from the submitted checkboxes. The $basket1 variable will only contain the value from the checkbox (which is the basket_name). You are seeing 0 in the basket_price field because its data type is an integer and its is being truncated to 0 because you are trying insert a string value into it (the baskek name). You need another input field to submit the basket price and insert that value into the basket_price field in your operationlog table. But you should not be inserting the basket name/price into another table you should ideally be referencing those values using the primary key of the basket table as the foreign key in the operationlog table. Later on when you go to display the data from the operationlog table you would use a join to get the basket name/price values. Also you should not be using raw $_POST data in your queries. You should be validating and sanitizing the input before using it in your queries. And note the mysql_ functions are deprecated (no longer supported) you should update your code to use PDO or MySQLi database api's
-
Weird I cant seem to be able to send you a PM to inform you I have merged your topics seeing as they are similar. Also please do not bump old topics to "advertise" your new topics either.
-
file_get_html and dom -- stuck in problem -- help needed
Ch0cu3r replied to qam47's topic in PHP Coding Help
Sorry I meant to use $innerpage->find('.article-image') not $lt->find('.article-image') However I think step 2 actually means to get the thumbnail image shown with the headline link and not the actual image from the article of the headline? In which case the foreach loop needs to be // get headline link in <div class="imgBox"> foreach($html->find('.imgBox') as $lt) { // get the article url from the anchor tag href attribute $headline_link = $lt->find('a', 0)->href; // get the image url from the image tag src attribute $headline_image = $lt->find('img', 0)->src; $allimg[]['image'] = $headline_image; } Maybe you need to clarify what step 2 means. -
The output you see is what you get by passing $result to var_dump(), this will print the structure of the array and show the data types of the values stored in the array. You do not need to use explode to get the value from the array. You loop over the values in the the array using foreach and echo the value of the current item $result = $adldap->group()->all($includeDescription = false, $search = "*", $sorted = false); // this returns an array of results var_dump($result); // this will print the structure of the array // this loops over the items in the array and prints each value foreach ($result as $value) { echo $value . '<br />'; } Explode is used for splitting a string into an array.
-
file_get_html and dom -- stuck in problem -- help needed
Ch0cu3r replied to qam47's topic in PHP Coding Help
For step 2 all you need to do is pass $site_url . $url_inner to file_get_html() $html_innerpage = file_get_html($url_inner to file_get_html); // get the article html For step 3 you use $tl->find() to find the article image ( .article-image ). For step 4 echo the image. -
How is isInstalled() function being called? It should never need to be called from the installer. A work around would be to not redirect if the current page is setup.php function isInstalled() { if(!strstr($_SERVER['SCRIPT_NAME'], 'setup.php') && !file_exists($_SERVER['DOCUMENT_ROOT'].'/config/config.php')) { header('Location: http://'.$_SERVER['HTTP_HOST'].'/setup.php?step=0'); exit; } }
-
I would say you would want to setup three tables in your database. users table - stores user info such as user id, username, password etc... items table - store the items in the checklist such as the item id, title, description etc... item_completed table - in this table you only record the user id along with the id of the completed item. You would use a join to know if the user has completed an item in the check list If you are new to joins I recommend you have a look at here first http://www.sitepoint.com/understanding-sql-joins-mysql-database/. You will want to use a Left Join (query the items table and left join the items_completed table where the logged in user id and item id matches).
-
How do I use unlink() to delete a file from the server?
Ch0cu3r replied to sonnieboy's topic in PHP Coding Help
Not quite understanding you. I guess you want to replace the Delete ' . $result["BidIDFile"]; after the checkbox with your link? You can replace the checkbox line with this echo '<input type="checkbox" name="delete[]" value="BidIDFile"> <a href="http://uploads/'.$result["BidFile"].'" target="_blank" onclick="window.open (this.href, \'child\', \'height=800,width=850,scrollbars\'); return false" type="application/octet-stream">'.$result["Addend4"].'</a>'; -
If you dont want to use session then do not advance the user pass the first step if the database credentials are not correct. If the credentials are correct save them to your config file (as was discussed in your previous thread). On the install steps that require a database you would include your config file. If you dont want the config file to be created until the install process has finished then use sessions for storing the credentials
-
How do I use unlink() to delete a file from the server?
Ch0cu3r replied to sonnieboy's topic in PHP Coding Help
Ok looking at your code I assume only the file paths are stored in the following fields? BidIDFile <--- stores the filepath for BidFile TabSheet <--- " " " " TabSheet SignInSheet <--- " " " " SignIn Sheet Addend1 <--- " " " " Addendum 1 Addend2 <--- " " " " " 2 Addend3 <--- " " " " " 3 Addend4 <--- " " " " " 4 Addend5 <--- " " " " " 5 I couldn't find what fields stores the filepath for the form fields labelled Addendum 6 and Executed Contract in your form? I wont post the code for all 10 fields in your form. I will show an example for the Bid File field. <td class="td_input_form"><input type="file" name="BidIDFile[]" size="50"></td> Change the Bid File upload field (shown above) to to this <td class="td_input_form"> <?php // if the BidIDFile is empty, if(empty($result["BidIDFile"])) { //then show file upload field for Bid File echo '<input type="file" name="BidIDFile[]" size="50">'; } else { // Bid file already upload, show checkbox to delete it. echo '<input type="checkbox" name="delete[]" value="BidIDFile"> Delete ' . $result["BidIDFile"]; } ?> </td> This will show the file upload field if a Bid File has not been uploaded (the BidIDFile column is empty in the table row). If there is a value then it will show a checkbox for deleting the file. You will apply this code logic for the remaining upload fields. Changing BidIDFile to the corresponding column in your table for each field. To delete the file you need to loop over $_POST['delete'] array when the form has been deleted. This array contains the table columns for each uploaded files. You would perform a select query to get the file paths from these columns in your table. From the result of the query you would pass each file path to unlink to delete the file. Then to remove the file paths from the table you would run an update query setting the columns to an empty value. Example code // Connect to SQL Server database include("connections/Connect.php"); $strsID = isset($_GET["Id"]) ? $_GET["Id"] : null; if(isset($_POST['delete'])) { // whilelisted table columns $fileColumnsInTable = array( 'BidIDFile', 'TabSheet', 'SignInSheet', 'XConnect', 'Addend1', 'Addend2','Addend3','Addend4','Addend5', 'Addend6'); $fileColumns = array(); foreach ($_POST['delete'] as $fileColumn) { if(in_array($fileColumn, $fileColumnsInTable)) $fileColumns[] = $fileColumn; } // get the file paths for each file to be deleted $stmts = "SELECT " . implode(', ', $fileColumns) . " FROM bids WHERE ID = ? "; $querys = sqlsrv_query( $conn, $stmts, array($strsID)); $files = sqlsrv_fetch_array($querys,SQLSRV_FETCH_ROW); // loop over the files returned by the query foreach ($files as $file ) { //delete file unlink($file); } // now remove the values from the table $stmts = "UPDATE bids SET " . impload(' = '', ', $fields) . " WHERE ID = ? "; $querys = sqlsrv_query( $conn, $stmts, array($strsID)); } -
EDIT. In jcbones code change lines 8, 9 and 10 to $file_name = $_FILES['uploaded_file']['tmp_name']; //name of the saved file. $new_file = $_FILES['uploaded_file']['name']; // or set this variable to 'gps.txt' You should not need to modify the code provided by jcbones. The code should append the contents of the uploaded file to gps.txt. If the code is not working, then either the file is not being uploaded or it is unable to write to gps.txt. Check your servers error log to see if there are any errors.
-
If you find you are repeating code then its time to refactor the code into a function, example code function getTimePeriod($value) { $value = preg_replace('/[^0-9]/', '', $value); if($value == '') { $value = '1 month'; } elseif($value == '7') { $value .= ' days'; } elseif($value == '24') { $value .= ' hours'; } return $value; } $oneTime = getTimePeriod($one); $twoTime = getTimePeriod($two); $threeTime = getTimePeriod($three); For more information on writing your own functions go to http://php.net/manual/en/functions.user-defined.php
-
You should not use mysql_fetch_assoc() for checking if the query returned a result, as this will cause your function to skip the first row in the result. What you should use is mysql_num_rows() instead. if(mysql_num_rows()) { while ( $row = mysql_fetch_assoc( $result ) ) { $attachments_id[]=$row['post_id'];//put all post ids for specific address into array } ...
-
You can not just rename the mysql_ functions to mysqli_ as they are completely different. You should be looking at php.net/mysqli for the correct usage of these functions. For what its worth your better of deleting the code generated by Dreamweaver and just writing the code yourself, with a lot few lines of code.
-
Currently your link is invalid html. If you look at my post you will see I posted the correct syntax for your link. The artists span goes where the ... is in my code. Also when adding the name of a class to a html tag you don't include the period in the class name.
-
You need to use the $artist['userid'] variable for setting the userid in your link, example echo '<a href="artists_details.php?userId='.$artist['userid'].'"> ... </a>';
-
From the code your posted the "no such file or directory" message is not from your PHP code. It is most likely the default 404 file not found error message from your server. Are you sure all files are named and placed in the correct directory on your server?
-
Seems to me you are trying to write a anagram solver? To find possible words from the letters provided Yes one way would be to use preg match ( anagram letters in a character class wrapped in a word boundary ) to see if the letters used in the word are contained in the anagram. But this will only get you as far as finding possible words from the anagram. You will now need to check to make sure each letter used in the word does not exceed how may times it was used in the anagram, eg the if the letter t is used twice in the anagram then the word cannot use the the letter t more then twice. You can use count_chars to help you there.
- 4 replies
-
- php
- preg_match
-
(and 3 more)
Tagged with:
-
If you are developing/testing php code then rename php.ini-development to php.ni Yes php-cgi.exe is most likely being used by IIS.
-
I only suggested Non Thread safe as that was what I read from the note on windows.php,net If the non thread safe version does not work then try the thread safe version. I only suggested to stop IIS in case Windows complained when you went to overwrite the files that a process was using/reading them.
-
Not a IIS user. But I would assume you should able to download the latest version of PHP and copy the files over to your PHP5.3 installation folder and overwriting any existing files. Before doing this first make a copy of your existing PHP5.3 folder Download the latest 5.6 Non Thread Safe zipped package from windows.php.net (labelled VC11 x86 Non Thread Safe) Stop IIS Extract the contents of the zip to your PHP5.3 installation folder Restart IIS PHP should now be updated.