ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
[SOLVED] upload file, rename, and restrict size.
ignace replied to adamlacombe's topic in PHP Coding Help
http://www.php.net/manual/en/features.file-upload.php explains you how to upload files and restrict them. use copy() to rename the uploaded file to the username's name: http://be.php.net/manual/en/function.copy.php Here you go -
[SOLVED] upload file, rename, and restrict size.
ignace replied to adamlacombe's topic in PHP Coding Help
1) read the manual 2) come back if you have a php problem -
[SOLVED] Php switch statement with a while loop
ignace replied to littlehelp's topic in PHP Coding Help
Where does $res and $count come from? <?php function doIt($it) { switch ($it) { case '$count'://i want to use a counter and increment the counter each time through while($row=mysql_fetch_array($res)){//i want to use a wile loop this does not work return "<div style=\"width: 100px; height: 84px; text-align: center; float: left;\"><img src=\"images/pokemon_sprites/001.png\" width=\"100\" height=\"100\" /></div><div style=\"overflow: hidden; width: 100px; float: left; padding-top: 32px; line-height: normal;\"><strong>Bulbasaur</strong><br><span class=\"smallVerdana\">Level 1<br /><div class=\"clear\"><img src=\"battle_files/spacer.gif\" alt=\"sp\"></div> <div style=\"width: 100px; text-align: left;\"> <div class=\"hpBar\" style=\"width: 100%;\"><img src=\"battle_files/spacer.gif\" alt=\"sp\" style=\"height: 12px;\"></div>45/45 Hit Points<br /><div class=\"clear\"><img src=\"battle_files/spacer.gif\" alt=\"sp\"></div></div>";//'.$i[iD].'. } break; } } ?> -
DW recordset to pull 1 record from DB based on date
ignace replied to T2theC's topic in PHP Coding Help
Please provide a short summary (table names + columns) of all relevant tables -
Creating a search from multiple parameters and select boxes.
ignace replied to Solarpitch's topic in PHP Coding Help
<?php $select = 'SELECT * FROM clients'; $where = ''; if (!empty($_POST['email_address'])) { $emailAddress = $_POST['email_address']; // don't forget to validate and filter $where .= " email_address = '$emailAddress' OR email_address LIKE \'%$emailAddress%\'"; } if (!empty($_POST['phone_number'])) { .. $select .= "WHERE $where"; ?> -
Apparently I was wrong. fopen() does not get disabled but gets limited, to be more precise: A full listing can be found here: http://www.php.net/manual/en/features.safe-mode.functions.php
-
Unique urls for individual posts in mysql database
ignace replied to mitman's topic in PHP Coding Help
<?php if (empty($_GET['id'])) { //?id= does not exist, what to do? } $id = (int) $_GET['id']; $query = 'SELECT * FROM contents WHERE id = %u'; $fquery = sprintf($query, $id); $result = mysql_query($fquery, $db); $row = mysql_fetch_assoc($result); //work with $row print $row['title']; print $row['excerpt']; ?> -
$row[nl2br('Comment')] Would be less clever You probably mean: nl2br($row['Comment']) And yes you could do that
-
Then it would still work $putanja = "../files/naslovi/" . $_GET['id'] . "/" . $photo['filename'] . ".txt"; print basename($putanja); //$photo['filename'].txt
-
DW recordset to pull 1 record from DB based on date
ignace replied to T2theC's topic in PHP Coding Help
We are a help forum, so we are always gentle unless you ask us things that are already covered in the manual because those who wrote it deserve the respect. Add this to your query: LIMIT 1 I'm in a good mood today -
modify your checkboxes name to: <input type="checkbox" name="ch[]" value="jobfunction1"> <input type="checkbox" name="ch[]" value="jobfunction2"> <input type="checkbox" name="ch[]" value="jobfunction3"> <input type="checkbox" name="ch[]" value="jobfunct..."> Then in your php you can do: $JobFunction = implode(', ', $_POST['ch']); // jobfunction1, jobfunction2, ..., jobfunction13 (no trailing ,) The same goes for $business, $owner, $human, .. Assume a common name: occupation Business: <input type="radio" name="occupation[]" value="1"><!-- if checked then the value=1, null otherwise --> Owner: <input type="radio" name="occupation[]" value="1"> Human: <input type="radio" name="occupation[]" value="1"> <?php $occupation = $_POST['occupation']; //array('1', '', '', '1', '', '', '', '1', ..); array_walk($occupation, 'set_bool'); $occupation = implode(', ', $occupation); // 1,0,0,1,0,0,0,1, .. function set_bool(&$item, $key) { $item = !empty($item) ? 1 : 0; } ?>
-
<?php print basename($_SERVER['SCRIPT_NAME']); ?>
-
transfer a file from one directory to another
ignace replied to dreamwest's topic in PHP Coding Help
<?php $filesource = implode(DIRECTORY_SEPARATOR, array($fromdir, $file)); $filedestination = implode(DIRECTORY_SEPARATOR, array($todir, $file)); copy($filesource, $filedestination); ?> -
You need a new page, then when a user wants to edit a certain image: <input type="hidden" name="filename" value="<?php print $photo['filename']; ?>"> <input type="hidden" name="action" value="update_image"> <input type="text" name="caption" value="<?php print $photo['caption']; ?>"> And add this php code: <?php if (!empty($_POST['action']) && $_POST['action'] === 'update_image') { $id = $_GET['id']; $filename = $_POST['filename']; $caption = $_POST['caption']; $filelocation = "../files/naslovi/$id/$filename.txt"; $fh = fopen($filelocation, 'w'); if ($fh) { fwrite($caption); fclose($fh); } } ?>
-
[SOLVED] Changing and Deleting Entries in a MySQL Database
ignace replied to Grizzly13's topic in PHP Coding Help
if (empty($_SESSION['username'])) { header('location: index.php'); } else { // directly implies $_SESSION['username'] is not empty (if it was this wouldn't execute) if ((!empty ($_SESSION['username'])) && ($_SESSION['admin'] == '0') && ($_SESSION['status'] == '1')) if ((!empty ($_SESSION['username'])) && ($_SESSION['admin'] == '0') && ($_SESSION['status'] == '1')) if ((!empty ($_SESSION['username'])) && ($_SESSION['admin'] == '0') && ($_SESSION['status'] == '0')) if ((!empty ($_SESSION['username'])) && ($_SESSION['admin'] == '1')) Can be simplified to: if (!empty($_SESSION['username'])) { if (!$_SESSION['admin']) {// !0 = true if (!$_SESSION['status']) {// status=0 header('Location: index.php'); } else {// status=1 header('Location: userInbox.php'); } } else {// admin=1 include('topHalf.php'); echo ''; } } else {// $_SESSION['username']=empty header('Location: index.php'); } Which can be directly transformed to: if (empty($_SESSION['username']) || ($_SESSION['admin'] == FALSE && $_SESSION['status'] == FALSE)) { header('Location: index.php'); } if ($_SESSION['admin'] == FALSE && $_SESSION['status'] == TRUE) { header('Location: userInbox.php'); } if ($_SESSION['admin'] == TRUE) { include('topHalf.php'); echo ''; } This should help you simplify your script and will make it easier to spot errors more easily. To simplify it further, you'd get: if (empty($_SESSION['username']) || (empty($_SESSION['admin']) && empty($_SESSION['status']))) { header('Location: index.php'); } if (empty($_SESSION['admin']) && $_SESSION['status'] == TRUE) { header('Location: userInbox.php'); } if ($_SESSION['admin'] == TRUE) { include('topHalf.php'); echo ''; } -
Add this: <input name="quantity" type="text" value="<? echo $stringData;?>"/> To this: <form method="post" enctype="multipart/form-data" class="edit"> <h2 class="fieldset-title">Upload nove slike</h2> <fieldset> <input type="file" name="photo" /> <input type="hidden" name="page" value="<?php echo $_GET['page']; ?>" /> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /> <input type="hidden" name="action" value="add_photo" /> <input type="hidden" name="action" value="add_photo" /> <input type="submit" name="submit" value="Dodaj" /> </fieldset> </form> Change: if (file_exists($ourFileName)) { } else { $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); } To: if (!empty($_POST['quantity'])) { $quantity = $_POST['quantity']; $ourFileHandle = fopen($ourFileName, 'w'); if ($ourFileHandle) { fwrite($fh, $quantity); fclose($ourFileHandle); } }
-
It is still there. Check your html to verify it, however html doesn't recognize \n therefor it is up to you to format it properly. <?php print nl2br("Hello all,\nI have the following\nA dog,\nA Cat"); ?>
-
Stop asking these kind of questions, the most don't even respond to them because they are addressed in the manual: http://be2.php.net/manual/en/ref.filesystem.php
-
Although not sure i think this might pull it off. SELECT * FROM members m WHERE week(m.signup_date, 1) = week(now(), 1) - 1 It's up to your implementation to display it for each and every day. Please note that for mysql the week starts on sunday. Edit: I modified the code now it starts on monday.
-
-- Signups today SELECT count(*) as todays_new_members FROM members m WHERE m.signup_date = NOW() -- Signups this month SELECT count(*) as new_members_this_month FROM members m WHERE month(m.signup_date) = month(now()) -- Signups this year SELECT count(*) as new_members_this_year FROM members m WHERE year(m.signup_date) = year(now()) -- Total signups SELECT count(*) as total_registrations FROM members There are probably better (more performant) solutions. My 666th Post
-
[SOLVED] is users is admin or editor then problem
ignace replied to jesushax's topic in PHP Coding Help
Weird, this should work however it may be an encoding kind of thing. -
$filename = "../files/naslovi/" . $_GET['id']; .. mkdir("../files/naslovi/" . $_GET['id'], 0777); Assume i would pass this to your script: ?id=../../badassdirectory $filename = "../files/naslovi/../../badassdirectory"; // i.e. ../badassdirectory mkdir("../files/naslovi/../../badassdirectory", 0777); You now have an additional directory (possibly) in your root. P.S. Use proper indentiation it makes your code readable
-
transfer a file from one directory to another
ignace replied to dreamwest's topic in PHP Coding Help
<?php $fromdir = '/path/to/directory'; $todir = '/path/to/new/directory'; $files = scandir($fromdir); foreach ($files as $file) { if ($file[0] !== '.') { // escapes ., .. and files starting with a . (mostly hidden files) $filesource = implode(DIRECTORY_SEPARATOR, array($fromdir, $file)); $filedestination = implode(DIRECTORY_SEPARATOR, array($todir, $file)); copy($filesource, $filedestination); } } -
This produces this output: ...