-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
[SOLVED] Help setting data in header file from a seperate file
mikesta707 replied to rickphp's topic in PHP Coding Help
well you can do $url = $_SERVER["REQUEST_URI"]; that will give you the page you are on (for example if at www.mysite.com/news.html that will return news.html) and you can do a switch statement to decide which gets the class -
hmm, do a print_r on new_genres maybe. And post the code between the while loop and the function call. Do you alter the variable in anyway before the function call?
-
ahh ok, well then for ($i = 0; $i < 10; $i++){ //this will repeat 10 times, but we need to change it //so that you get a different random number each time. //what is the acceptable range of id numbers? $id = rand(0,10); $temp = $id*$i; $temp += (100 - $temp > 10) ? rand(0,10) : 0; $id=$temp; $sql = sprintf("SELECT * FROM test WHERE id='$id'"); $rs = mysql_query ($sql, $conn); while ($row = mysql_fetch_array ($rs)){ echo ("Question 1: " . $row["question"] ."<br><br>"); echo ("A: " . $row["answer1"] ."<br>"); echo ("B: " . $row["answer2"] ."<br>"); echo ("C: " . $row["answer3"] ."<br>"); echo ("D: " . $row["answer4"] ."<br>"); } } btw these lines $temp = $id*$i; $temp += (100 - $temp > 10) ? rand(1,9) : 0; but this will get questions in intervals. like if $i is 1, it will choose from 11-20, if $i is 2, 21-30 and so on. I'm sure there is a better way, but this is how I would do it off the top of my head. if you give me a little while I can probably come up with a better solution
-
much like password, you didnt assign the variables any value from the post data, so they are blank for firstname you should do something like $firstname = $_POST['firstname'];
-
[SOLVED] basic $result = mysql_query problem
mikesta707 replied to unistake's topic in PHP Coding Help
.... session_start() is ussed for sessions, not mysql connections. I suggest you read a simple tutorial on php and mysql if you don't know how to connect to a mysql database, but it should look something like $conn = mysql_connect("localhost", "username", "password") or die(mysql_error());//connect to mysql $select = mysql_select_db("test") or die(mysql_error());//select the database "test" //now we can do some queries -
[SOLVED] Calculate (add) all integers from mysql rows
mikesta707 replied to keldorn's topic in PHP Coding Help
then you probably aren't returning any rows from that query. I'm going to assume that you indeed have rows that were added on this day. so make sure that you have the format of your date right, and its as you expect. Oh and one thing. I'm going to assume your date column is a varchar data type? Well since you don't surround it with quotes in your query, it may be assuming its an int (or rather it would be an equation, 2009 minus 9 minus 10) try $Hits = mysql_query("SELECT * FROM links WHERE date='" . $date . "' ORDER BY id DESC LIMIT 0,500") or die('Could not connect: ' . mysql_error()); and see if that helps also echo your query before it executes to make sure its what you expect it to be -
in this area of code if ($_POST['password'] == $_POST['password2']) { //create new user, disabled $username = mysql_real_escape_string(str_replace(' ', '_', $_POST['username'])); you never seem to set the $password variable, which is what you are passing into the encrypt function. try doing this if ($_POST['password'] == $_POST['password2']) { //create new user, disabled $username = mysql_real_escape_string(str_replace(' ', '_', $_POST['username'])); $password = $_POST['password']; and it should work. by the way you are encrypting your password twice. Wasn't sure if you were aware or not just letting you know.
-
[SOLVED] Help setting data in header file from a seperate file
mikesta707 replied to rickphp's topic in PHP Coding Help
are the links static URLS, like <a href="mysite.com/news.php">news</a> or dynamically gotten via get variables like <a href="index.php?id=news">news</a> ? -
[SOLVED] basic $result = mysql_query problem
mikesta707 replied to unistake's topic in PHP Coding Help
either your user ODBC doesn't have the correct permissions or you set his login name and password wrong. should the password be "NO"? -
... post all the code. what you posted doesn't even have any code in it. Errors are best spotted when you see the erroneous line, and the context it's in, but all I see is the header line and some comments, with a die...
-
[SOLVED] Calculate (add) all integers from mysql rows
mikesta707 replied to keldorn's topic in PHP Coding Help
post your updated code and let me see. Assuming the query was the same, and it worked out, it should calculate correctly. Also, why did you put an exit() inside the while? -
do a print_r on the $orig_genres before you call that function. see what it holds. this line $orig_genres[] = $row[0]; is correct, in that it will push the value of $row[0] in the $orig_games array. Idk what else is happening to it afterwards tho, so try a print_r and maybe post the code after that while loop
-
well whats the range for acceptable ID numbers? 1-4? once You know that do something like for ($i = 0; $i < 10; $i++){ //this will repeat 10 times, but we need to change it //so that you get a different random number each time. //what is the acceptable range of id numbers? $id = rand(0,4); $sql = sprintf("SELECT * FROM test WHERE id='$id'"); $rs = mysql_query ($sql, $conn); while ($row = mysql_fetch_array ($rs)){ echo ("Question 1: " . $row["question"] ."<br><br>"); echo ("A: " . $row["answer1"] ."<br>"); echo ("B: " . $row["answer2"] ."<br>"); echo ("C: " . $row["answer3"] ."<br>"); echo ("D: " . $row["answer4"] ."<br>"); } }
-
post your code? but you seem to be passing an empty string into the mcrypt function... if you read the error code. check to make sure the string you are passing into the function is populated with data. try echoing before you call the function. as far as the header error, its completely unrelated, and caused because you are outputting something before the call. The header must be sent before any output (basically before any echos, and before the body tag of your HTML)
-
[SOLVED] Calculate (add) all integers from mysql rows
mikesta707 replied to keldorn's topic in PHP Coding Help
that won't work. mysql_fetch_assoc returns only 1 row at a time. that will try to add together all the entries in the array from that row. the array will look something like $arr['id'] = 2; $arr['date'] = some date; $arr['hits'] = 240; you're code probably won't even execute because it expects an array as the parameter and you are supplying an integer -
loading text file with html formating into a textarea
mikesta707 replied to mccormr7's topic in PHP Coding Help
what is $story? I dont see anywhere where its set. also wrap your code in code tags in the future, it makes it easier to read echo $somecontent before you write it to the file and see what happens? -
[SOLVED] Calculate (add) all integers from mysql rows
mikesta707 replied to keldorn's topic in PHP Coding Help
$count = 0; while ($line = mysql_fetch_assoc($Hits)) { $count += $line['hits']; } echo $count; ? -
Reading from stdClass Object within an array
mikesta707 replied to saucypony's topic in PHP Coding Help
if you are familiar with OOP, the -> operator in PHP is similar to, say, the "." operator in languages like C++ and java. It basically is a way to access member functions and variables in an abject. for example say I have a simple class class foo { public $variable = "Hello "; private $variable2="world!"; function bar(){ echo $this->variable2; } } Note how we used $this->variable2. that means access the variable "variable2" in "this" class. If we were to instantiate the class in a program, we would access the functions and public variable like so $foo = new foo(); echo $foo->variable; $foo->bar(); that would echo "Hello world!" this is very similar to, say, javascript, where you can access an objects function like so array.split(); but instead of "." we use ->. The dot character in PHP is used for string concatenation. -
people with dynamic IP's will run into problems because they will be prompted to get another coupon. This also won't work with people who clear their cookies or have them disabled. Also if you use cookies people can easily alter the cookies. Using a member system to decide will be the best way in my opinion.
-
loading text file with html formating into a textarea
mikesta707 replied to mccormr7's topic in PHP Coding Help
post code? but stripslashes() might do the trick for you -
I think it would cast the string as an int in that comparison, and all strings get cast to 0 if i'm not mistaken. So do this $ratedavg = $postedear['average']; and see if it helps. There is no reason to surround the data with quotes anyways, as if its a string it will be treated as such when assigned, and if its an int it will be treated as such, but forcing it to be a string always can run into problems
-
im assuming that the messages get stored in some sort of table. Before you add the messages to the table, just check to see if the message is there already. if not add it, if so don't.
-
your use of quotation marks is wrong, and its terminating the string prematurely echo "You may book this"."<a href=\"#\" onclick=\"openbox('E-mail directly', 1)\">here</a>"; you want to escape your quotation marks that are inside the string. alternatively you can use single quotes, but I prefer to escape my doule quotes. its all personal preference really
-
temporarily banning the IP from logging in in my opinion. or via sessions/cookies, though cookies might be a less secure alternative
-
well in that script $bt never seems to be set. but beyond that it looks fine to me. make sure you set $bt to zero before the foreach, and test it.