-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
storing some values from a php-array into mysaql-db fails
Ch0cu3r replied to Maze's topic in PHP Coding Help
What did you change the first line to? I ran your code and I get no such error. Sounds to me you have made other changes to your code which is now causing this error. -
storing some values from a php-array into mysaql-db fails
Ch0cu3r replied to Maze's topic in PHP Coding Help
Ohh... never knew that. Learnt something new there @Maze ignore my comment regarding the order by clause. -
yes you can setup a very basic template file. If put the above code in file called template.php. Now replace <h2>Home</h2> with <?php echo $page_title; ?> When you want to use the template file you'd do something like this // define the page title $page_title = 'About'; // now include the template include $_SERVER['DOCUMENT_ROOT'] . '/template.php';
-
storing some values from a php-array into mysaql-db fails
Ch0cu3r replied to Maze's topic in PHP Coding Help
On line 3 localhost, root and rimbaud should all be wrapped in quotes $db = new mysqli('localhost','root','rimbaud','test'); // use your credentials The only error remaining will be line 121 $currentTags = array(); $sql = "SELECT DISTINCT tagname FROM pois_tag ORDER BY tagname = 'name' DESC, tagname"; $res = $db->query($sql); while (list($tn) = $res->fetch_row()) { //<--- line 121 $currentTags[] = $tn; } IGNORE You will get that error when mysqli_query returns false. Looking at the query I can see an error in the order by clause ORDER BY tagname = 'name' DESC, tagname"; An ORDER BY clause only takes a collection of column names and an optional direction to sort the column values by (either ASC or DESC). The = 'name' text is most likely causing an error which is causing your query to fail. Because the query has failed $db->query has not returned a result object and so you are getting this error PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 -
May you did not call FLUSH_PRIVILEGES; after modifying the permissions? If can revert back to your old mysql user you are having issues with and run my code it should tell you what was wrong. Before doing so make sure you have error reporting enabled, add the following at top of your script (after the opening <?php tag) ini_set('display_errors', 1); error_reporting(E_ALL);
-
The code you posted looks fine, it should insert a new record into the Ads table and then update the Ads_AID field value to stroud for the newly inserted record. I do have question why you are doing this? Because you have not add error checking to your queries you wont be able to understand why the code is failing. When running queries you should check it executed without returning errors. The mysqli_query function returns TRUE on success (note this does not indicate the query altered the data in the database), and FALSE if MySQL returned an error (indicates there is a problem with the query). When mysqli_query returns FALSE you can get the error message using mysqli_error. When running queries which modify the data held in a table you need to use a function called mysqli_affected_rows to check that it actually did anything. This functions returns the number of rows affected by the query. This only applies to INSERT, UPDATE, REPLACE and DELETE queries. Your code should look something like this $qry_inserted_Ad = mysqli_query($con,"INSERT INTO Ads (Ads_ID, Ads_AID, Ads_Title) VALUES ('', '$Polished_AdRef', '$Polished_AdTitle')"); // checked query has executed (this DOES NOT indicate the query modified the data in the table) if($qry_inserted_Ad) { // check that the query did modify the table - ie: added a new row if(mysqli_affected_rows($con) > 0)) { // get the newly inserted records id - mysqli_insert_id() returns zero on failure $new_Ad_id = mysqli_insert_id($con); } } // insert query return FALSE most likely due to a error in the query else { // trigger an error, returning the mysql error trigger_error('Adding new ad to the Ads table has failed: ' . mysqli_error($con), E_USER_WARNING); } // check that we have retrived the new rows id if(isset($new_Ad_id) && $new_Ad_id != 0) { $qry_updated_Ad = mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID=$new_Ad_id"); // checked query has executed (this DOES NOT indicate the query modified the data in the table) if($qry_updated_Ad) { // check that the query did modify the table - ie: updated a row if(mysqli_affected_rows($con) > 0)) { echo "Succesfully updated Ad #$new_Ad_id!"; } else { echo "Did not update Ad #$new_Ad_id!"; } } // insert query return FALSE most likely due to a error in the query else { // trigger an error, returning the mysql error trigger_error("Updating ad #$new_Ad_id in Ads table failed: " . mysqli_error($con), E_USER_WARNING); } } else { echo "Unable to retrieve the inserted Ad id!"; }
-
Your database returns the time in 24 hour format, which will be represented as a string. You are comparing that against time() which returns a unix timestamp (number of seconds passed since Jan 1 1970). PHP will not convert this to a 24 hour format nor will it convert your database times to a timestamp. You need to convert $row['clock'] to a timestamp in order to compare it to time(). Here is an example while($row = mysql_fetch_array($result)) { $output = $row['name']. ' - ' . $row['age']; // explode, the time into its components (hour, minutes, seconds) list($hours, $minutes, $seconds) = explode(':', $row['clock']); // build a new timestamp using mktime(), compare the new timestamp with the current time if(mktime($hours, $minutes, $seconds) < time()) { // bold string if timestamp is less than the current time. $output = "<b>$output</b>"; } echo "$output<br />"; }
-
You need to dynamically build your query, specifically the WHERE clause. Example code // define the basic query $sql = 'SELECT movie_name, movie_genre, movie_cast FROM movies_table'; $where = array(); // dynamically build the WHERE clause conditions if($_POST['movie_name'] != 'All') { $where[] = "movie_name='{$_POST['movie_name']}'"; // <-- never do this, only an example } if($_POST['movie_genre'] != 'All') { $where[] = "movie_genre='{$_POST['movie_genre']}'"; // <-- never do this, only an example } if($_POST['movie_cast'] != 'All') { $where[] = "movie_cast='{$_POST['movie_cast']}'"; // <-- never do this, only an example } // apply the where clause conditions to the query. if(!empty($where)) $sql .= ' WHERE ' . implode(' AND ', $where); // execute the query NOTE: The above is only an example. You need to take extra steps before using it in your code, such as sanitizing _POST vars etc.
-
Parse the return values of a webservice object
Ch0cu3r replied to seran129's topic in PHP Coding Help
Thats is a strange value to be returned from an api it looks to me result_data should contain an array maybe? But anyway to answer your question how to get the result_data value you'd use $city = $response->return->result_data; To remove city[0]= apply this $city = str_replace('city[0]=', '', $city); -
How to extract a list of grapes from a string using preg_match
Ch0cu3r replied to ingteractive's topic in Regex Help
You need to fix you regex first. All regex patterns need to be enclosed in delimiters. You have left off the opening delimiter (in your case a forward slash / ) As you are wanting to match complete words you'll want to wrap the list of grapes in a word boundary $ds = "/\bRiesling|Sauvignon Blanc|Zinfandel|Muscat\b/i"; Finally to return the matched words in a pipe separated list you can implode $matches[0] as this will contain an array populated with the matched words. Note if a word is found more than once it will be listed again (duplicated) in the array. If you want to return each unique word found then pass $matches[0] to array_unique first before imploding the array echo "<p>These grapes were used in the string:<br />" . implode('|', array_unique($matches[0])); -
How to insert & retrieve data from mysql table for a specific user
Ch0cu3r replied to chr0n1k's topic in PHP Coding Help
As a user can have multiple contacts, You will need to setup a one to many relationship between your users table and contacts table. To do so you'd add an extra column to your contacts table which be a foreign key for thee user_id field in your users table. If you are unsure about this, then have read through this tutorial on database relationships http://code.tutsplus.com/articles/sql-for-beginners-part-3-database-relationships--net-8561 To only retrieve the contacts belonging to the user you'll need to first authenticate the user. You should save the authenticated users user_id into the session when they have logged in. Then you can run a query like this to retrieve their stored contacts <?php session_start(); $sql = 'SELECT * FROM contacts WHERE user_id = ' . $_SESSION['user_id']; // retrieve all the contacts belonging to the currently login in user $result = mysql_query($sql) or trigger_error('DB Error: ' . mysql_error()); if($result && (mysql_num_rows() > 0)) { while($row = mysql_fetch_assoc($result)) { // output contact information echo '<p>Contact Name: '. $row['firstname'] .', '. $row['lastname'] .'<br />Company: '. $row['company'] .'Tell No: '. $row['cell_no'] . '</p>'; } } -
fgetcsv() returns the current rows data in an array for you, so there is then no need for any of this code $result = $data; $str = implode(",", $result); $slice = explode(",", $str); You'd concatenate $data[0] and $data[1] to join the first two columns together if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br>"; echo "No files...!!!!!"; echo "<script>alert('No files...!!!!!');window.location.href='upload_file.php';</script>"; } else { $csv_file = $_FILES["file"]["tmp_name"]; if (($getfile = fopen($csv_file, "r")) !== FALSE) { $data = fgetcsv($getfile, 1000, ","); // this will ignore the first row - which is usually the column headings while (($data = fgetcsv($getfile, 1000, ",")) !== FALSE) { $col_1_and_2 = $data[0] . $data[1]; // concatenate column 1 and 2 echo $col_1_and_2 . '<br />'; // output the concatenated string } } }
-
Any data sent to the server is only held in memory temporarily. It will not permanently retain the information from a request unless you specifically tell it what it is want to stored and where. If the data sent from your form is important then maybe you should consider saving it in a database first before emailing it the recipient.
-
Remove the form="contactdb" attribute from the <textarea> tag
-
Then you may want to signup to mybb.com forums and seek support there.
-
Either modify your HTML so the paypal form tags span your other divs (easiest solution) Or use JavaScript to grab the values of the external inputs fields and dynamically inject their values into your main paypal form (adds unneeded complexity).
- 7 replies
-
- paypal
- linking input form
-
(and 3 more)
Tagged with:
-
I very much doubt it, Unless either your script records the submissions somewhere or your SMTP server dumps the failed messages somewhere on the server. Sounds to me your new SMTP server requires authentication before emails can be sent. PHP's built in mail() function does not support servers that require authentication. In this case you'll need to use a third part PHP script called PHPMailer instead.
-
So you want to integrate the mybb forum authentication system into your site? if so have you seen this what I found by goggling "integrate mybb into website".
-
That is not the sort of community we are. If you want someone to do the necessary edits then post in the freelance forum
-
The phpmyadmin wiki explains why this feature has been removed as of 3.4.5 https://wiki.phpmyadmin.net/pma/import#Microsoft_Excel_2007_Workbook_.28XLSX.29_-_removed Your only options are to find an alternative application which supports this feature attempt to modify phpmyadmin yourself and implement this feature yourself or to convert your excel files to csv.
-
You sure? I have tested your code and I am able to alter the status of each led individually.
-
Storing selection from dynamic listbox into database.
Ch0cu3r replied to HarryAdney's topic in PHP Coding Help
No, I am not referring to that To get the chosen item you need to use $_POST['country_list'] there is no dollar sign before country_list I repeat there is no dollar sign before country_list ['country_list'] is not a variable, but a key to the $_POST superglobal (associative) array. This array is populated with the values submitted by your form in key/value pairs. The key being the name of an input field from your form. The value will be the value of that field. So $_POST['country_list'] will return the value of the chosen option from the <select name="country_list"></select> dropdown menu. If you do not understand what arrays are then consult the manual here: http://php.net/arrays -
Storing selection from dynamic listbox into database.
Ch0cu3r replied to HarryAdney's topic in PHP Coding Help
Why have you got a dollar sign before country_list. There should not be a dollar sign there. Do you not know how to use associative arrays? or how to retrieve data from $_POST? $country_list should be $country