-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
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.
-
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".
-
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
-
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 }
-
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.
-
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.
-
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
Or use the code sample I posted previously.. if you are still with us. -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
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? -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
Define "does not work". -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
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? -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
Don't you think you should share that error that you found by error checking? -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
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. -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
Again - point out to us which line is failing you or explain what you are doing and not understanding. 25 words or less please. That will make more sense. BTW - did you understand what I told you last? -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
What people are telling you is to NOT write your code like this and to learn how it SHOULD be done. Ignoring that - what is the problem now? YOu can't find the right value? Are you allowing for case being incorrect? Or have you researched how to make a proper compar to allow for different cases? Research, research, research - something a programmer has to do. -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
So have you got your answer yet from Philw's post? -
BUILDING A TRANSCRIPT SYSTEM USING PHP/MYSQL
ginerjm replied to JophusEdumadze's topic in PHP Coding Help
Probably will need a good php reference guide to help you learn. -
object of class mysqli_result could not be converted to string
ginerjm replied to mattchamp97's topic in PHP Coding Help
HTH! -
Compare result of MySQL statement to string in PHP
ginerjm replied to mattchamp97's topic in PHP Coding Help
I"m confused. Do you want to find the records with a specific id num or the ones that are students? And - a table with named "user_info" with a column named "userid" kind of implies that there is only one row that matches. Hmmm..... -
I"m guessing you did a little research to look up that function. Also called "implode". But you probably found that out too. Good work!
-
Php code using function for copyright 2015-2020
ginerjm replied to saaima's topic in PHP Coding Help
Yes - forums (including this one) DO help people. But not with all of their tasks. Forums like this one help you address your code. Help you correct it or debug it or help you amend your solution. We are not here to just plain write it for you. We are here for people who are having difficulty but that means showing us the difficulty. -
And you are asking the PHP forum to do what for you?
-
The message is correct. The problem is in the query. If you did it the way I said to do previously, you echo out the query itself with your error message and look at it. YOu have some bad logic in that query. Do it this way: $q = "SELECT cat_id, subcat_id, subcategory_title, subcategory_desc FROM categories c, subcategories s WHERE ($parent_id = categories.cat_id) AND ($parent_id = subcategories.parent_id"); $select = mysqli_query($con, $q); if (!$select) { echo "Error running query - $q<br>", mysqli_error($con); exit(); } Note how I wrote the query to make it more readable. And how I saved the query itself so that it can be echo-ed out to review. Your problem may very well be that you have two tables but you don't distinguish which selections are from which table. If you have fields with the same name in both tables the query engine doesn't know which one you want. Note how I assigned aliases in the query to the table names. Add those aliases to your field names by doing "c.cat_id" or "s.cat_id" depending which table the field comes from. And you are missing a closing paren.
-
Add some checking in your code to be sure that the query was run successfully. Something like: // check if there was an error running the query if (!$select) { echo "Error running query : " . mysqli_error($con); exit(); } I'll let you figure out where to place this block of code This will print out a message if the query is failing you. Or if the $con did not get properly made prior to that. Suggestion. Always assign your query statement to a variable and then use the variable in the query call. That way you can have your error handling code print out the query for your review. As you have it now you can't do that.
-
When you figure out where your "name" field went to, I highly suggest you modify some of your db field names. Using "date" and "time" is not good practice. NAME the field, don't just say date or time. And are all of these fields necessary on that one record? Should there be some division of them amongst a couple of tables to make a proper RDBMS?