Jump to content

ginerjm

Members
  • Content Count

    5,172
  • Joined

  • Last visited

  • Days Won

    68

Everything posted by ginerjm

  1. Why is your pdoconnect header not what I gave you??? I don't know what the mention of "structure" has to do with this topic. Nor the photograph. You're making it very difficult to help you. The error message obviously comes from the connect logic so that is where the problem lies. As for the main script - when you get a false result from the connect call why are you not exiting??? Add an echo to the pdoconnect logic to display the input dbname just to make sure you are actually executing this set of code. And - I assume that you are supplying the uid and pswd in the connect code and only left it as xxx and yyy for me.
  2. So - add some echos to check what is going on. Or you could post the part of the current script that is making that connection call as well as the entire module that contains the connection code so that WE can see what you are seeing. That would be so very very helpful.....
  3. No it does not. If the user clicks on a choice that is the value that should appear in your $_POST array as element 'district' Of course - on many mobiles the screen is so small it would be easy to select the wrong one with my big fingers.
  4. I don't understand what this means: "seems to be random the course it selects " What is the problem?
  5. You should NOT EVER store any kind of hint to a password. Once the user has logged in with his/her password all you need is perhaps the username and a token (maybe). You never need the pswd again.
  6. I don't actually use try/catch in my code so it must have been left over from something I copied from you and edited. Actually - the catch is commented out so it should not be a problem. Do we still have a problem? Tomorrow.
  7. So you have solved the error? What now? And what is the catch for? Seems like an orphan
  8. I have no idea why your dbname is not getting passed. Did you try echoing it out from inside the function? Where is this other error? What is line 15? AND WHY DO YOU KEEP EDITING MY CODE? Do NOT include the db name in anything but the call to the connect!! Actually change the function header to this: function PDOConnect($l_dbname=NULL, $l_msg=null, $l_options=null) And get RID of the database name you supplied lower down. Tsk, tsk, tsk.
  9. I doubt if the mail is being sent.
  10. Here is my second demo. Please note the following changes. You don't put the dbname in the function header. You supply the name in the call to the function. Also - the connection function is something you should store in a folder along with all of your other generalized utility scripts that will be used in many of your future scripts. Somewhere outside of the root tree so that nobody can get there from a browser connection. You then always include it using a 'require' statement that points to that folder and script. You can include the uid and pswd in the script because nobody will be able to see it from the web. // start of script every time. session start(); // setup a path for all of your canned php scripts $php_scripts = '/home/user/php/'; // a folder above the web accessible tree // load the pdo connection module require $php_scripts . 'PDO_Connection_Select.php'; //******************************* // Begin the script here $ip2 = GetUserIpAddr(); if (!$pdo = PDOConnect("foxclone_data") { echo "Failed to connect to database" // exit? } else { $sql = "INSERT INTO LOGIN (ip_address) VALUES ('$ip2' )"; // use exec() because no results are returned $pdo->exec($sql); echo "New record created successfully"; } catch(PDOException $e) { echo "Query failed to run properly: $sql <br><br>" . $e->getMessage(); } exit(); //***************************************** // functions below //****************************************** function GetUserIpAddr() { if(!empty($_SERVER['HTTP_CLIENT_IP'])) { //ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //ip pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } //****************************************** // This code s/b removed once you place it into the php folder // and rely on the require line at the top. function PDOConnect($l_dbname, $l_msg=null, $l_options=null) { if ($l_options == null) { // set my default options $l_options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_FOUND_ROWS => true, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC); } if ($l_dbname == null) $host="mysql:host=localhost;charset=utf8"; else $host="mysql:host=localhost;dbname=$l_dbname;charset=utf8"; $uid = "xxxxxxx"; $pswd = "yyyyyyyyy"; try { $mysql = new PDO($host, $uid, $pswd, $l_options); } catch (PDOException $e) { if (strtoupper($l_msg) == "SHOWMSG") echo "Fatal Error<br>Failed to connect to mysql via PDO. PDO Error msg is:<br>".$e->getMessage(); else echo "Fatal Error<br>Possible bad dbname?<br>Failed to connect to mysql via PDO. Sensitive error msg may be viewed with additional parm to call to PDOConnect(dbname,'showmsg')"; return false; } if (!$mysql) return false; else // all worked - return handle to pdo connection. return $mysql; }
  11. YOu put the function at the top. That's a big no-no!
  12. Maybe you should show us the actual code then.... What about the points I made?
  13. This script is a bit mal-constructed. YOu are outputting an html form but then your follow it with the php logic that means nothing UNTIL the form is submitted. A good layout would be to have the php come first and the html come later. Plus it is a bit out-dated. And you are missing some headers for the email.
  14. So what have you tried? It's much easier to help you when we see what the code currently looks like. It could be something simple like a switch based upon the incoming value and a switch construct to execute the appropriate header() call but we can't tell unless see a bit more since your explanation wasn't completely clear, ie "create and simple forward".
  15. This is what my function looks like: function PDOConnect($l_dbname=NULL, $l_msg=null, $l_options=null) { // PDO requires it to be enabled in php.ini // add this to the ini file: /* extension=pdo.so extension=pdo_sqlite.so extension=sqlite.so extension=pdo_mysql.so */ if ($l_options == null) { // set my default options $l_options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_FOUND_ROWS => true, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC); } if ($l_dbname == null) $host="mysql:host=localhost;charset=utf8"; else $host="mysql:host=localhost;dbname=$l_dbname;charset=utf8"; $uid = "xxx"; $pswd = "xxx"; try { $mysql = new PDO($host, $uid, $pswd, $l_options); } catch (PDOException $e) { if (strtoupper($l_msg) == "SHOWMSG") echo "Fatal Error<br>Failed to connect to mysql via PDO. PDO Error msg is:<br>".$e->getMessage(); else echo "Fatal Error<br>Possible bad dbname?<br>Failed to connect to mysql via PDO. Sensitive error msg may be viewed with additional parm to call to PDOConnect(dbname,'showmsg')"; return false; } if (!$mysql) return false; else // all worked - return handle to pdo connection. return $mysql; } Basically the only arg I use is the dbname when calling this. It is designed to allow for future usages though. The basic call I use is if (!$pdo = PDOConnect("my_dbname") { //show some kind of message // exit? } // proceed with $pdo as the handle to all database interactions
  16. I would write a good set of connection code and make it a function by itself. Then I would call that function to start a connection do my query and processing outside of it. I would also improve that error message to tell you where and what happened but without the details so you don't let users see it. And when I do a query I write it so that I can check the results. Something like: $qresults = $pdo->query($q); if (!$qresults) { // handle error }
  17. There Is No MYSQL Connection. And I don't have that code for you because you have to choose your db extension. I gave you a link to help you out. Please read it.
  18. Here is what I would do: // start of script every time. <?php session_start(); // DO NOT USE THE MYSQL EXTENSION. IT IS OUTDATED AND NO LONGER VALID. $con = mysql_connect("localhost","xxxxx","yyyyyyyyy"); if (!$con) { die('Could not connect: ' . mysql_error()); } $ip = GetUserIpAddr(); mysql_select_db("foxclone_data", $con); // build a query statement $q = "INSERT INTO LOGIN (when_login, ip_address) VALUES (now(), '$ip' )"; // Run your query - personally I use PDO since it is easier than mysqlI // Check the result of your query - Did it fail? // Create a message informing user of success or failure // do your html coding here, placing the message variable where it fits. exit(); //************************** function GetUserIpAddr() { if(!empty($_SERVER['HTTP_CLIENT_IP'])) { //ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //ip pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } // What if you don't find any ip address? return $ip; } Note my comments. One normally (?) begins a session at the top of every script and usually doesn't worry about ending it since PHP will do that for you. And again - the mysql extension has been deprecated for several years and removed as of php version 7 (or earlier). Most host provide mysqlI or PDO. Here on this forum PDO seems to be the preferred one and I agree with that opinion. It is pretty easy to use and handles prepared queries quite well. Read the manual https://www.php.net/manual/en/class.pdo This is a good thing to write a function for and use in all of your scripts. Add a dbname to the function arguments too.
  19. Or use the code sample I posted previously.. if you are still with us.
  20. Here's another suggestion. You say the if statement does not work. Let's prove that it is actually getting executed by placing an echo line just before it to show that your script is getting to that spot echo "About to test the query value: ".$row1['accountType'] . "<br>"; if(strtoupper($row1['accountType']) == 'STUDENT') echo " result is student"; else echo "results is NOT student"; This will ABSOLUTELY HAVE TO SHOW YOU SOMETHING unless you are not doing any output to the web browser. BTW - do you have php error checking enabled?
  21. Perhaps this line will solve your problem - even tho you haven't told us of the problem if(strtoupper($row1['accountType']) == 'STUDENT') echo " result is student"; else echo "results is NOT student"; Of course you might want to add some code to check that the query actually returned some row(s)..... Have you read up on how to do that?
  22. Don't you think you should share that error that you found by error checking?
  23. What do you mean by "store the result....." Why do you need to store it anywhere? You already have it! And what compare are you trying to do that you are not already doing in this if? What I told you was not about good practice. I how you have to be aware of what you are trying to compare as far as the case goes.
×
×
  • 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.