Jump to content

jp15

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jp15's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, Im trying to make it so that the user can open a file in the browser, which they select from a drop down list populated from a table in a database. Here is what I have so far but am lost, If you have any code to help that would be great or any tutorials, many thanks. Code: <?php $mysql = mysql_connect("localhost", "*", "**"); mysql_select_db("db_*", $mysql) or die(mysql_error()); $sql="SELECT id,name FROM upload2"; $result =mysql_query($sql); echo '<form name="form1" method="post" action="thisfile?.php">'; echo '<select>'; while ($data=mysql_fetch_assoc($result)){ echo '<option value ="',$data['id'],'">',$data['name'],'</option>'; } echo '</select>'; echo "<input name= 'option' type='submit' value='Download'>"; echo '</form>'; ?> It was also be good to provide them with an option to download the file. Any help much appreciated.
  2. Hi please help, trying to delete a value from a drop down list populated by a table in my database. this is the code: <? $conn = mysql_connect('localhost','**','**'); $db = mysql_select_db(**'); if(isset($_POST['id']) && !empty($_POST['id'])){ $id = mysql_real_escape_string($_POST['id']); $sql = "DELETE FROM `upload2` WHERE `id` = $id"; $result = mysql_query($sql); $num = mysql_affected_rows(); if($num == 1){ echo "<p>Record $id deleted successfully.</p>\n"; }else{ echo "<p>Unable to delete record $id.</p>\n"; } } ?> <form action="$PHP_SELF" method="post"> Name to delete:<br /> <select name="id"> <? $sql = "SELECT `id`,`name`, FROM `upload2` ORDER BY `name`; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n"; } ?> </select> <input type="submit" value="Delete" /> </form> and this is the error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /.automount/barra4/ug/home/jp15v07/public_html/discard.php on line 29 Line 29 : echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n"; Ive looked up the error but am fairly new to php so cant seem to solve it, appreciate any help thanks.
  3. Over to the experts, I have spent a while trying to produce customize some code, this is what it does so far. Displays files from the "uploads" directory in a drop down list. Uses java script to remove a value from the list. What I would like to be able to do and I need to no if its "doable" is; - make the links to files active (so the file will open when selected, maybe with the aid of a button would be nice) - once a user has removed a value from the list, to remove the file from the "uploads" directory and no just the list. Is this possible, if not, are there other ways to achieve this. Appreciate your help guys. Code: <?php $dir = opendir('location'); echo '<select id="mySelect">'; while ($read = readdir($dir)) { if ($read!='.' && $read!='..') { echo '<option> <a href="files/'.$read.'">'.$read.'</a></option>'; } } echo '</select>'; closedir($dir); ?> <input type="button" onclick="formAction()" value="Delete"> </form>
  4. Hi, as it stands I can add events to the calendar and view them no problem. What I would like to be able to do is to make it clear once an event has been added by making the date bold or possibly highlight the background with a different colour so the user knows which days already have events scheduled. This may be really simple and I am fairly new to PHP so would appreciate any help, Thanks a lot: Calendar.php: <?php // At line 2 of our calendar.php script, add the MySQL connection information: $mysql = mysql_connect("localhost", "", ""); mysql_select_db("", $mysql) or die(mysql_error()); // Now we need to define "A DAY", which will be used later in the script: define("ADAY", (60*60*24)); // The rest of the script will stay the same until about line 82 if ((!isset($_POST['month'])) || (!isset($_POST['year']))) { $nowArray = getdate(); $month = $nowArray['mon']; $year = $nowArray['year']; } else { $month = $_POST['month']; $year = $_POST['year']; } $start = mktime(12,0,0,$month,1,$year); $firstDayArray = getdate($start); ?> <html> <head> <title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title> </head> <script type="text/javascript"> function eventWindow(url) { event_popupWin = window.open(url, 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=400,height=400'); event_popupWin.opener = self; } </script> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="month"> <?php $months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); for ($x=1; $x<=count($months); $x++){ echo "<option value=\"$x\""; if ($x == $month){ echo " selected"; } echo ">".$months[$x-1]."</option>"; } ?> </select> <select name="year"> <?php for ($x=1980; $x<=2010; $x++){ echo "<option"; if ($x == $year){ echo " selected"; } echo ">$x</option>"; } ?> </select> <input type="submit" name="submit" value="Go!"> </form> <br /> <?php $days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); echo "<table border=\"1\" cellpadding=\"5\"><tr>\n"; foreach ($days as $day) { echo "<td style=\"background-color: #38ACEC; text-align: center; width: 14%\"> <strong>$day</strong></td>\n"; } for ($count=0; $count < (6*7); $count++) { $dayArray = getdate($start); if (($count % 7) == 0) { if ($dayArray["mon"] != $month) { break; } else { echo "</tr><tr>\n"; } } if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) { echo "<td> </td>\n"; } else { $chkEvent_sql = "SELECT event_title FROM calendar_events WHERE month(event_start) = '".$month."' AND dayofmonth(event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start"; $chkEvent_res = mysql_query($chkEvent_sql, $mysql) or die(mysql_error($mysql)); if (mysql_num_rows($chkEvent_res) > 0) { $event_title = "<br/>"; while ($ev = mysql_fetch_array($chkEvent_res)) { $event_title .= stripslashes($ev["event_title"])."<br/>"; } mysql_free_result($chkEvent_res); } else { $event_title = ""; } echo "<td valign=\"top\"><a href=\"javascript:eventWindow('event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');\">".$dayArray["mday"]."</a><br/>".$event_title."</td>\n"; unset($event_title); $start += ADAY; } } echo "</tr></table>"; mysql_close($mysql); ?> Event.php: <html> <head> <title>Show / Add Events</title> </head> <body> <h1>Show / Add Events</h1> <?php $mysql = mysql_connect("localhost", "jp15v07", "pompey123"); mysql_select_db("db_jp15v07", $mysql) or die(mysql_error()); // Add our new events if ($_POST){ $m = $_POST['m']; $d = $_POST['d']; $y = $_POST['y']; // Formatting for SQL datetime (if this is edited, it will NOT work.) $event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00"; $insEvent_sql = "INSERT INTO calendar_events (event_title, event_shortdesc, event_start) VALUES(' ".$_POST["event_title"]."', '".$_POST["event_shortdesc"]."', '$event_date')"; $insEvent_res = mysql_query($insEvent_sql, $mysql) or die(mysql_error($mysql)); } else { $m = $_GET['m']; $d = $_GET['d']; $y = $_GET['y']; } // Show the events for this day: $getEvent_sql = "SELECT event_title, event_shortdesc, date_format(event_start, '%l:%i %p') as fmt_date FROM calendar_events WHERE month(event_start) = '".$m."' AND dayofmonth(event_start) = '".$d."' AND year(event_start)= '".$y."' ORDER BY event_start"; $getEvent_res = mysql_query($getEvent_sql, $mysql) or die(mysql_error($mysql)); if (mysql_num_rows($getEvent_res) > 0){ $event_txt = "<ul>"; while($ev = @mysql_fetch_array($getEvent_res)){ $event_title = stripslashes($ev["event_title"]); $event_shortdesc = stripslashes($ev["event_shortdesc"]); $fmt_date = $ev["fmt_date"]; $event_txt .= "<li><strong>".$fmt_date."</strong>: ".$event_title."<br/>".$event_shortdesc."</li>"; } $event_txt .="</ul>"; mysql_free_result($getEvent_res); } else { $event_txt = ""; } mysql_close($mysql); if ($event_txt != ""){ echo "<p><strong>Today's Events:</strong></p> $event_txt <hr/>"; } // Show form for adding the event: echo " <form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\"> <p><strong>Add Event:</strong><br/> Complete the form below then press the submit button when you are done.</p> <p><strong>Event Title:</strong><br/> <input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/></p> <p><strong>Event Description:</strong<br/> <input type=\"text\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/></p> <p><strong>Event Time (hh:mm):</strong><br/> <select name=\"event_time_hh\">"; for ($x=1; $x<=24; $x++){ echo "<option value=\"$x\">$x</option>"; } echo "</select> : <select name=\"event_time_mm\"> <option value=\"00\">00</option> <option value=\"15\">15</option> <option value=\"30\">30</option> <option value=\"45\">45</option> </select> <input type=\"hidden\" name=\"m\" value=\"".$m."\"> <input type=\"hidden\" name=\"d\" value=\"".$d."\"> <input type=\"hidden\" name=\"y\" value=\"".$y."\"> <br/><br/> <input type=\"submit\" name=\"submit\" value=\"Add Event!\"> </form>"; ?> </body> </html>
  5. Superb, exactly the kind of thing I was looking for, Thanks again guys real appreciate all your help
  6. ym_chaitu apologies for the eventful post, just felt like I was being judged as It appears my intentions were misconstrued! Thank you for the scripts, I will have a look and let you know how I get on, Thanks again much appreciated.
  7. The sarcastic response was triggered by the witty remark about using Google!! Sado, just to try and set the record straight, Im not here to offend anybody, and I respect the the wealth of knowledge provided on such sights like this. I am now aware of the sensitive nature though, my problem was genuine, I haven’t produced any code as I didn’t no where to start. I have however, spent many, many hours coding my website to a certain standard. I could not get my head around the concept of how to do, what i wanted to do. So I guess it was more of a discussion of the possibilities I was looking for, or a framework of code as a starting point. My intentions of leaving uni are to become an IT consultant and not an engineer in that respect and I’m honest enough to say my technical abilities aren’t my strong point - this is why I attempted to seek help. I don’t appreciate assumptions based on what I want from a "dump ass nerd", not my intention at all, I am not that sort of person. I just thought this would be a good place to come for some ideas. Thanks for your time and soz for any misunderstanding.
  8. Thanks for the mature response, I tried that believe it or not. Never used one of these forums before - and rightly so obviously. You realy have been most helpful! Thanks again old sport!
  9. Hi there, I wonder if you can help me, now I’m not a pro at php, pretty basic to be honest but I need some help with a system I am creating for my third year project at uni. I need to know how I could provide means for a user to upload a file or provide a link to a file and have that same file displayed on the page once they have done so (if that makes sense). This is so they can organise their resources for and then access them at a later date for whatever reason. If you could provide me with some idea of what this would involve or point me in the direction of some code that would allow me to do this, I would be grateful. Kind Regards
×
×
  • 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.