DavidAM
Staff Alumni-
Posts
1,984 -
Joined
-
Days Won
10
Everything posted by DavidAM
-
I just loaded an ODBC driver for mySql, then linked the mySql tables into Access and ran INSERT queries to transfer the data. Of course, I had to create the mySql tables manually, first.
-
Think about the code you write. That statement says: "If the user did NOT upload a file, then record the name of the file they DID upload"
-
While I agree 100% with Barand, I do think the flat-file concepts are very important. At some point in the future, you will have to read a flat-file to bring data into your database, or write a flat-file from data in the database (for someone else). So, don't give up on understanding the file system and flat-file use. And, as I understand your intent right now (to learn), even working to allow updates to that flat-file will benefit you in understanding how file operations behave.
-
You need to check $_POST['file_upload'] itself. Although, I think it will always be set as well, so you want to check to see if it is empty. Or check to see if your $file_upload variable is empty.
-
mysqli fetch_all() and fetch_array() errors
DavidAM replied to nodirtyrockstar's topic in PHP Coding Help
mysqli_fetch_all() is only available with the native driver. I've never used it (fetch_all(), that is). I've never really wanted to use it. Even for populating dropdown selections, I just use a loop. I don't think you will see enough benefit to justify the time and effort to reconfigure PHP.- 4 replies
-
- mysqli
- fetch_all()
-
(and 1 more)
Tagged with:
-
mysqli fetch_all() and fetch_array() errors
DavidAM replied to nodirtyrockstar's topic in PHP Coding Help
fetch_array() will return only one row. You need to use it in a loop to process all of the rows: $query = "SELECT `artist` FROM `bands`;"; $result = $mysqli->query($query); while ($bandArr = $result->fetch_array(MYSQLI_NUM)) { printf("%s\n", $bandArr[0]); } Of course, since you are only selecting one column, there will only be one element in the $bandArr array (it will be element zero).- 4 replies
-
- mysqli
- fetch_all()
-
(and 1 more)
Tagged with:
-
There are several issues with that code, not the least of which is indentation (which could be the fault of the "WYSIWYG" editor). Here is an outline (using your code) of how you can accomplish this. $query = "SELECT * FROM eventjobs WHERE organiserid = " . intval($_SESSION['userID']) . " LIMIT 10"; /* This assigns the resource (or FALSE) to $result AND tests if the query succeeded NOTE: The query WILL succeed if there are NO ROWS found */ if ($result = mysql_query($query)) { // if (empty($organiserid)) # As you have seen this is not useful // Check to see if there were ZERO rows returned if (mysql_num_rows($result) == 0) { echo 'You have no events. Create an event.'; } else { /* You were only processing the first row. You need a while loop */ // $row = mysql_fetch_array($result); while ($row = mysql_fetch_assoc($result)) { ?> <div class="eventjoblistings"> AND SO FORTH </div> <?php } // END while ($row = } // END if (mysql_num_rows ( } // END if ($result = mysql_query(
-
Where exactly does it "come out" with a backslash? In the database? In a web page? Somewhere else? You should be using an appropriate escaping function, such as mysql_real_escape_string, before writing a value to the database. But you should not be using that same function on data being sent to a web page. Which means you should only escape for the database when building the query. WRONG $name = mysql_real_escape_string($_POST['name']); $sql = "INSERT INTO table VALUES('$name')"; echo $name; NOT WRONG $name = $_POST['name']; $sql = "INSERT INTO table VALUES('" . mysql_real_escape_string($name) . "')"; echo htmlspecialchars($name);
-
How to get number of days in a month and also knowing a leap year
DavidAM replied to 50r's topic in PHP Coding Help
$days = date('d', mktime(0, 0, 0, $month + 1, 1, $year) - 1) -
func_get_args
-
Help with deleting records using a form with checkbox type inputs.
DavidAM replied to kdigital's topic in PHP Coding Help
No question No error message Just naked code hung out there for the world to see How pretty -
Modulo is a mathmatical term referring to the remainder when one number is divided by another: 3 modulo 2 = 1. Using the percent-symbol -- the usual operator for modulo -- as the delimiter in a regular exp-ression does not constitue the use of "modulo". That RegEx only verifies that the characters are valid (well, if you take out the underscore). There's no real reason to do the split and use a for loop for that. if (! preg_match('%^[A-Z0-9-]{8}$%i',$plate)) return false; If you then split on the dash, you can use a pair of checks on each component. One check for letters and one check for the digits. Using the anchors (start and end of string) to be sure.
-
The modulo tip also threw me. I can't think of any way it would be useful. However, if the example "XX-XX-XX" is a fixed format (i.e. it will always be three sets of two characters separated by dashes), then you could explode on the dash and test each pair of characters. But the wording of the problem (as stated above) does not explicitly indicate that the format is fixed, i.e. XXX-XXX- is also valid. But again, you can explode on the dashes and test each set of characters (it's just that the character set size is variable)
-
cant connect my results page to connect with mysql database - Help!
DavidAM replied to Glasgow-Guy's topic in MySQL Help
If you know there are other PHP scripts using the database, you might hunt down the connection code they are using. It might give you a clue. Basically, the process is: 1) Connect to db server, 2) Select Database, 3) run queries. You are not getting past step one, so the fact that you are using a different database is not significant (yet). If there are other scripts that do get past step 1, then the configuration may not be wrong. It may be that the "host" name needs to be very specific or include or port number or something. Looking at a working script my give you the hint. -
cant connect my results page to connect with mysql database - Help!
DavidAM replied to Glasgow-Guy's topic in MySQL Help
Port 8080 is an alternate HTTP port. HTTP is the Hyper Text Transport Protocol which is used for WEB pages. Connecting to a mySql database server has NOTHING to do with HTTP. The error message indicates a problem with the configuration. Perhaps the mySql socket is not where PHP thinks it is. I think you need to talk to your host about this. It may require a change to the mySql configuration file or the PHP configuration file, or both. Give them the complete text of that first error message, and see what they say. -
cant connect my results page to connect with mysql database - Help!
DavidAM replied to Glasgow-Guy's topic in MySQL Help
I fail to see what that has to do with anything. The problem is that the database connection is not coded correctly. You do not use the "http://" scheme for logging in to a mysql database. On most hosts you just use "localhost", sometimes you can use the actual domain name (without the "http://" scheme and without the "www." subdomain) That first error message indicates the connection failed. What error, if any, do you get if you use "localhost"? -
Unless I am mistaken, a DIV does not have a value (.val()). I think you need to use .html().
-
After Submiting, Formtoemail.php Return Error At Php Closure(?>)
DavidAM replied to PrPrO's topic in PHP Coding Help
"clean_string" is NOT a PHP (built-in) function. You were calling it in your original code that you posted. It is probably defined in some file that you need to include. I don't see any include statements in your posted code, I figured the include statements were in some part of the code that you did not post. -
After Submiting, Formtoemail.php Return Error At Php Closure(?>)
DavidAM replied to PrPrO's topic in PHP Coding Help
The $ime variable does not exist. In fact, none of the variables that you pass to clean_string have been defined. It would appear that your script expects register_globals to be on, which is a BAD thing. This setting has been deprecated for some time. It is a security issue. To access the fields from your form, you need to refer to the $_POST array. You have tested for them at the beginning of the script, you need to use them in the same way: $email_message .= "Ime: " . clean_string($_POST['ime']) . "\n"; -
Php Issues? Php Not Receiving Post Data From Htmll Form
DavidAM replied to gdisalvo's topic in PHP Coding Help
Yes, you can have both. The IP Address 127.0.0.1 is, by standard, defined as the "loop-back" address. It loops back to the machine that sends to it. It should be active on any computer that has a network card. The host name localhost is typically assigned to this address. The assignment is made in the /etc/hosts file. There is no requirement that it be there, but it usually comes that way (in my experience). The /etc/hosts file is a lookup file used by the networking layer. Think of it as a simple DNS lookup table that is specific to your system. It is used before going out to the DNS servers. It will be searched when using the browser, or any other application that needs an IP address from a hostname. -
I would not reset any counters, nor is there a need to. I would create a table containing the userID and the loginTime (DATETIME). Then everytime someone logs in, you insert a row to this table. You can easily query the table for a count by user where the loginTime is between the start and end time values for the week. In my experience, about 15 minutes after you hand the first report to the boss, he will say; "you know what, I just want to see this at the end of the month" --- or something like that with some other date range. By logging the logins, you can provide just about any report he asks for. --- "Give me the counts by user of those that logged in on the weekends" (i.e. who are my hard workers?). And, don't just give him each report he asks for. Tell him it will take a day or two, and then give it to him first thing in the morning. If you do it right away, people start expecting immediate results, and soon the world will learn that computer programmers are not really as vital as everyone thinks, because they will believe everything is easy, and you will ruin all of our lives.
-
Each invocation of the function is a separate occurance and gets its own local variables. The recursive call is NOT modifying $a. For that matter, you are not modifying it locally. If you want the recursive call to affect the local variable, you would have to pass by reference or return it: function f($a) { if($a<2) { echo "before:".$a."</br>"; $a = f($a+1); echo "after:".$a."</br>"; } return $a; } f(0);
-
Query Using Mysqli Is Returning "field List" Error From $_Get
DavidAM replied to atticus's topic in PHP Coding Help
You need to put quotes around your string values in the VALUES clause. Without the quotes, mysql thinks they are column names. You also need to escape them using mysqli_real_escape_string. -
If you are using Apache, you might have a look at the Alias (and Directory) directives for the configuration files. This is how the default installation makes the Apache documentation available from the local server without putting the files in your document root. Otherwise, any file you want from that "protected" directory must be read by a script in the publicly accessible area and passed through to the browser. That also means that all links in the "protected" files to other "protected" files must use the same approach. And, for the record, I advise against putting the entire path name in the url. This gives hackers some information about your server that your really do not want them to have. I would use something like getimage.php?file=imagefile.jpg&chapter=1 and then have the getimage.php script decide how to build the full path.