Brendan
Members-
Posts
26 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
Brendan's Achievements
Member (2/5)
0
Reputation
-
The problem with the reference is I would still have to create/define the array within the main() function. I want the main function to be more flexible, which means I need to define the array outside of the main() function because the array will vary depending on what I am calling the function for. The whole point of the function is so I can have a function that lists information from a mysql database and puts it into an html table format. Sometimes I will want to, for example, explode a date and location and put them together in one table row element (<td>). So in the example script on the post above, for example, I would want to insert a custom function into the foreach loop, from outside of the main() function, that will use the sql while loop's variables even though i'm creating a custom function or array outside of the main() function. So I want to reference variables that technically aren't yet created when I define the variable outside of the main() function, but are there when I call them inside of the foreach loop.
-
I have tried that, such as with the following script: function main($array){ $sql=mysql_query("$sql_query"); if(!empty($sql)){ while($row=mysql_fetch_array($sql)){ foreach($array as $key => $value){ print $array[$key][value]; } } } } $array[1][value]=$row[value]; $array[2][value]='test'; However it is still the same result, the array was still created before it is passed to the function so the $row[value] was still interpreted as empty before it reached the function.
-
function main(){ $sql=mysql_query("$sql_query"); if(!empty($sql)){ while($row=mysql_fetch_array($sql)){ foreach($array as $key => $value){ print $array[$key][value]; } } } } $array[1][value]=$row[value]; $array[2][value]='test'; I want array[1] to return the content of the MySql field "value" while array[2] just return the word "test" however the array is set outside of the mysql loop (and it has to be since the function main() is included from a different file) The code I have shown above doesn't work since $row[value] isn't yet defined. How would I go about doing this without including the array anywhere in the main() function?
-
The code works fine on the webserver, the timeout is due to slow processsing of the code so it's not a loop problem. Anyone know potential ways of solving this?
-
I am unaware if this is a mysql or php issue, but my test server is on a windows xp machine and runs extremely slow when processing the two. The home page of the site, which involves very little php/mysql runs fairly quickly. The database and php code work quickly on the webserver, and i actually have php on the my local test server connect to the webservers mysql database for testing. It is slow to the extent that I get the "Fatal error: Maximum execution time of 60 seconds exceeded." frequently.
-
Does anyone know what could have caused this...?
-
Hello all, i'm upgrading my servers from php4 to php5, and have an upload script left unworking. Rather than upload a file, it just refreshes the page and clears the form after it reads the file. <?php include("../login.php"); ?> <html><head> <script language="javascript" src="../functions.js"></script> <style type="text/css"> html, body, td { background-color: #364962; color: #ffffff; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: bold; } INPUT, TEXTAREA { background-color: #ffffff; border-color: #000000; border-style: solid; border-width: 1px; color: #000000; padding:2px; height:18px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: normal; } SELECT { background-color: #ffffff; border:1px solid black; color: #000000; height:18px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: normal; } OPTION { background-color: #ffffff; border:0px solid black; color: #000000; } .Radio { background-color: #ffffff; border-width: 0px; color: #000000; } </style> <?php require("../functions.php"); $filename=$_POST["filename"]; $overwrite!="ON"; $description=$_POST["description"]; $submit=$_POST["submit"]; $userfile=$_FILES['upload']; $filename=stripslashes($filename); $description=stripslashes($description); $dirval='/home/user/directory/files/'; $sql=mysql_query("select * from users where id='$id_iq'"); if(!empty($sql)){ $row=mysql_fetch_array($sql); $username=$row["username"]; $level=$row["level"]; } $sqlnum=mysql_query("select * from example where username='$username'"); $sqlnum= mysql_num_rows($sqlnum); if ($level = 1) { $maxfiles = "5"; } else if ($level=2) { $maxfiles = "10"; } $maxsize = "7340032"; if ($submit) { if ($sqlnum < $maxfiles) { if (!empty($filename)) { if($submit && $userfile && $userfile['size']!=0) { //If a file is uploaded... $filename = $id_iq.'_'.$userfile['name']; $filename_temp = explode(" ", $filename); $filename = implode("_", $filename_temp); $size = $userfile['size']; $error = $userfile['error']; if ($size<=$maxsize) { if($error!=0){ //If an error occured then... showerror('Error'); } if (file_exists($dirval.$filename)&&$overwrite!="ON") { //Check if the file already exists... showerror('File already exists'); //Or display error } else { $ext = substr($filename, strrpos($filename, '.') + 1); $ext = strtolower($ext); if($ext=="doc"){ $correctfile=true; $correctformat=true; } else { $correctfile=false; $correctformat=false; } if ($correctfile) { $uploaded=move_uploaded_file($userfile["tmp_name"], $dirval.$filename); //Move the uploaded file } //print '<hr>Uploaded'.$uploaded.'<hr>'; if (file_exists($dirval.$filename)){ //Check if the file is uploaded $filename=str_replace('"', '', $filename); $filename=addslashes($filename); $description=addslashes($description); $sqladdmusic =mysql_query("INSERT INTO example ( `username` , `filename` , `filename` , `description` , `server` ) VALUES ( '$username', '$filename', '$filename', '$description', '1')"); showerror('Succesfully uploaded "'.$filename.'"!'); refresh(); } else { if ($correctformat!="true") { showerror('Sorry, file type not allowed.'); } else { showerror('Couldn`t upload "'.$filename.'"'); } } } } else { showerror('Files over 7 MB are not accepted.'); } } } else { showerror('Please enter a file name.'); } } else { showerror('You already have '.$maxfiles.' files uploaded.'); } } $filename=stripslashes($filename); $description=stripslashes($description); ?> <title>Upload File</title> </head> <body bgcolor="#6787B3"> <FORM NAME="sendfile" onSubmit="uploadconfirm();" ENCTYPE="multipart/form-data" ACTION="upload.php" METHOD="post"> <font style="font-size:11px; font-weight:bold;"> MAX filesize: 7 MB<br> You may upload up to <?php print $maxfiles; ?> files total.<p> </font> <input type="file" tabindex="1" name="upload" size="30"><br> File Name<br> <input type="text" tabindex="3" name="filename" value="<?php print $filename; ?>" size="20"><br> Description<br> <textarea name="description" tabindex="4" style="width:300px; height:200px;"><?php print $description; ?></textarea><br> <input type="submit" tabindex="6" name="submit" value="Upload" >   Upload may take a few moments.</center> </form> </body> </html>
-
That's correct, thorpe, but it is a problem with the way the new Firefox browser handles sessions. Internet Explorer handles it correctly, whereas Firefox does not. I tried adding the exit; though it simply kept me from logging in with a second username at all and instead redirected me to the login page if i had already logged in with another username.
-
Yup, that doesn't work either surprisingly. Maybe revealing some more code will help: [code] <?php require_once 'script.php which initiates session_start() and mysql' $php_self=$_SERVER['PHP_SELF']; $http_host=$_SERVER['HTTP_HOST']; $loginusername=$_POST["loginusername"]; $password=$_POST["password"]; $submit=$_POST["submit"]; $userid=$_SESSION["userid"]; if($submit){ $sqllog=mysql_query("SQL Query, this part is tested and works; the results are correct "); $row=mysql_fetch_array($sqllog); $num=mysql_num_rows($sqllog); if($num==1){ $_SESSION["userid"]=$row["id"]; header ("Location: http://$http_host/login/userhomepage.php"); } else { header ("Location: log_in.php?status=wrongid"); } } if (!isset($_SESSION["userid"]) or empty($_SESSION["userid"])) { session_write_close(); header ("Location:http://$http_host/login/logout.php"); } if (isset($_SESSION["userid"]) and !empty($_SESSION["userid"])) { $sql=mysql_query("Sql query to select user'"); if(!empty($sql)){ $row=mysql_fetch_array($sql); $username=$row["username"]; $_SESSION["viewuser"]=$row["username"]; } } ?> [/code] This code is included in every members-only page.
-
For some reason php5 and Firefox don't seem to get along when it comes to sessions. I have finally gotten them to start, but can't seem to destroy them. I have put the following code into a script named logout.php. <?php session_start(); session_unset(); session_destroy(); $http_host=$_SERVER["HTTP_HOST"]; header ("Location: http://$http_host/index.php"); ?> Yet when i try to login with a different username, the old username is still logged in. Also, when i go back to a page after logging out it is still loaded when it should redirect to the login page. How about a simple solution, anyone? Perhaps i am overlooking something.
-
Could CHMOD perhaps be used in some way?
-
I am still curious as to a possible solution to this problem. Thanks
-
A user can upload a song which can be played through a flash player. They also can choose whether or not the song can be downloaded by users. The problem is, if you were to download a program which found the url of the streaming song, you would be able to simply type the url into your browser and download the song. So i am wondering, how do you prevent the downloading of certain music files from the browser, but allow the streaming of the song through a flash player?
-
where category='1' AND price>'61.00' AND price<='100.99' ORDER BY prod DESC I've tried that, but this doesn't seem to work.
-
How would i go about searching a mysql database for a value greater than one number and less than or equal to another, and visa versa? For Example if ($price=="3") {$op.="(price>61.00 && price<=100.99)";} This doesnt work of course, but perhaps it will give an idea of what im trying to achieve. Thanks, -Brendan