Jump to content

Brendan

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by Brendan

  1. 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.
  2. 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.
  3. 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?
  4. 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?
  5. 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.
  6. Does anyone know what could have caused this...?
  7. 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" > &nbsp Upload may take a few moments.</center> </form> </body> </html>
  8. 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.
  9. 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.
  10. 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.
  11. Could CHMOD perhaps be used in some way?
  12. I am still curious as to a possible solution to this problem. Thanks
  13.       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?
  14. 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.
  15. 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
  16. Hey, im just curious as to what the best way to upload image files is from an upload form. If i were to upload them directly to a mysql database it would use up the mysql database more than i would want. If i were to upload it to the server and have an entry in mysql which would point to each file, then i'm afraid the files and mysql entries could get mixed up or something to that extent, such as the file being created but having an error where a mysql entry isnt created. Any suggestions?
  17. This is the code that i have so far; i can't seem to output a valid array. You can see where i have the code $q = implode(",", $sizes); and print $q;. This should output 4,2,5, ect. depending on what the user typed into the form, but it displays nothing at all, it's empty. It doesnt seem to be valid outside of the while loop for some reason. [code]<?php include("login.php"); $formdisplay="show"; $font="#000000"; $redf="#DD7171"; $font_color=$font; $msg="Use this form to add a product to the inventory."; if (!isset($size_fields)) { $size_fields=""; } $pid=$_GET['pid']; <<removed some post and mysql values that were here>> if(($_POST['add_sizes']) or ($_POST['submit'])){ if($_POST['add_sizes_amount']<10){ $ii=$_POST['add_sizes_amount']; $i=$ii+$current_array; if ($_POST['submit']) {$i-=$ii;} $current_array=0; while ($i>0) { $current_array++; $i--; $temp='sizes'.$current_array; $sizes_val_final=$_POST[$temp]; $sizes=array($current_array => $sizes_val_final); $temp2='stock'.$current_array; $stock_val_final=$_POST[$temp2]; $stock=array($current_array => $stock_val_final); $size_fields.=' Size:  <input name="'.$temp.'" style="width:50px;" type="text" value="'.$sizes_val_final.'"> Stock: <input name="'.$temp2.'" style="width:50px;" type="text" value="'.$stock_val_final.'"><br><font style="font-size:10px;"> <p>'.$current_array.'<p>'; } $q = implode(",", $sizes); print $q; print $sizes[1]; } else { $msg="Please add no more than 9 fields at a time";} } if($_POST['submit']){ if(empty($brandname)){ $msg="Please fill in the Brand Name field."; $font_color=$redf; } else if(empty($product)){ $msg="Please fill in the Product field."; $font_color=$redf; } else if(empty($productid)){ $msg="Please fill in the Product ID field."; $font_color=$redf; } else if(empty($retail)){ $msg="Please fill in the Retail Price field."; $font_color=$redf; } else if(empty($ordercost)){ $msg="Please fill in the Order Cost field."; $font_color=$redf; } else if(empty($color)){ $msg="Please fill in the Color field."; $font_color=$redf; } else if(empty($category)){ $msg="Please fill in the Category field."; $font_color=$redf; } else { $sql =mysql_query("INSERT INTO SL_products( `product` , `productid` , `retail` , `ordercost`, `color` , `description` , `category` )         VALUES ('$product' , '$productid' , '$retail' , '$ordercost', '$color' , '$description' , '$category' )"); $sql =mysql_query("INSERT INTO SL_quantity( `product` , `productid` , `retail` , `ordercost`, `color` , `description` , `category` )         VALUES ('$product' , '$productid' , '$retail' , '$ordercost', '$color' , '$description' , '$category' )"); $formdisplay="hide"; $msg='Product has been added to the inventory. <a href="http://'.$_SERVER['HTTP_HOST'].'/'.$_SERVER['PHP_SELF'].'>Click here</a> to add another product.'; } } include_once ("../layout.php"); ?>                     <form action="<?php print $_SERVER['PHP_SELF'].'?pid='.$pid; ?>" method="POST"> <table width="100%" border="0" cellspacing="0" cellpadding="0">               <tr>                 <th scope="col">       <table  id="formbg" width="100%" cellpadding="0" cellspacing="0" bgcolor="#95ABCD" id="tb">               <tr>                 <td width="100%" align="left" valign="top" style="padding:10px;"><font color="<?php print $font_color.'">'.$msg; ?></font></td>               </tr> </table> <?php if ($formdisplay=="show"){ ?> <table><tr><td></td></tr></table>             <table id="formbg" width="100%" border="0" cellspacing="0" bgcolor="#95ABCD" cellpadding="5">               <tr>                 <td width="150" align="left" valign="top">Brand Name</td>                 <td align="left" valign="top"> <SELECT NAME="brandname" SIZE="1" tabindex="4"  style="width:200px;"> <?php   $sql = "select * from SL_brands where id='$brandname_final'";   $r1 = mysql_query($sql);   if(!empty($sql)){   $browse = mysql_fetch_assoc($r1);   $brandnameval=$browse['brand'];   } print '<OPTION value="'.$brandname_final.'" SELECTED>'.$brandnameval; ?> <?php   $sql = "select * from SL_brands order by ID asc";   $r1 = mysql_query($sql);   if(!empty($sql)){   while ($browse = mysql_fetch_assoc($r1)) {   $browse['id'];   $brandlist=$browse['brand']; ?> <option value="<?php print $browse['id'];?>"><?php print $brandlist;?> <?php }} ?> </SELECT>   </td> </tr>               <tr>                 <td width="150" align="left" valign="top">Product</td>                 <td  align="left" valign="top" height="30"><input name="product" tabindex="1" style="width:250px;" type="text" value="<?php echo"$product_final"; ?>"></td>               </tr>                 <tr>                 <td width="150" align="left" valign="top">Product ID (QuickBooks)</td>                 <td  align="left" valign="top" height="30"><input name="productid" tabindex="1" style="width:250px;" type="text" value="<?php echo"$productid_final"; ?>"></td>               </tr>               <tr>                 <td width="150" align="left" valign="top">Retail</td>                 <td  align="left" valign="top" height="30">$ <input name="retail" tabindex="1" style="width:150px;" type="text" value="<?php echo"$retail_final"; ?>"> <br><font style="font-size:10px;">Type amount in this format: 29.00.</font></td>               </tr>               <tr>                 <td width="150" align="left" valign="top">Order Cost</td>                 <td  align="left" valign="top" height="30">$ <input name="ordercost" tabindex="1" style="width:150px;" type="text" value="<?php echo"$ordercost_final"; ?>"> <br><font style="font-size:10px;">Type amount in this format: 29.00.</font></td>               </tr> <?php $sqltotal=mysql_query("select*from SL_quantity where productid='$pid'"); if(!empty($sqltotal)){ $totalnum=mysql_num_rows($sqltotal); } if ($totalnum>0) { ?>               <tr>                 <td width="150" align="left" valign="top">Sizes </td>                 <td  align="left" valign="top" height="30"> <?php   $sql = "select * from SL_quantity order by size asc";   $r1 = mysql_query($sql);   if(!empty($sql)){   while ($row = mysql_fetch_assoc($r1)) {   $current_stock=$row['stock'];   $current_size=$row['size'];   $mysql_array+=1; ?> Size: <input name="<?php print 'mysql_sizes['.$mysql_array.']'; ?>"  style="width:60px;" type="text" value="<?php print $current_size; ?>"> Stock: <input name="<?php print 'mysql_stock['.$mysql_array.']'; ?>"  style="width:60px;" type="text" value="<?php print $current_stock; ?>"><br><font style="font-size:10px;"> <p> <?php } } } if (isset($size_fields)) { print $size_fields; } $q = implode(",", $sizes); print $q; print $sizes[1]; if ($totalnum>0) { ?> </td> </tr> <?php } ?>               <tr>                 <td width="150" align="left" valign="top"></td><input type="hidden" name="current_array" value="<?php print $current_array; ?>">                 <td  align="left" valign="top" height="30">Add <input name="add_sizes_amount" tabindex="1" style="width:30px;" type="text" value="1"> more size(s) <input name="add_sizes" type="submit" value="Go"></td>               </tr>               <tr>                 <td width="150" align="left" valign="top">Color</td>                 <td  align="left" valign="top" height="30"><input name="color" tabindex="1" style="width:250px;" type="text" value="<?php echo"$color_final"; ?>"></td>               </tr>               <tr>                 <td width="150" align="left" valign="top">Description</td>                 <td align="left" valign="top" height="30"><input name="description" tabindex="1" style="width:250px;" type="text" value="<?php echo"$description_final"; ?>"></td>               </tr>               <tr>                 <td width="150" align="left" valign="top">Category</td>                 <td align="left" valign="top"> <SELECT NAME="category" SIZE="1" tabindex="4"  style="width:200px;"> <?php   $sql = "select * from SL_categories where id='$category_final'";   $r1 = mysql_query($sql);   if(!empty($sql)){   $browse = mysql_fetch_assoc($r1);   $categoryval=$browse['category'];   } print '<OPTION value="'.$category_final.'" SELECTED>'.$categoryval; ?> <?php   $sql = "select * from SL_categories order by ID asc";   $r1 = mysql_query($sql);   if(!empty($sql)){   while ($browse = mysql_fetch_assoc($r1)) {   $browse['id'];   $browse['category'];   $categorylist=$browse['category']; ?> <option value="<?php print $browse['id'];?>"><?php print $categorylist;?> <?php }} ?> </SELECT>   </td> </tr> </table> <table><tr><td></td></tr></table> <table  id="formbg" width="100%" border="0" cellspacing="0" bgcolor="#95ABCD" cellpadding="5">                        <tr>                           <td width="150">&nbsp;</td>                           <td width="150" align="center"><input name="submit" tabindex="11" type="submit" value="Submit Changes"> </td>                           <td width="150" align="left" valign="top">&nbsp;</td>                         </tr>                       </table>                     <?php } ?>           </table> </form> <?php include_once ("../footer.php"); ?> [/code]
  18. That doesn't seem to work. For example: while ($i>0) { $current_array+=1; $i-=1; $temp='$sizes['.$current_array.']'; $sizes_val=serialize($temp); $sizes_val_final=$_POST['$sizes_val']; $temp2='$stock['.$current_array.']'; $stock_val=serialize($temp2); $stock_val_final=$_POST['$stock_val']; $size_fields.=' Size:  <input name="'.$sizes_val.'" style="width:50px;" type="text" value="'.$sizes_val_final.'"> Stock: <input name="'.$stock_val.'" style="width:50px;" type="text" value="'.$stock_val_final.'"><br><font style="font-size:10px;"> <p>'.$current_array.'<p>'; } print $size_fields; } This doesn't work, and i'm not sure how else to do it. I want to store the value of the text boxes into the sizes[] and stock[] arrays and then return the $_POST information into the value field. Thanks
  19. How would i go about using post with an array? For example: $stock_val='stock['.$current_array.']'; $sizes_val='sizes['.$current_array.']'; print ' Size:  <input name="'.$sizes_val.'"  style="width:50px;" type="text" value="?"> Stock: <input name="'.$stock_val.'"  style="width:50px;" type="text" value="?"><br><font style="font-size:10px;">'; The name fields work fine, but i can't seem to figure out how to use $_POST for the value field with the array.
  20. I have a question involving database and server management. I have a community website in which songs and pictures can be uploaded, and blogs can be created with mysql. Eventually if all goes well, there will be need for multiple servers. Now i need to know how to prepare in advance for an increase in servers, so when people upload files to the servers, i will know which server each file is on, and also i need to know if i would need multiple sql databases if it were to get very big? When you go to big sites such as myspace, you will see that pictures and songs are stored on seperate servers such as imageserver1.domain.com, imageserver2.domain.com. Now i need to know how to store the pictures on different servers when i upload it with php, and when the pictures are viewed how to look at the right server to view the picture. How do these proffesional websited do it? I want to do it in the most practicle way possible. Thanks
  21. thanks alot man, that helped alot.
  22. Alright say i have the following table structure: Table 1 _____________________________ |----USERNAME----|----ADDDATE----| -----myname-----------2006-01-02---- ----myname2----------2006-01-03---- ______________________________ Table 2 _____________________________________ |---USERNAME---|----FIELD1----|----FIELD2----| -----myname-----------blue-----------tall---- ----myname2----------black----------short--- ______________________________________ Now i want to have a mysql query that takes table 2, searches through it and picks out certain rows depending on the where clause that is set, and then match those rows usernames to the usernames on table 1 so that the username, adddate, field1, and field 2 are all returned in the same query. Thanks, -Brendan
  23. [!--quoteo(post=367410:date=Apr 21 2006, 11:02 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Apr 21 2006, 11:02 PM) [snapback]367410[/snapback][/div][div class=\'quotemain\'][!--quotec--] @Brendan php_self points to the generated file (includes included) so that in your case the form points correctly to index.php not to the originally included form.php code. If you think of include as equivalent to the server doing a copy/paste of the include into the file called you'll see why index.php is the real 'self'. If you want/need form.php as a standalone script that can submit on itself, you'll need form.php as a separate file which is not included but accessed by link. [/quote] So then i'm assuming there isn't a function that will return the script filename where the function is used? If not, then how would i go about including it as a seperate link, while still being imbedded in the current page?
  24. [b]SOLVED[/b] OK, i have a script with a form in it, form.php, included in a file with the layout and everything, index.php. Now say i want to put action="<?php print $_SERVER['PHP_SELF'] ?>" in the form, so that when i click submit the form submits the information to its self. The problem is that the form submits to the file its included in, index.php, instead of to its self, form.php. So when i want it to be action="form.php" it ends up being action="index.php" instead.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.