-
Posts
1,216 -
Joined
-
Last visited
Everything posted by WebStyles
-
Override default temp directory in php
WebStyles replied to t8mas062184's topic in PHP Installation and Configuration
I'm guessing it's for file uploads? you can configure the tmp directory in php.ini -
opps, sorry, did it from memory without checking the manual. let this be a lesson to me
-
check out the date function on php.net. all the options are there and nice ly explained. basically the format you want is something like: date("d l Y");
-
well, yeah... so far so good. basically you want to use mysql_real_eacape string before you insert, update or select stuff from a database, when the query is based on user input values.
-
I'd rather explain again than give you the code. This is your original code: (just the while loop) while($row = mysql_fetch_assoc($query)) { $to_str = ""; $navn_arr = $mail_arr = array(); $navn = $row['fornavn'] . " " . $row['efternavn']; $mail = $row['email']; $to_str .= ", $navn <$mail>"; $navn_arr [] = $navn; $mail_arr [] = $mail; print_r ($navn_arr); print_r ($mail_arr); } this line: $navn_arr = $mail_arr = array(); is the same as doing this $navn_arr = array(); $mail_arr = array(); and it's just saying "make these two variables be empty arrays" at the bottom, when you do this: $navn_arr[] = $navn; $mail_arr[] = $mail; you're adding stuff to each of those arrays. As I said before, since everything is inside a while loop, you're starting with an empty array, then adding stuff, then emptying it again (because the while loop repeats all the code inside the curly braces {} as many times as necessary), so you en up just having the last line from the database stored in those arrays. Since you also have both print_r() statements inside the loop, it will print every line from the database for you (but will only store the last) what you want is to initialize the arrays before the loop. Hope this helps
-
initialize your arrays before the while loop, not inside it.
-
This line $navn_arr = $mail_arr = array(); is resetting both arrays inside the loop, so basically what you're doing is: 1. reset arrrays 2. add data to arrays 3 reset arrays 4 add data to arrays... etc
-
Need some help with user notification email?
WebStyles replied to andy_b_1502's topic in PHP Coding Help
Your variables are passed using the POST method, so you need to grab them all like this: $company_name = $_POST['company_name']; before you can insert them into a database. for sending an email, check out the mail function -
I didn't look at your code, but could it be that you're reaching the allowed upload limit and the last 4 or 5 images are not being sent ?
-
Sum of the value getting from array in foreach
WebStyles replied to Sanjib Sinha's topic in PHP Coding Help
you have the same value="1" in all of them... you could use that field for the price: <input type=”checkbox” name=”book[0][0]” value=”5.00″> Book1 <br> <input type=”checkbox” name=”book[0][1]” value=”7.00″> Book2 and then use something like: $sum = 0; foreach($_POST['book'] as $price){ $sum += $price[$i]; } -
this line is also wrong: (double quotes again) line 148. $queryud = mysql_query("UPDATE Jogadores SET Lesao = "S" WHERE IDJogador = '$jogc' ", $db) ; (I would seriously consider re-writing the whole thing, because none of it makes much sense. What you have in the entire page could be done in a much better way, more efficient, faster and with less than half the lines of code you have.)
-
You have another error on line 84: this: $jogcd = ff['Dado'] ; is missing the $ before the variable name. at another quick glance, all your queries do not need the while loop this: $qec = mysql_query("SELECT IDEquipaC FROM calendario WHERE Jornada = '$jornada', Liga = '$liga', Jogo = '$jogo' ", $db) ; while($ab = mysql_fetch_array($qec)) { $equipac = $ab['IDEquipaC'] ; } is basically selecting all rows that match your criteria and replacing the value of $equipac every time. I'm guessing that query only returns one reult, so it should be something like this: $qec = mysql_query("SELECT IDEquipaC FROM calendario WHERE Jornada = '$jornada', Liga = '$liga', Jogo = '$jogo' limit 1", $db) ; $ab = mysql_fetch_array($qec); $equipac = $ab['IDEquipaC'] ; The same can be said about ALL the other queries
-
can you post the EXACT code you have now please? (the whole page)
-
this line: echo "A equipa da casa não tem saldo negativo; "<br>" ; has an extra double quote that should not be there! in portuguese: tens umas aspas a mais nessa linha. Oh, and the line happens twice in your code.
-
you can set different names during your SELECT but you need the field names for that, so you won't be using SELECT * instead you use something like : "SELECT students.fName as SfName,teachers.fName as Tfname FROM students LEFT JOIN teachers ON students.teacherId = teachers.teacherId" then u use the new names: $row['SfName'] and $row['TfName'] (SELECT * is bad anyway)
-
you title says , so your logic is correct, you know what you want to do, but you don't have a single JOIN in your query. maybe you should read this: http://dev.mysql.com/doc/refman/5.0/en/join.html Also: you query ends with AND
-
Just an idea, since you cannot find any code with INSERT's: ... maybe you have a trigger set on another table that's inserting stuff into your users table?
-
str_replace works for me, as long as you have the correct encoding. I did this little page to test it: <?php mb_internal_encoding("UTF8"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> </head> <body> <form action="" method="post"> <textarea name="inputText"></textarea> <input type="submit"> </form> <br /> <?php if(isset($_POST['inputText'])){ $text = $_POST['inputText']; echo stripslashes(str_replace("Â","A",str_replace("“","",str_replace("”","",$text)))); } ?> </body> </html> it outputs the same, with Â's converted to A and word's curly quotes removed. Note: I used stripslashes just to see the output because the single quotes were escaped, but you definitely want to use something like mysql_real_eacape_string before inserting something like that into a database. Hope this helps
-
Get a list of unique variables from a script
WebStyles replied to mrherman's topic in PHP Coding Help
this will search and print out for any code starting with $ and ending with a space. it's not perfect though, cause if you have something like this $var="whatever"; there is no space after the variable. But it's a start. All your variables should show up on the list, except some will have other stuff after them. replace index.php for your file's name and place them in same directory. <?php $file = file_get_contents('index.php'); //echo $file; preg_match_all('/\$(.*?)\\s/is', $file, $matches); echo implode("<br>",$matches[0]); ?> Hope it helps EDIT: you can also apply array_unique to filter out duplicates. -
Just tested, the result is the same, it picks a random entry from the line containing the ip address. (this time it's really random, after each refresh it will pick a different name) thanks.
-
Hi guys. This is my first question on phpFreaks (the other 900+ posts I've made were always an attempt to help someone else) Here's the issue: when using gethostbyaddr($_SERVER['REMOTE_ADDR']) on a local machine (current using MAMP on OS X) the name returned is not the first entry in my /etc/hosts file. (On php.net there's another person also commenting on this and saying that apparently gethostbyaddr selects a random entry from the file.) This is not really an issue, since everything will work fine on my FreeBSD production server where each IP address has only one DNS record (I'm building the company's intranet, so I know exactly what's in our DNS tables) but I'm curious to know if anyone has had the same issue/problem and if there's a way around it. (Logic/Common sense tells me the first record should be the one returned) Currently I have the following information in my /etc/hosts file: 127.0.0.1 localhost 127.0.0.1 iSy 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost # Other names for testing purposes 127.0.0.1 name1.blablabla.com 127.0.0.1 name2.blablabla.com 127.0.0.1 name3.blablabla.com 127.0.0.1 name4.blablabla.com 127.0.0.1 name5.blablabla.com 127.0.0.1 name6.blablabla.com 127.0.0.1 name7.blablabla.com 127.0.0.1 name8.blablabla.com the value returned is always line 8: name2.blablabla.com. If I comment out that line, then it moves 'randomly' to line 12: name6.blablabla.com and sticks with it even if I shut down the servers and then boot up again. any ideas? cheers.
-
You want to choose a user and show the projects that belong to him/her? Since you said project_client stores the user id's... (assuming the user's id is in a variable called $userID) $sql_get_projects=mysql_query("select `project_id` from `tbl_projects` where `project_client` = '$userID' order by `project_id`",$makeconnection); while($result = mysql_fetch_assoc($sql_get_projects)){ echo $result['project_id'].'<br />'; } @mysql_close($makeconnection);
-
hmmm... just answered the same question in your duplicate post. (you shouldn't do that!!!) anyway, this one says you want the wrong answers along with what should have been the correct answer... so change this line: echo "$num1 * $num2 === $answer <br />"; to: if(($num1 * $num2) != $answer) echo "$num1 * $num2 === $answer | Correct answer was: <b>".($num1 * $num2)."</b><br />";
-
At a quick glance, this: $result = mysql_query("Select gebruiker_id from Owner where gebruiker_id ='".mysql_real_escape_string($_SESSION['user_id'])"'"); should be: $result = mysql_query("Select gebruiker_id from Owner where gebruiker_id ='" . mysql_real_escape_string($_SESSION['user_id']) . "'"); (period missing after mysql_real_escape_string)
-
Since you're already using ajax, this should be easy for you. You can grab the content with javascript using something like: var content = document.getElementById("DIVNAME").innerHTML; then use ajax to post it to a php script for processing.