
dazzathedrummer
Members-
Posts
101 -
Joined
-
Last visited
Everything posted by dazzathedrummer
-
Hi, I'm trying to create a page that shows information about people visiting my site, particularly whether they are logged in or not. The login system works fine and i can get info on who's visiting by writing session info to a db and retrieving it - that's all ok. It just doesn't work when I combine the two. What i'm trying to do is detect a cookie that was set by logging in on a different page - if it's set then $member stores the username and writes that to the db with the the session data. I also have a similar if statement that detects another cookie that is set simply by hitting the site - this is so I get info that can be 'Logged in' or 'not logged in' and 'new visitor' or 'returning visitor'. Both of the if statements return 'false' results despite my having logged in and checked that the cookies exist - and if I echo out the variables, I get the results that I expect - my username and 'returning visitor' I'm not understanding why the 'false' results are being posted to the db despite the fact that both if statements seem to be (and should be) returning trues. here is the code that I have placed at the very top of my 'index.php': - <?php session_start(); $ses = session_id(); $time = time(); $timech=$time-300; //checks logged in cookie if(isset($_COOKIE['guard_member'])) { $member= $_COOKIE['guard_member']; } else { $member= 'not logged in'; } //checks visitor cookie if(isset($_COOKIE['guard_visit'])) { $visitor ='returning visitor'; } else { $visitor= 'new visitor'; } //stores browser info $browser= ($_SERVER['HTTP_USER_AGENT']); mysql_connect("database", "user", "password") or die(mysql_error()); mysql_select_db("the_guards_org_uk_users") or die(mysql_error()); $result = mysql_query("SELECT * FROM tg_session WHERE session='$ses'"); $num = mysql_num_rows($result); if($num == "0"){ $result1 = mysql_query("INSERT INTO tg_session (session, time, username, status, browser_os)VALUES('$ses', '$time', '$member', '$visitor', '$browser')"); }else{ $result2 = mysql_query("UPDATE tg_session SET time='$time' WHERE session = '$ses'"); } $result3 = mysql_query("SELECT * FROM tg_session"); $usersonline = mysql_num_rows($result3); //echo "There are: <b>".$usersonline."</b> users online"; //echo $member; //echo $visitor; mysql_query("DELETE FROM tg_session WHERE time<$timech"); ?> Just to reiterate; the cookies are set before coming to this page and the data writes to the db fine - it just seems to be the wrong data. ?
-
basic textarea formatting question
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
excellent that does the trick. a couple of things, i'm using both functions to set variables separately (ie twice for each text input) is there a way to combine the two?? So, where I want text from the form feild "text" to have slashes and also have line breaks im doing this: - $text1 = mysql_real_escape_string($_POST['text']; then $text = nl2br($text1); and $text gets pushed into the DB. just wondering if theres a more eligant way of doing that as i'll have to double the number of variables for each textarea. Also - is there a way to negate nl2br? it works fine on the way into the DB, but if a user 'edits' a field using a textarea, the "<br>" tags become visible in the text area. -
Ok, again, I've been searching for the answer to this but not found anything much to solve my problem (or maybe I should say 'I found loads of info that ended up giving me a headache' haha). So, all i want to do is take a form textarea, have a user input regular text that will eventually populate an area of a webpage. I'm ok on everything apart from the formatting of the text - how do I convert the text being sent to the database into a format so that it comes back out of the database looking like it did when it went in (with paragraphs, line breaks, apostrophes etc). ?
-
that's great thanks a lot. ...out if interest, this particular email is for band members so we dont mind seeing each others addresses in the 'to' field - how simple would it be to adapt this code so that it sends one email per email address in a mailing list - so that each person in the list can only see their own address?
-
Hi, I'm trying join up two things here, i have the following code that will return selected email addresses from a DB as a string with commas (eg "eamail1@email.com, email2@email.com, etc": - <?php // Connects to your Database mysql_connect("database", "host", "password") or die(mysql_error()); mysql_select_db("the_guards_org_uk_users") or die(mysql_error()); $query = "SELECT fname, sname, username, email FROM users where is_guard=1"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo"{$row['email']}, "; } echo $row; mysql_close(); ?> I also have this simple code for sending mail from the server: - <?php // Connects to your Database mysql_connect("database.lcn.com", "LCN_7792", "theguards9402") or die(mysql_error()); mysql_select_db("the_guards_org_uk_users") or die(mysql_error()); $query = "SELECT fname, sname, username, email FROM users where email ='darren.bullough@btinternet.com'"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "{$row['email']}"; } echo $row; mysql_close(); $to = 'eamil1@email.com'; $subject = 'Guard Admin - Gig update test email, please delete.'; $message = 'Test'; $headers = 'From: admin@the-guards.co.uk' . "\r\n" . 'Reply-To: admin@the-guards.co.uk' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> How can I use the results of the first query as the email addresses for the 'To' feild in the mail code?? I've tried 'including' the file, setting a variable and call the variable where $to is set and I've also tried the same but with the first code incorporated as opposed to included. admittedly, I must be doing it wrong???? The reasoning behind this is so that email recipients can change their email address elsewhere on the site.
-
code to send email via smtp host
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
thats works!!! excellent - so that's using the servers 'default' settings? -
code to send email via smtp host
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
these are my servers sendmail settings: - sendmail_from no value - no value sendmail_path - /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i serialize_precision 100 100 short_open_tag On On SMTP - localhost localhost smtp_port - 25 How do I change the code to use sendmail?? -
code to send email via smtp host
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
yeah - thanks, I've tried that one - I get a server error though "500 internal server error" Is there something that I need to configure? My ISP uses sendmail, do I need to specify the path? -
Hi, i've been google'ing for a couple of hours now and cant seem to find out how to write a script that will send an email from the server via smtp. Could anyone point me in the right direction? thanks, Darren
-
Getting an update query to work
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
thats it!! Problem solved! I guess that's what you said in your first reply "variable called but not set" doh! ...now I understand I can set this up for all fields. Thanks very much for your help!! -
Getting an update query to work
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
...yes, I did. ahhh - if I do $id = 67, then mysql_query("update tg_gig_list set gl_text='$text' where gl_id='$id'"); ..will update row 67. so, does this suggest that when the variable is set using $id = $_POST['gl_id'], it will take '67' from the previous form, but when the 'update' button on this form is pressed, it looses the value?? -
Getting an update query to work
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
I put this in the "gig entered..." section and echoed it - it returns 1, what does that mean? -
Getting an update query to work
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
Yes, I get the success message, so the query works, its just not getting an ID to update - either because the type is wrong (but that would error wouldn't it?) or $id isn't set at that point. ? -
Getting an update query to work
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
Hi, its coming from another forms 'post' - its being sent from an 'edit' button on a list - so $id = '67' when the page starts, presumably this is why it echos out correctly. I'm probably not seeing something here - i'm fairly new to this. Is this why the sql query isnt recognising '67'? -
Hi, I've been creating an update form with the help of this forum. I'm almost there but i've run into what I think is a data type problem. here's my code: <?php // Connects to your Database mysql_connect("database.lcn.com", "LCN_7792", "PASSWORD") or die(mysql_error()); mysql_select_db("the_guards_org_uk_users") or die(mysql_error()); $id = $_POST['gl_id']; $text = $_POST['gl_text']; echo $id; //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['gl_date']) { die('You did not enter a valid date'); } // now we insert it into the database mysql_query("update tg_gig_list set gl_text='$text' where gl_id='$id'"); ?> <h1>Gig entered succesfully</h1> <p>back to <a href="guard_admin.php">admin area</a>.</p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr> <td>Date (YYYY-MM-DD)</td> <td><input type="date" name="gl_date" maxlength="20"value="<?php echo $_POST['gl_date']; ?>"></td></tr> <tr> <td>Venue</td> <td><input type="text" name="gl_venue" maxlength="20"value="<?php echo $_POST['gl_venue']; ?>"></td></tr> <tr> <td>City</td> <td><input type="text" name="gl_city" maxlength="20"value="<?php echo $_POST['gl_city']; ?>"></td></tr> <tr> <td>Postcode</td> <td><input type="text" name="gl_postcode" maxlength="10" value="<?php echo $_POST['gl_postcode']; ?>"></td></tr> <tr> <td>Phone</td> <td><input type="text" name="gl_phone" maxlength="20"value="<?php echo $_POST['gl_phone']; ?>"></td></tr> <tr> <td>Contact</td> <td><input type="text" name="gl_contact" maxlength="20"value="<?php echo $_POST['gl_contact']; ?>"></td></tr> <tr> <td>Fee</td> <td><input type="text" name="gl_net" maxlength="6" value="<?php echo $_POST['gl_net']; ?>"></td></tr> <tr> <td>Comments (internal)</td> <td><textarea rows="5" cols="17" name="gl_comments"><?php echo $_POST['gl_comments']; ?></textarea></td></tr> <tr> <td>Web text</td> <td><textarea rows="15" cols="17" name="gl_text"><?php echo $_POST['gl_text']; ?></textarea></td></tr> <tr><td>Private Function</td> <td><input type="checkbox" name="gl_pf" value="<?php echo $_POST['gl_pf']; ?>"><td></tr> <tr><td>Publish</td> <td><input type="checkbox" name="gl_publish" value="<?php echo $_POST['gl_publish']; ?>"/></td></tr> <tr><td>Unavailable</td> <td><input type="checkbox" name="gl_unavailable" value="<?php echo $_POST['gl_unavailable']; ?>"/></td></tr> <tr><td align="right" rowspan="2"><input type="submit" name="submit" value="update"></td></tr> </table> </form> <?php } ?> The problem is with the $id variable not being taken in the query in the right format (I think), where I have "...where gl_id = '$id'" im not getting a match - but if I hardcode "...where gl_id = '67'" I get the desired result. I'm echoing out $id at the top and that gives me '67' so i'm assuming that its the type that the query doesn't like. The db feild 'gl_id' is a 5 char Int. How can I match these up?
-
how do I put a border around each record from a table query???
dazzathedrummer replied to dazzathedrummer's topic in CSS Help
Hi, sorry the result of the php is here:- http://www.the-guards.org.uk/private/giglist_private.php -
how to edit records from form list??
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
Ok i'm getting somewhere now! I've managed to get the list to echo the ID number in the entry form (although it wont do it if the ID form element is hidden??). I'm just wondering if its best to query the db in the entry form to display the data and then update it - or 'post' the data into the form from the list and then update based on the ID number. Am I right in thinking that the later would be simpler as it doesn't involve querying the db? -
Hi, I have a fairly simple list coming from a php/mysql query - I'd like to put a border around each record to make the list more readable. I'm having trouble with this - if I set 'border=1' in the table tag, obviously the border goes around the whole table - I've tried putting the table in a div, but that has the same effect. can anyone help me on this - i'm sure its quite simple, I just haven't got there yet. here's my php include table: - echo' <h1>Gigs</h1> <table width=\"605\" height=\"200\" >'; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {echo " <tr> <td style=\"height:80px; width:80px;\"valign=\"top\"> <img height=\"79px\" width=\"79px\" valign=\"top\" alt=\"calendarpic\" style=\"position:absolute; vertical-align:top; z-index:1;\" src=\"calpics/{$row['background']}.png\"/> <img height=\"79px\" width=\"79px\" valign=\"top\" alt=\"calendarpic1\" style=\"position:absolute; vertical-align:top; z-index:2;\" src=\"calpics/{$row['day']}.png\"/> <img height=\"79px\" width=\"79px\" valign=\"top\" alt=\"calendarpic2\" style=\"position:absolute; vertical-align:top; z-index:3;\" src=\"calpics/{$row['month']}.png\"/></td>". "<td colspan=\"3\"><font size=\"4\"><strong>{$row['gl_venue']}</td><td>{$row['gl_pf']}<br>{$row['gl_publish']}<br>{$row['gl_unavailable']}</td></tr>". "<tr><td width=\"495\" colspan=\"3\">{$row['gl_text']}</td></tr>". "<tr><td><b>Fee</td><td><strong>Phone</strong></td><td><b>Contact</td></tr>". "<tr><td>{$row['gl_net']}</td><td width=\"150px\">{$row['gl_phone']}</td><td>{$row['gl_contact']}</td></tr>". "<tr><td><strong>Comments</td></tr>". "<tr ><td height=\"20px\" colspan=\"3\">{$row['gl_comments']}</tr></td>". "<td colspan=\"2\"><a href=\"http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q={$row['gl_postcode']}\">Click for map</a></td><td><input type=\"submit\" value=\"edit\"></td></tr>"; } echo '<tr style=\"height:40px\"></tr></tr></table><br><br>'; ?>
-
how to edit records from form list??
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
ok, yeah I know - slight amount of lazyness haha. so, do I need to capture $_post records for the selected db record and then set them as the form 'values' on the entry form? if so, how do I get the ID of the particular record that i'm selecting - that's what's confusing me?? -
Hi, I have a php 'gig' list http://www.the-guards.org.uk/private/giglist_private.php that I have also written a basic (no validation yet) entry form for http://www.the-guards.org.uk/private/giglist_private_entry.php I would like to be able to have members 'edit' entries on the list by clicking the 'edit' button that I have on each record. When the 'edit' button is pressed I would like the user to be taken back to the entry form with the selected record shown in the form for editing - how do I go about this. I understand the principle - populate the form with the values of the fields in the record where the row ID = 'x' and then update table where row ID = 'x'. but i'm unsure how to go about coding this. any help would be greatly appreciated.
-
CSS/formatting problem when using an include
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
i'll try that - thanks for all your help!! darren -
CSS/formatting problem when using an include
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
almost there now!! i'd deleted the closing table tag! I cant seem to get the images to 'align="top"' they seem to default to bottom (valign doesnt work either). I read about using css float, but that only seems to do left and right?? -
CSS/formatting problem when using an include
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
excellent thanks for the link, i've managed to clean everything up but I think now i've broken the IMG tags in the php. I cant spot where it might be going wrong and my server doesn't give me errors (and I cant figure out why apache wont run on my laptop). can anyone spot why this wont run: - <?php // Connects to your Database mysql_connect("database.lcn.com", "LCN_7792", "theguards9402") or die(mysql_error()); mysql_select_db("the_guards_org_uk_users") or die(mysql_error()); $query = "SELECT (left(LCASE(monthname(gl_date)),3)) as 'month', day(gl_date) as 'day',gl_date, gl_venue, gl_venue, gl_city, gl_postcode, gl_phone, gl_contact, gl_net, gl_comments FROM tg_gig_list order by gl_date desc"; $result = mysql_query($query); echo' <h1>Gigs</h1> <table border="0"><tr> <th>Image</th> <th>Month</th> <th>day</th> <th>Venue</th> <th>City</th> <th>Postcode</th> <th>Phone</th> <th>Contact</th> <th>Net</th> <th>Comments</th> </tr>'; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo " <tr> <td style=\"height:80; width:80;\"> <img height=\"79\" width=\"79\" alt=\"calendarpic\" style=\"position:absolute;display:block;z-index:1;\" src=\"calpics/background.png\"> <img height=\"79\" width=\"79\" alt=\"calendarpic1\" style=\"position:absolute;z-index:2;\" src=\"calpics/{$row['day']}.png\"> <img height=\"79\" width=\"79\" alt=\"calendarpic2\" style=\"position:absolute;z-index:3;\" src=\"calpics/{$row['month']}.png\"></td>". "<td>{$row['month']}</td>". "<td>{$row['day']}</td>". "<td>{$row['gl_venue']}</td>". "<td>{$row['gl_city']}</td>". "<td>{$row['gl_postcode']}</td>". "<td>{$row['gl_phone']}</td>". "<td>{$row['gl_contact']}</td>". "<td>{$row['gl_net']}</td>". "<td>{$row['gl_comments']}</td></tr>"; } </tr> </table>'; echo $row; mysql_close(); ?> thanks -
CSS/formatting problem when using an include
dazzathedrummer replied to dazzathedrummer's topic in PHP Coding Help
Correction - sorry. giglist.php does not contain embeded CSS - it has a specifically formatted table. The row and cell heights are not being recognised when used as an include.