Everything posted by smileyboy
-
strip slashes, ', ", and <br />
Jem, can you help me insert that into my code - this is as close as I have got - I'm sure it is pretty close? Thanks for your help so far... Entering the Data: if (isset($_POST['submitted'])) { if (empty($_POST['welcome'])) { $errors[] = 'Please enter a welcome message.'; } else { $w = mysqli_real_escape_string($dbc, trim($_POST['welcome'])); $q = "UPDATE body_text SET welcome='$w' WHERE body_text_id=$id LIMIT 1"; $r = @mysqli_query($dbc, $q); Retrieving the Data on the same page (editing text page): $q = "SELECT welcome, news, recommends, guest_writer, previews, live_reviews, cd_reviews, about, contacts, competition FROM body_text WHERE body_text_id=$id"; $r = @mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form. // Get the user's information: $row = mysqli_fetch_array ($r, MYSQLI_NUM); echo '<form action="edit_text2.php" method="post"> <p>Welcome: <br /><textarea name="welcome" rows="10" cols="50" value= > 'stripslashes('.$row['0'].')' </textarea> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> Retrieving the data on another page (but not editable): $q = "SELECT news AS n, welcome AS w FROM body_text"; $r = @mysqli_query ($dbc, $q); echo stripslashes(nl2br($row['w']));
-
Having trouble carrying over key id from one page to the next
Thanks Ben ... that's sorted it!
-
Font Styles
Thanks for the tips ... I'll go through and remove the font tags Thanks again
-
Unable to fugure out isset() and empty() for this page
I simply want to show a heading (and the associated string) if there is a string present in the table. If the table contains no strings in that colums I dont want to show the heading or the string. This is what I have so far but it is not recognising from the table whether there is a string present or not: Almost there with this website by the way .... require_once ('../mysqli_connect.php'); // Make the query: $q = "SELECT band_name AS bn, genera AS g, music_description AS md, biog AS b, gig_history AS gh, gig_future AS gf, reviews AS re FROM band_members WHERE band_id='$id'"; $r = @mysqli_query ($dbc, $q); // Run the query. if ($r) { // If it ran OK, display the records. // Fetch and print records if present: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { if (isset($) { echo "<h5>Biograpgy</h5>"; echo stripslashes(nl2br($row['b'])); } if (!empty($) { echo "<h5>Biograpgy1</h5>"; echo stripslashes(nl2br($row['b'])); }
-
Turning text into Sentence Form
Is there a variation of ucfirst () which will convert to sentince form - ie Capitalises after every full stop (.) but leaves already existing words capitalised? so hi I am enjoying the Webdesigners forum. it's really cool. would change to: Hi I am enjoying the Webdesigners forum. It's really cool.
-
strip slashes, ', ", and <br />
I thought mysql_real_escape_string removes other stuff to make the code safer? I'm new to this and was never really told what it did, just that you should always use it ...
-
Having trouble carrying over key id from one page to the next
I’m trying to make this link work. The first page makes a list of bands. Each has a hyperlink to a page based on their band_id (key value of band_members table). The first page displays correctly and the link looks correct in the new page: http://localhost/bandinfo.php?id=31 where id=31 changes correctly depending on the artist clicked on. My code in the bandinfo.php page is not picking up the id value. The page will display correctly if I force the code to be id=31. How do I include the id from the previous page in this code? Thanks for any help... Page 1: artists.php $page_title = 'Artists'; require_once ('../mysqli_connect.php'); // Connect to the db. $q = "SELECT band_id, genera, band_name, music_description FROM band_members ORDER BY genera , band_name"; $r = mysqli_query($dbc, $q); $currentGenre = ''; while ($messages = mysqli_fetch_array($r, MYSQLI_ASSOC)) { if ($currentGenre != $messages['genera']) { echo "<h2>{$messages['genera']}</h2>\n"; $currentGenre = $messages['genera']; } echo "<a href=bandinfo.php?id={$messages['band_id']}><h5> {$messages['band_name']}</h5></a><br /> {$messages['music_description']}<br /><br />\n"; } mysqli_free_result ($r); mysqli_close($dbc); // Close the database connection. Page 2: bandinfo.php: session_start(); $page_title = 'Band Details'; require_once ('../mysqli_connect.php'); $q = "SELECT band_name AS bn, genera AS g, music_description AS md, biog AS b, gig_history AS gh, gig_future AS gf, reviews AS re FROM band_members WHERE band_id='$id'"; $r = @mysqli_query ($dbc, $q); if ($r) { // If it ran OK, display the records. // Fetch and print all the records: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo stripslashes(nl2br($row['bn'])); echo stripslashes(nl2br($row['g'])); echo '<h1>News</h1>'; echo stripslashes(nl2br($row['md'])); } mysqli_free_result ($r); } else { error messages …
-
Navigation buttons with images controled by PHP
I knew I was close. After looking at you code all I needed to do was change the = to == in: ($page_title == 'news') And it works well. Thanks again ... big time...
-
Navigation buttons with images controled by PHP
Still can't get it to work, so I've tried to aproach it differently but still not working. I think this only needs a few tweaks to get it working: each page has (news, about etc) has $page_title = 'news'; And I'm trying to add this so it knows which picture to show. It unfortunantly is showing news2.jpg all the time even when I navigate to 'news' or 'about' etc: <?php if ($page_title = 'news'){ echo '<a href="index.php"><img src="images/news2.jpg" border="0" ></a>'; }else{ echo '<a href="index.php"><img src="images/news.jpg" border="0" ></a>'; } ?> Can anyone help?
-
Drop down truncating words when sending to table
Works a treat thanks ...
-
Font Styles
Both those tricks work well. I did not realise the dot (.) infront of the style defines it as one you made up. to get rid of the paragraph break i replaced <p class="S1"></p> with <font class="S1"></font>. Now works a treat ... Thanks again
-
strip slashes, ', ", and <br />
Ok ... After trying to solve this all day, I manage to solve it 1 hour after posting. If anyone is interested: $w = mysqli_real_escape_string($dbc, stripslashes(trim($_POST['welcome']))); This is probably not the neatest solution ... but it works.
-
strip slashes, ', ", and <br />
Ok I've mannaged to work out using echo nl2br($row['w']) to show the line breakes correctly. Still not solved the slashes ...
-
strip slashes, ', ", and <br />
I'm going crazy here ... I simply want to UPDATE data in a table: $w = mysqli_real_escape_string($dbc, trim($_POST['welcome'])); $q = "UPDATE body_text SET welcome='$w', news='$ne' WHERE body_text_id=$id LIMIT 1"; When I do this I get a backslash every time I enter a singe or double quotation mark (') or ("). I can't make stripslashes() work ... I'm not really sure where it goes. I also need page return (ie hitting enter) to work too - at the moment it is going into the table with a return, but not when being called? Any help please ... PHP v 5.2.5
-
Drop down truncating words when sending to table
Hope this is any easy one: When I select a 2 word value from the make_catagory_pulldown() it only sends the first word to the database table. Is there an easy fix for this? Ideally I'd like to pulldown to be made from a column in a database ... can anyone show me the script for this? Thanks very much for any help ... This is the script I am using: function make_catagory_pulldown() { $catagory = array (1 => '', 'Hairdressers', 'Media', 'Music Shops', 'Performance Artists', 'Promotions', 'Recording Studios', 'Rehersal Space'); echo '<select name="catagory">'; foreach ($catagory as $key => $value) { echo '<OPTION value='.$value.'> '.$value.''; // this causes the genera to be included rather than the key position } echo '</select>'; } // Check for catagory: if (empty($_POST['catagory'])) { $errors[] = 'You forgot to enter the catagory.'; } else { $ca = mysqli_real_escape_string($dbc, trim($_POST['catagory'])); } <p>Company Name: <input type="text" name="company" size="40" maxlength="100" value="<?php if (isset($_POST['company'])) echo $_POST['company']; ?>" /></p>
-
Navigation buttons with images controled by PHP
Still having a little trouble: I've tried to insert the code without much success. This is what I have at the moment more or less although it is over a number of 'inserted' files: <?php #index.php session_start(); $page_title = 'Main Title'; # defult page title <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo $page_title; ?></title> <link rel="stylesheet" href="includes/mainstyle.css" type="text/css" media="screen" /> </head> <body> ?> <div class="ts_6"><a href="index.php"><img src="images/news.jpg" border="0" ></a></div> <div class="ts_7"><a href="artists.php"><img src="images/artists.jpg" border="0" ></a></div> <div class="ts_8"><a href="industry.php"><img src="images/industry.jpg" border="0" ></a></div> <div class="ts_9"><a href="gigs.php"><img src="images/gigs.jpg" border="0" ></a></div> <div class="ts_10"><a href="reviews.php"><img src="images/reviews.jpg" border="0" ></a></div> <div class="ts_11"><a href="about.php"><img src="images/about.jpg" border="0"></a></div> <div class="ts_12"><a href="competition.php"><img src="images/competition.jpg" border="0" ></a></div> And I have put into the styles (mainstyles.css) sheet: .active_news:link , .active_news:visited { background-image: url(images/news2.jpg); } .active_artists:link , .active_artists:visited { background-image: url(images/artists2.jpg); } .active_industry:link , .active_industry:visited { background-image: url(images/industry2.jpg); } .active_gigs:link , .active_gigs:visited { background-image: url(images/gigs2.jpg); } .active_reviews:link , .active_reviews:visited { background-image: url(images/reviews2.jpg); } .active_about:link , .active_about:visited { background-image: url(images/about2.jpg); } .active_competitions:link , .active_competitions:visited { background-image: url(images/competitions2.jpg); } Could you help me insert either of the codes above to make the buttons work (switch when active)?
-
Font Styles
This should be an easy one ... but I'm having trouble finding the answer: I can work out how to define a new style for headers eg <h1> </h1> but as they are headers they add a couple of <br /> automatically. I have tried to define other variables eg <S1></S1> in the style sheet. They display ok in mozilla but not in explorer. Are there a set of pre defined text options that I can change like the header (<h1>) ones in the style sheet? in my style sheet, this does not display <S1></S1> text correctly: S1 { font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 14px; color: #EF047E; }
-
Formatting Tables/lists
And it's working well ... Top stuff.
-
Formatting Tables/lists
Fab - I'll give that a try and let you know how I get on ...
-
Keeping text Formatting when inputting data
I'm currently using this to enter data into the table: eg1 $w = mysqli_real_escape_string($dbc, trim($_POST['welcome'])); eg2 $w = mysqli_real_escape_string($dbc, str_replace("\\r\\n",'<br>',trim($_POST['welcome']))); eg3 $w = mysqli_real_escape_string($dbc, nl2br(trim($_POST[welcome]))); this re displays the data after entering it (in the editing box): $row = mysqli_fetch_array ($r, MYSQLI_NUM); Welcome: <br /><textarea name="welcome" rows="10" cols="50" value= >' . $row[0] . '</textarea> This is used to display it when referring to it in the 'news' section of the website: $q = "SELECT news AS n, welcome AS w FROM body_text"; $r = @mysqli_query ($dbc, $q); if ($r) { while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<h1>Welcome</h1>'; echo $row['w']; //'</td><td align="left">' . $row['n'] . '</td></tr> Most of the inputs are in sentence form. I want to keep formatting if the entered data has carriage returns, I would like simple HTML if the user chose to use these (bold, italics and links etc), and I want to make it (fairly) secure. eg1 is no good as it adds / and there is no HTML formatting or returns. eg2 is ok but you have to manually put in the html formatting for carriage returns eg3 is almost there, in the editing box it replaces the returns with <br />. If you update the text again it adds another <br /> to and returns which is no good. eg: enter this: hello welcome to this site Looks like this in the text box after updating: hello <br /> welcome to this site But if you were to make another change (add 'everyone') it looks like this: hello everyone <br /> <br /> welcome to this site Both eg 2 and 3 look correct in the final display in the website (apart from the increasing number of carriage returns). All I want to do is keep formatting if the entered data has carriage returns, have simple HTML and not be too insecure. Phew ... any help ...?
-
Formatting Tables/lists
for my example there will definently not be any artists entered twice. I have tried to get my head around normalisation and how to call results from more than one table but have not understood it yet. So would like to find a solution using the same table... the closest I have got is this, but it prints the first genre only once and does not print the next genre. It then lists all artists and albums down the page... $printed = FALSE; // Flag variable. // Fetch each: while ($messages = mysqli_fetch_array($r, MYSQLI_ASSOC)) { // print the genre once if (!$printed) { echo "<h2>{$messages['genre']}</h2>\n "; $printed = TRUE; } echo "{$messages['artist']} <br /> {$messages['album_name']} <br /><br /><br />\n"; }
-
Formatting Tables/lists
This should be simple but I am struggling. I want to create a list of music that looks like this: rock album1 artist1 album2 artist2 blues album3 artist3 album4 artist4 etc. I have a table (music) with a key, and a column for each 'genre' 'album_name' and 'artist'. I can't work out the PHP/mySQL code to make it list each genre only once as a heading. Also want to order it alphabetically but genre then artist name but that should be no problem. Thanks for any help ...
-
Navigation buttons with images controled by PHP
Thanks Kenv That's great too.
-
Navigation buttons with images controled by PHP
you are fantastic. Thank you both ...
-
Navigation buttons with images controled by PHP
.active:link , .active:visited { background-image: url(images/news2.jpg); } I just want to double check that I can use a different active jpg for each button. I have seen code similar to this and I thought it was just using the same image to highlight the button. So below are an example of the 2 images, new.jpg will be the non active state and news2.jpg will be the active state (remember I also have 6 other buttons about.jpg/about2.jpg, contact.jpg/contact2.jpg etc etc). So can the above code be repeated for each different version of the button? That is, do I have to define in the CSS when to use the above code for each button? Thanks so far ... was getting severe cold sweats before ...