-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Variables are not expanded in single quotes. Remove the single quotes around the use of $username here ...Where('username', '$username')...
-
Each value in the drop down menu needs to be wrapped in <option></option> tags. Example html <select id="tankname" type='text' name="tankname"> <option>Tank 1</option> <option>Tank 2</option> <option>Tank 3</option> </select>
-
If you are uploading the files to your site via HTML form then there is no need for the ftp functions. The file has already been uploaded when the form is submitted, you'd use move_uploaded_file to place the file where you want it to be saved.
-
How to check for a variable with a certain value?
Ch0cu3r replied to ageattack's topic in PHP Coding Help
What is it you are trying to do? Variable variables inst efficient way of grouping data. That is what arrays are for. If you are only wanting to get unique values then store your data in an array and use array_unique to get only the unique values. -
Code review (directory handling) working, but not pretty
Ch0cu3r replied to anderson_catchme's topic in PHP Coding Help
What? Why? That is unnecessary The details of the images a user uploads should not need be inserted into the users table. When a user uploads an image you insert a new row into a table called images (or whatvever you want to name it as) to store the image details (such as filename, filesize etc) along with the users id/username. When you want to show the images a user has uploaded you query the images table filtering the results by the users id/username. -
There is a problem with your sql. Use $mysqli->error to see what the error is
-
You are getting those notices because those array keys/indexes does not exist in the $_SESSION array. How is your $_SESSION data set?
-
Because you need to wrap the value you are passing to the myhit( ) JavaScript function in quotes. ...onclick="myhit('<?php echo $row['track']; ?>')" Do note that PHP code and javascript code are not ran at the same time. They are completely different languages. PHP is server side and Javascript is client side.
- 9 replies
-
- php
- javascript
-
(and 1 more)
Tagged with:
-
Try capitalizing the font name and wrap it in quotes. Strings should be wrapped in quotes $fontname = 'Arial'; If it still does not work, then copy the Arial.ttf font from C:\Windows\Fonts and put it in the same folder as your script. Then change $filename = 'Arial'; to $filename = './Artial.ttf'; Also What is this for? $fontname-- ; That does not make sense to me.
-
What? We no mind reader
-
The code you posted should be doing just that. However from the screenshot you posted it appears the code you have posted is within another while loop (or in your wording a repeat region) which is why the headings are being duplicated.
-
Then you need to start learning CSS
-
Yes. Open a <table> and <tr> tag before the echo and then wrap the variables in <td></td> tags followed by the closing </tr> and </table> tags.
-
No, So long as you call session_start() at the beginning of your script the $_SESSION variables will be available to use. jazzman1's code suggestion inserts the logged in users username along with the uploaded files details into the upload table. That is what is what you are wanting to do right?
-
That error should be be solved by changing these two lines //'branches' => array(), //'br_contacts' => array() to 'branches' => array(), 'co_contacts' => array()
-
The code appears to be working. I think the issue is the $company_array is not being constructed correctly. Which I think is being caused by the first query. Due to the join on the co_contact table. When a contact is not found all the contact table field values will be returned as null. As seen below (company 1 has 1 contact but company 2 has no contacts) +------------+-----------+-----+------------+--------------------+-----+ | company_id | comp_name | ... | company_id | cont_name | ... | +------------+-----------+-----+------------+--------------------+-----+ | 1 | Company 1 | ... | 1 | Company1 Contact 1 | ... | | 2 | Company 2 | ... | NULL | NULL | ... | +------------+-----------+-----+------------+--------------------+-----+ Notice the the company_id field is returned twice, The first instance is the value from the company table the second instance is the value from the co_company table. On the second row the second instance for company_id is null because a contact for Company 2 was not found. Here lies the issue. Now when PHP processes the results only the last instance of the company_id field will be returned from the row. In the code $row['company_id'] is used as the array key for grouping the companies data into arrays. For Company 2 $row['company_id'] will be null and not 2 (the value it should be) so the details for that company are not going to be grouped correctly. After the first query being processed the $company_array array will look like this Array ( [1] => Array ( [name] => Company 1 [street] => 1 Street, NYC [csz] => csz 1 [phone] => 111222330 [fax] => 111222339 [web] => http://company1.com [email] => inbox@company1.com [branches] => Array ( ) [co_contacts] => Array ( [0] => Array ( [name] => Company1 Contact 1 [title] => Company1 Contact 1 Title [email] => contact1@company1.com ) ) ) [] => Array ( [name] => Company 2 [street] => 2 Street, NYC [csz] => csz 2 [phone] => 222334440 [fax] => 222334448 [web] => http://company2.com [email] => inbox@company2.com [branches] => Array ( ) [co_contacts] => Array ( [0] => Array ( [name] => [title] => [email] => ) ) ) ) When we start together the branches details for each company the data will become malformed. And you get the result you are getting currently. To solve the issue we need to explicitly state the fields we want to return from the co_company table. The first query can be changed to // Retrieve ALL the "company" specific data (including contacts) $query = "SELECT company.*, # return all fields in the company table co_contact.cont_name, # return the following fields from the co_contact table co_contact.cont_title, co_contact.cont_email FROM company LEFT JOIN co_contact ON company.company_id = co_contact.company_id WHERE comp_county = 'BERNALILLO' ORDER BY company.comp_name, co_contact.cont_rank"; Try changing the query. What result do you get now?
-
A couple notes for download.php I have omitted the code for connecting to mysql so you must add the code you use for connecting to mysql before the first if statement. I have also omitted the code for outputting an error if the query fails. This is why I think you are getting a blank white page. Adding the missing pieces of code should get download.php to function.
-
3 randomized fields, no duplicates - buggy! NEED HELP!
Ch0cu3r replied to phpsyn's topic in PHP Coding Help
It is a bad idea using queries in loops. Instead you should first add the random values to arrays. Use in_array to check if the value has been generated before. Then you can insert all the random combinations using one query eg INSERT INTO table (col1, col2, col3) VALUES (...combination 1...), (...combination 2...), (...combination 3...), -
I only gave you example code for download.php. It is untested. If it is not working your need to start to debugging it.
-
@spock9458 Is the same problem you posted a year ago located here? Psyco's provided you with code to achieve this already here has he not? You are getting that error because you are using next() in correctly. You are passing it a conditional expression not a variable.
-
Look at lines 4 and 12... gives you a clue. Also why are you going in and out of php mode on lines 5 and 6 and 13 and 14? This is pointless if you are not going to output anything between closing and opening php tags.
-
Ha classic.. I can be such a tool sometimes. Code should now be error free echo '<h2>Uploaded Files</h2>'; // get the files belonging to the logged in user $result = mysql_query('SELECT upid, filename, size FROM upload WHERE username=\''.mysql_real_escape_string($_SESSION['MM_Username']).'\''); // check query did execute without errors if($result) { // output each file while($row = mysql_fetch_assoc($result)) { // set a link to download.php passing the files upid as a query string parameter echo '<a href="?upid='.$row['upid'].'">'.$row['filename'].' - '.$row['size'].'</a><br />'; } // query did not execute, log or show error message } else { trigger_error('Cannot get users files from database: ' . mysql_error()); }
-
Change the end of line 64 from ); to )); I left off the closing parenthesis for the mysql_query function. EDIT: Make sure you have applied the changes to download.php suggested by mac_gyver too
-
In profile.php you'd just fetch the records that match the users username from the uploads table. You'd then output the details for each file returned by the query, eg filename and filesize. You'd make the filename a link to your download script. The link will contain a file id query string parameter set to the upid of the file. Basic example code for profile.php for showing the users uploaded files echo '<h2>Uploaded Files</h2>'; // get the files belonging to the logged in user $result = mysql_query('SELECT upid, filename, size FROM upload WHERE username=\''.mysql_real_escape_string($_SESSION['MM_Username'].'\''); // check query did execute without errors if($result) { // output each file while($row = mysql_fetch_assoc($result)) { // set a link to download.php passing the files upid as a query string parameter echo '<a href="download.php?upid='.$row['upid'].'">'.$row['filename'] - $row['size'].'</a><br />'; } // query did not execute, log or show error message } else { trigger_error('Cannot get users files from database: ' . mysql_error()); } . Now in download.php you'd run a query fetch the row where the upid field matches $_GET['upid'] in the uploads table. If the query returns a row you'd present the file for download. Basic download.php example code <?php session_start(); // very basic check to see if user is logged in if(!isset($_SESSION['MM_Username'])) { // kill the script display warning. die('Unauthorised accessed. You must be logged in to access this file'); } // Has a file id been passed? if(isset($_GET['upid']) && ctype_digit($_GET['upid'])) { // fetch the file where the upid matches $result = mysql_query('SELECT filename, type, size, content FROM upload WHERE upid='.intval($_GET['upid'])); // query executed ok if($result) { // get the files details list($filename, $type, $size, $content) = mysql_fetch_row($result); // present file for download header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$filename"); echo $content; exit; } }
-
PHP is not the solution. Look at using CSS media quries to display different parts of your web page depending on the device being used. This technique is called Responsive Web Design goggling that term will yeild may articles/tutorials. Such as this page was found
- 7 replies
-
- screen size
- responsive
-
(and 2 more)
Tagged with: