-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
any particular web hosting may have restrictions on how to send email through their mail server (and may not even supply a sending mail server, your friend that can send emails may be sending them through some other mail server.) what is your free web host's name and have you checked their FAQ section on sending emails? common problems would be a mail server that's set up to require smtp authentication or problems with the From: address (or lack of) being used in the email headers.
-
different flavors, colors, or sizes of something are different things, each with a unique id.
-
the first error is because there is no ?id=value present on the end of the url when you requested the page and $_GET['id'] doesn't exist. for variables that may not exist, you need to test if they do exist before referencing them. php has a function, isset() that can be used for this. the second error is actually related to the first one. without any id value, the sql query statement becomes "SELECT * FORM article WHERE id=" which is syntactically incorrect and produces a query error. if you had error checking logic in your code (which you should always have) to test if the query ran without any errors, you would be getting a mysql error at that point in the sql statement. you also have a typo in the FORM keyword in the sql statement. it should be FROM so, two recommendations - 1) for variables that may not exist, test if they are present before trying to use them, and if they don't exist, take an appropriate action, such as not running the code that's dependent on the variable existing. 2) always test for database query errors before trying to use the result from the query. and related to this, even if the query runs without any errors, it may not match any rows in the database table. you should also test if the query matched any rows before trying to fetch and use the data from the query. edit: as an additional note: all external data cannot be trusted. you must validate not only that it exists, but that it contains an expected value or that you render any nefarious value in it, inert. edit2: and you should also test if the database connection and select_db statements worked (you can select the database at the same time you make the connection.)
-
1) for the user email, how do you know it doesn't work and what part of it doesn't work? your statement could mean anything from a php error at the mail() statement, to the values being missing in the message or the link not being a clickable link. you should also be testing the value returned from the mail() function call and logging your own error message if it is false (you should also have php set up to log all the php detected errors.) 2) for the $email_user variable, your code is setting that from the result of a SELECT query statement. it will be a result resource if the query ran without any errors and a false value if the query failed due to an error, which since the query contains an sql syntax error, will currently always be a false value. is the $email_user supposed to be the $email variable already present in the code or are you trying to retrieve something from the SELECT query? if you are trying to retrieve something from that SELECT query (that you don't already have present in the code), you will need to fetch the row that the query matched before you can reference the values in the php code.
-
actually, the OP is triggering the error with an intentional typo in the file name. not sure what the question about this is, but the first message, the Warning, is because the file could not be found. the second message, the Fatal error: is because a require()/require_once() statement that fails also throws a fatal run-time error.
-
where exactly are you stuck at when you tried to do this? programming help forums are not here to find, give, or write code for you. without knowing what sort of problem you had when you tried this, the answer could range from a) you need to buy a good php/mysql book and/or take a programming class to z) you have a logic or syntax problem in your code that we could help with if you posted your code and told us what sort of error or symptom you got from that code. the thing you stated you want, will require that you lean enough html, php, and mysql to do the following steps - 1) create a form or link(s) that let the user pick which item he wants, that submits the corresponding id value as a get request to the display page. 2) on the display page, detect and validate the id value that was passed in the get request. 3) create a database connection, checking for connection errors. 4) form and run the sql query statement to retrieve the correct row using the submitted id value, protecting against sql injection in the id value and checking for query errors. 5) check if the query matched a row and if so, fetch the row. if not, display a message to the user. 6) if a row was found, display the data from the fetched row the way you want it to be displayed.
-
Call undefined function mysqli_connect()
mac_gyver replied to m4u_hoahoctro's topic in PHP Coding Help
at this point i don't think we know what exactly you have or what's being ran. you stated you installed xampp and Vertrigo. afaik, those both would have attempted to install Apache/Mysql/Php and either would have produced installation errors or perhaps installed two different apache/mysql servers using different port numbers. when you are running the phpinfo(); statement to find the php.ini and the mysqli information, how exactly are you invoking the .php script containing the phpinfo() statement? through phpdesigner or are you using your browser with a url something like - http://localhost/your_php_file.php ? -
actually, if your UPDATE query contained another SET term of - user_id = LAST_INSERT_ID(user_id), your second query of SELECT LAST_INSERT_ID() would return the user_id value. edit: and you don't actually need to explicitly run the second query, you can just call the lastInsertId.. function/method of whatever php database library you are using.
-
php is a web server-side scripting language. you need to request the page using a url on a web server. you can install a web server on your local computer to learn and develop php code. there are all-in-one AMP (Apache, Mysql, Php) packages you can find and install to do this. Xampp from apachefriends.org is probably the most common package.
-
since there won't be much paperwork involved, just the cash from your hands to mine, i can let it go for $2000 US, and you would be getting your bridge (or at least the bricks from it) back .dismantling and shipping would be up to you.
-
Call undefined function mysqli_connect()
mac_gyver replied to m4u_hoahoctro's topic in PHP Coding Help
the phpdesigner ide you are using is invoking php directly, not through the web server. you either need to invoke your files using a browser, through the web server, or you need to configure phpdesigner to use the same php.ini that the web based php is using. see the following from the phpdesigner documentation - -
your form's action='...' attribute has nothing to do with validation. it's where the form will submit to. which a little inference about what it's name is and what value it had in it when it worked would have told you. if it was correct and worked in the first place, don't blindly change it based on something you saw on the internet, otherwise i have a bridge in Arizona that i have been trying to sell, that you may be interested in buying...
-
the line of code you showed us (reply #3 in this thread) for the <form ....> tag is either not in a .php file or it's already part of a php echo statement. in either case, the php code in it isn't being parsed and executed. if the page where your form is at isn't a .php page or you haven't configured your web server to parse .htm or .html pages as php code, no php code in it will ever be executed. if your original form action='....' attribute worked, why did you make a change to it? i have a recommendation concerning the article you linked to at sitepoint, DON'T write code like this - $nameErr = $addrErr = $emailErr = $howManyErr = $favFruitErr = ""; $name = $address = $email = $howMany = ""; instead, use an array for the errors and and array for the form data. initialize the errors using $errors = array(), then set elements in the $errors array for each detected error - $errors['some_field_name'] = 'The some_field_name is required'; to test if there are any errors, just test if the $errors array is empty or not. initialize the $data array by making a copy of the $_POST array, trimming each element (some people allow leading/trailing white-space characters in password type fields.) if you are submitting arrays data in the post data, you can use a recursive user written trim function with array_walk_recursive() to operate on all elements of the submitted post data. then, use elements in the $data array everyplace you reference post data - $data['some_field_name']
-
the OP is probably dyslexic (or translated this from a right to left language) and posted his example phone number in reverse. his question/suggestion about using zero fill to 'fix' this would address leading zeros, not trailing ones.
-
Hello! Pretty simple PHP form, I broke it..please assist! :)
mac_gyver replied to teanza's topic in PHP Coding Help
some comments - 1) ALL the form processing code needs to be inside of a logic test that has checked if a form was submitted. if a form was submitted, all the form fields (except for unchecked checkboxes and un-selected radio-buttons) will be set, even if they are empty. 2) you should trim() all inputs before validating them. 3) you should validate all inputs to insure that required fields are not empty and that anything in a field is of an expected format and is not nefarious. 4) any user input that's put into the message body should be passed through htmlentities() (even if you are sending a plain text email, since email clients can be configured to view the email as html even if it is not) so that should you be using a browser as the email client to view the email, any javascript that was in the submitted message won't be rendered. 5) the email address that's being put into the mail header MUST be validated to insure in only contains an email address and nothing else that could be used to inject other headers into the email. 6) you should produce a specific error messages for each input that didn't match the expected format to tell the visitor what they did that was wrong, so that they can correct the problem. validation errors should be added as elements to a php array variable. 7) you should re-populate the form fields with any previously entered data so that the visitor doesn't have to re-type the values. doing this and displaying any validation errors is easiest if you have one page that contains the form and the form processing code. the email is not being sent from the person who submitted the form. it is being sent from a mail server at the web host where the form was submitted to. the From: address in the mail header is either an email address with a domain name that can be matched to the ip address where the sending mail server is at or if the domain doesn't match where the sending mail server is at, that there's an SPF DNS zone record at the domain being used in the from email address that says your sending mail server is authorized to send email for that domain. 9) you must test the value returned by the mail() function to determine if the sending mail server even accepted the email (it still may not be sent and the receiving mail server may not accept it) before displaying any sort of success message. 10) and because getting email to actually be sent is something of a problem due to all the spam abuse, you should log the relevant information about each form submission so that you know what's going on. -
Change image on website based on time in day
mac_gyver replied to krishh33's topic in PHP Coding Help
you should be using a database, but lacking that, here's an example showing a general purpose/data driven way of doing this common assignment - <?php // define constants for day names to make reading and writing code easier define('SUN',0); define('MON',1); define('TUE',2); define('WED',3); define('THU',4); define('FRI',5); define('SAT',6); // domain root relative path to where images are at $path = '/images/shows/'; // data - days (one or an array), start-time (inclusive), end-time (exclusive), image $a[] = array(SUN,'00:00','01:00','MensHealth'); //1 $a[] = array(SUN,'01:00','02:00','AlanTaylor'); //1 $a[] = array(SUN,'02:00','05:00','HughHewitt'); //1 (this image used later w/different hours) $a[] = array(range(SUN,SAT),'05:00','10:00','RedEyeRadio'); //7 $a[] = array(SUN,'10:00','11:00','MomTalk'); //1 $a[] = array(SUN,'11:00','12:00','GoodParenting'); //1 $a[] = array(SUN,'12:00','14:00','PetShow'); //1 $a[] = array(SUN,'14:00','15:00','GardenRebel'); //1 $a[] = array(SUN,'15:00','16:00','WorkingMother'); //1 $a[] = array(SUN,'16:00','17:00','WhatsCooking'); //1 $a[] = array(SUN,'17:00','18:00','HomeWizards'); //1 $a[] = array(SUN,'18:00','19:00','DougStephan'); //1 $a[] = array(SUN,'19:00','20:00','Finance'); //1 $a[] = array(SUN,'20:00','21:00','PopularScience'); //1 $a[] = array(SUN,'21:00','22:00','ABCRadio'); //1 $a[] = array(SUN,'22:00','24:00','Medicine'); //1 $a[] = array(MON,'00:00','03:00','ArmedAmerica'); //1 $a[] = array(MON,'03:00','05:00','HughHewitt'); //1 $a[] = array(range(MON,FRI),'10:00','13:00','BobRick'); //5 $a[] = array(range(MON,FRI),'13:00','16:00','DougStephan'); //5 $a[] = array(range(MON,FRI),'16:00','19:00','MariluHenner'); //5 $a[] = array(range(MON,FRI),'19:00','20:00','DebbieNigro'); //5 $a[] = array(range(MON,FRI),'20:00','22:00','DaveRamsey'); //5 $a[] = array(range(MON,FRI),'22:00','24:00','JoyBrowne'); //5 $a[] = array(range(TUE,SAT),'00:00','01:00','ShannonJoy'); //5 $a[] = array(range(TUE,SAT),'01:00','02:00','BillNojay'); //5 $a[] = array(range(TUE,SAT),'02:00','05:00','DennisPrager'); //5 $a[] = array(SAT,'10:00','12:00','HaidtReport'); //1 $a[] = array(SAT,'12:00','13:00','ABCNews'); //1 $a[] = array(SAT,'13:00','16:00','GarySullivan'); //1 $a[] = array(SAT,'16:00','18:00','PopularTech'); //1 $a[] = array(SAT,'18:00','19:00','WhatWorks'); //1 $a[] = array(SAT,'19:00','21:00','JillMoney'); //1 $a[] = array(SAT,'21:00','23:00','YouManual'); //1 $a[] = array(SAT,'23:00','24:00','MadeAmerica'); //1 $hm = date('H:i'); //set variable the hour:minute HH:MM of the day. $d = date('w'); //set variable $d to the day of the week. // find the image that matches the day/time $img = ''; foreach($a as $e){ if(((is_array($e[0]) && in_array($d,$e[0])) || (!is_array($e[0]) && $d == $e[0])) && $hm >= $e[1] && $hm < $e[2] ){ $img = $e[3]; break; } } if($img == ''){ echo 'no matching program found'; } else { ?> <img src="<?php echo $path.$img.'.jpg'; ?>"> <?php } -
phone numbers, despite their name, aren't numbers, in a programming sense, and they certainly aren't integers. they are formatted strings consisting of decimal characters. you should be string them as a varchar type. you should also be storing any date values as a DATE data type.
-
it's also not clear from your description what result you are getting and what result you expect. please post something showing what output you are getting now and what exactly is wrong with it. i suspect that you want to 'pre-select' the current choice in the category and brand select/option menus, but that's just a guess. btw - DreamWeaver isn't a very good tool for anything let alone server-side coding, like php. of the 500 lines of code you have, there's only about 300 lines that are doing anything useful. the other 200 are either duplicating something or are not contributing anything to the result. and until you can produce code that does what you want, there's no point in trying to create a page that has nearly 40 different javascript features on it. stick to getting the basics working first.
-
Redirect to previous page after login not working
mac_gyver replied to Canadian's topic in PHP Coding Help
the linked to forum reply contains example code showing how to do the suggested redirect. -
Redirect to previous page after login not working
mac_gyver replied to Canadian's topic in PHP Coding Help
i suspect that your code is actually redirecting to where you want, but code on that page is redirecting back to the page you finally see. rather than redirecting all over the place on your site and trying to keep track of where you should be at, you can simplify all of this by making a single page (index.php) that handles everything. see the following reply for how your page should be generally laid out - http://forums.phpfreaks.com/topic/296602-storing-multipe-session-variables-for-a-cart/?do=findComment&comment=1513104 the post method form processing code for the login functionality will authenticate the user, set the session variable that identifies him (i recommend using the user id, not the user name), then does a redirect to the same page to cause a get request for that page. the get method code for the login functionality will either produce the login form (and probably a registration link), if the visitor is not logged in, or it will produce a welcome message and a log out link if the visitor is logged in. you would just display the result from the get method login code where you want it on your page. any other content on the page, navigation, main content, ... can use the logged in state to determine what content they will produce, that will then be displayed where you want it on your page. -
Is it worth storing database results in a session
mac_gyver replied to NotionCommotion's topic in PHP Coding Help
i don't know precisely, but everything about the query cache would be found in the documenation - http://dev.mysql.com/doc/refman/5.6/en/query-cache.html it looks like checking the value of Qcache_hits, before and after a query is ran will tell you if the query got the result from the cache - -
Is it worth storing database results in a session
mac_gyver replied to NotionCommotion's topic in PHP Coding Help
you just execute the query. the result you get back will either be from the query cache, if the result is in the cache and it is current, or the database engine will actually run the query against the database table(s) to get the result (and put it in the cache as well.) the advantage of doing this at the database level will mean that common and current things on your site - configuration, menus, the current state of forum threads, ... will be in the cache and all the visitors viewing that common/current information will get results from the cache. -
there's two problems with what you are asking/doing. 1) you should not have a database table with columns with same meaning data spread out like that. database tables are not spreadsheets. all the code and queries to store, find, update, delete, or make use of any of the values in a any column is more complicated. each same meaning piece of data should be stored in a separate row in a database table. 2) an average is derived data. it should not be stored, but instead calculated any time it is needed.
-
you need to look at the web server access log to find out where the requests are coming from and/or add logic in your php script to log all the information you are getting with the request. i looked at your previous thread, and the code isn't even checking if a form was submitted, so anything like a search engine spider or a bot script making a get or post request for the page will cause the code to run. once you have made sure a post method form has submitted, you need to properly validate each input to make sure that it is not empty and that it only contains data of the expected format. you are also putting form data into the header field. this will allow a hacker to do anything he wants to the email that gets sent by your server. without proper validation, this will allow any to:, from:, cc: , bcc:, subject, message body, attachments.... to be send through your mail server. and an fyi - the email is not being sent from the person who entered the information in the form. the email is being sent from your sending mail server. the From: mail header needs to be an email address at the domain of your sending mail server or you need an SPF DNS zone record at the domain being used in the from address that says your sending mail server is authorized to send email for that domain. the Reply-to: mail header is where you would put the email address from the person who filled in the form, after you have validated that it only contains an email address and no mail header injection content.
-
Is it worth storing database results in a session
mac_gyver replied to NotionCommotion's topic in PHP Coding Help
the query cache, in the database engine, will do this for you. for any particular query statement, if the tables referenced in the query haven't changed (insert, update, delete), the result is gotten from the query cache, assuming the result is already in the query cache. if any table referenced by the query statement has changed, the new data is retrieved and cached.