Jump to content

Buttero

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by Buttero

  1. Hey, I wanna add a new button to this there is already a buttob to press for bold , and italic, i want to add one for paragraph (<p>) here is my current code: <script language="JavaScript" type="text/javascript"> <!-- // global variable for textarea and menubar (i'm lazy, what can i say?) var ta; var bar; function init() { // init global variables ta = document.getElementById("ta"); bar = document.getElementById("bar"); if(ta.selectionStart != undefined) { // has support for DOM2 Ranging in textarea ta.addEventListener("keypress", checkKey, true); // add listener bar.style.display = "block"; // unhide the sucker } } function checkKey(evt) { // debug window.status = evt.charCode; if (evt.ctrlKey != true) return; if (evt.shiftKey != true) return; // t or if(evt.charCode == 116 || evt.charCode == 84) { tag('em'); } // b or B if(evt.charCode == 66 || evt.charCode == 98) { tag('strong'); } } function tag(tag) { start = ta.selectionStart; end = ta.selectionEnd; // Split before, sel, after and insert tags in between before = (ta.value).substring(0, start); sel = (ta.value).substring(start, end); after = (ta.value).substring(end, ta.textLength); ta.value = before + "<" + tag + ">" + sel + "</" + tag + ">" + after; // focus ta.focus(); ta.selectionStart = end + 5 + (tag.length * 2); ta.selectionEnd = ta.selectionStart; } //--> </script>
  2. Hey guys! I've just got a contact script working, but when I recive the email, all the info is hard to distinguish visually. e.g: From:nameEmail:emailMessage:message It displays like that, does anyone know how to seperate them all? I tried to wrap each of them in <p> tags, but that just showed up as text in the email. Here is the code: <?php if(isset($_POST['submit'])) { $to = "lol@gmail.com"; $subject = "Contact"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "From: $name_field E-Mail: $email_field Message:\n $message"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); } else { echo "blarg!"; } ?> Any help would be greatly apprichiated, Thanks
  3. ok it now looks like it does something, it successfully goes to the index page, but never deletes anytihng, heres the code: <?php $host="localhost"; // Host name $username="#"; // Mysql username $password="#"; // Mysql password $db_name="#"; // Database name $tbl_name="#"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result = mysql_query($sql)or die(mysql_error()); $count=mysql_num_rows($result); ?> <div id="nav"> <? include("nav.php"); ?> </div> <form name="mysql" method="post" action=""> <h1>Delete multiple rows in mysql</h1> <?php while($rows=mysql_fetch_array($result)){ ?> <table width="100%" border="1"> <tr> <td valign="top"></td> <td valign="top"><strong class="title">Title</strong></td> <td valign="top"><strong class="title">Date</strong></td> <td valign="top"><strong class="title">Author</strong></td> </tr> <tr> <td valign="top"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td valign="top"><? echo $rows['title']; ?></td> <td valign="top"><? echo $rows['date']; ?></td> <td valign="top"><? echo $rows['user']; ?></td> </tr> </table> <?php } ?> <input name="delete" type="submit" id="delete" value="Delete"> <?php if(isset($_POST['delete'])){ foreach($_POST['checkbox'] as $no => $del_id){ $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">"; } } ?> </form>
  4. <?php $host="localhost"; // Host name $username="user"; // Mysql username $password="pass"; // Mysql password $db_name="dbname"; // Database name $tbl_name="tblname"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <div id="nav"> <? include("nav.php"); ?> </div> <form name="mysql" method="post" action=""> <h1>Delete multiple rows in mysql</h1> <?php while($rows=mysql_fetch_array($result)){ ?> <table width="100%" border="1"> <tr> <td valign="top"></td> <td valign="top"><strong class="title">Title</strong></td> <td valign="top"><strong class="title">Date</strong></td> <td valign="top"><strong class="title">Author</strong></td> </tr> <tr> <td valign="top"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td valign="top"><? echo $rows['title']; ?></td> <td valign="top"><? echo $rows['date']; ?></td> <td valign="top"><? echo $rows['user']; ?></td> </tr> </table> <?php } ?> <input name="delete" type="submit" id="delete" value="Delete"> <? // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">"; } } mysql_close(); ?> </form> Its a simple checkbox, if you check it and press the delete button, its meant to wipe if from the table, but noting happens :'( Can anyone help???
  5. Hey, does anyone know why this insertAtCursor isnt working for me?: <a href="javascript:insertAtCursor($('textarea'),'<img src=%22%22>');">Image</a></code> Thats all the javascript I have, and Im assuming that i dont need to add anything else in the page to make it work. I want it to insert an image tag when you click it, like what we have here on the left. I dont know what to put in the ' ($('textarea'') ' part either. Here is the whole form im using this in: <code><form method="post" action="idontthinkso.php"> <fieldset> <legend>Submit new frontpage news article</legend> <label for="user">Username:</label><br> <select name="user"> <option>Namel</option> </select> <input name="date" type="hidden" value="Wed Jan 31, 2007 "><br> <label for="title">Title:</label><br> <input name="title" type="text"> <br> <a href="javascript:insertAtCursor($('textarea'),'<img src=%22%22>');">Image</a> <label for="description">Description:</label><br> <textarea name="description" cols="50" rows="20" wrap="virtual"></textarea> <br> <p><input name="submit" type="submit" value="Submit"> </p> </fieldset> </form> I am not using prototype, and I dont have a function defined, this is my first time with javascript and I dont know what to do now! ???
  6. Hey all, I've recently made a very simple CMS, add news, and delete news. However I wanna expand on this and add two new things: [list] [*]The ability to edit a news article straight from the CMS [*]Show login name e.g. Buttero, log out [/list] I dont have any clue on how to do the first, and for the log in, Im just using Cpanels 'Password protect directory' to protect it, but with this I cant display the user thats logged in. Any help on this would be greatly apprichiated, and any other tips on what to add in my CMS would also help, Thanks in advance  :)
  7. Hey all, I want to make the logo in my website change when someone puts the cursor over it. Like a rollover image. Here is my CSS but it dosent seem to be working: [code]/* Main Style */ body { font-family: arial, trebuchet ms, verdana; } #header {} #header #logo { height: 55px; width: 90px; } #header a:link { background: url(img/logo.gif) no-repeat; height: 55px; width: 90px; } #header a:hover { background: url(img/logo-over.gif) no-repeat; height: 55px; width: 90px; } #header a:active { background: url(img/logo-over.gif) no-repeat; height: 55px; width: 90px; } #header a:visited { background: url(img/logo-over.gif) no-repeat; height: 55px; width: 90px; } [/code] [code]<body> <div id="header">   <a href="/">   <div id="logo"><img src="img/logo.gif"></div>   </a> </div> </body>[/code]
  8. I have coded a content managment system and on the submit.php page i have a series of feilds. However I have to go through the annoying task of hand coding all the tags like <!-- <img blah blah --> and all that crap. What I want is a button that i can click, and it automatically puts the opening img tag in there. And then when I click again, it closes the tag. The same for bold text etc. Anyone have any ideas or script? :)
  9. I have made a search form for my website. When your search gets results a notification box comes up saying "The below articles contain the search term $search" This all works fine. But when there are no results for the search, I would like to stop this notification box from appearing, I have added a line of code to say "Sorry no results were found" but the notification box still appears. You can see this by going to seski.co.uk and searching some random letters. As you can see the box with the tick icon comes up, however there is a message below saying there was no results. What I want to do is make the notification box not appear when there is no results. And to display a different box with a different icon and font color etc. Here is my code: [code]<? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","oo","oo"); //select which database you want to edit mysql_select_db("oo"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM frontpage_news WHERE description LIKE '%$search%'"); //grab all the content while($r=mysql_fetch_array($result)) {   //the format is $variable = $r["nameofmysqlcolumn"];   //modify these to match your mysql table columns     $title=$r["title"];   $description=$r["description"];   $user=$r["user"];   $date=$r["date"];   $id=$r["id"];     //display the row echo "<h2>".$title."</h2>"; echo "<h3>".$date." by ".$user."</h3>"; //explode $description into array and remove search keyword $exp_desc = explode($search, $description); //get number of parts to array $num = count($exp_desc); //loop through array for($x=0;$x<$num;$x++) { //display text from array echo $exp_desc[$x]; //check if it is last entry in array if($x+1 != $num) { //display formatted search keyword echo "<b>".$search."</b>"; } } echo "<hr>"; } if(mysql_num_rows($result) == o) echo "Sorry, no results were found." ?> [/code] Thanks in advance
  10. ah ok, now i get a better explained error: [quote]The query SELECT * FROM frontpage_news WHERE id= Caused the following error You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1[/quote] ???
  11. I upload this script to my server at Seski with all the username and pass updated. It worked fine until I clicked the news article I wanted to edit. Then this error message showed up: [quote]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/blah/public_html/q/edit.php on line 36[/quote] Here is edit.php [code]<? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","password"); //select which database you want to edit mysql_select_db("spoono_sections"); //If cmd has not been initialized if(!isset($cmd)) {   //display all the news   $result = mysql_query("select * from news order by id");     //run the while loop that grabs all the news scripts   while($r=mysql_fetch_array($result))   {       //grab the title and the ID of the news       $title=$r["title"];//take out the title       $id=$r["id"];//take out the id     //make the title a link       echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";       echo "<br>";     } } ?> <? if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") {   if (!isset($_POST["submit"]))   {       $id = $_GET["id"];       $sql = "SELECT * FROM news WHERE id=$id";       $result = mysql_query($sql);        [b]      $myrow = mysql_fetch_array($result);[/b]       ?>         <form action="edit.php" method="post">       <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">         Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>       Message:<TEXTAREA NAME="message" ROWS=10 COLS=30><? echo $myrow["message"] ?></TEXTAREA><br>       Who:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["who"] ?>" SIZE=30><br>         <input type="hidden" name="cmd" value="edit">         <input type="submit" name="submit" value="submit">         </form>   <? } ?> <?   if ($_POST["$submit"])   {       $title = $_POST["title"];   $message = $_POST["message"];   $who = $_POST["who"];     $sql = "UPDATE news SET title='$title',message='$message',who='$who' WHERE id=$id";       //replace news with your table name above       $result = mysql_query($sql);       echo "Thank you! Information updated."; } } ?> [/code] The bold part is line 36 like the error said.
  12. Thanks for evryones input. I would like to further enhance the search form so it accepts higher and lower case. I saw earlier that I run into problems if i search someones name in all lower case, the result still shows however the search term dosent appear bold because the first letter is capital. For example, when i search "billy" the article with the term "Billy" will still show up, but the term wont be made bold. This is because its not the exact same term, because of the capital letter. Maybye there is some sort of code i can put in there so that no matter what case the word is in, it will always appear as bold as long as it is a search term. :)
  13. thanks so much its working great now
  14. this is the code: [code]<? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","pass"); //select which database you want to edit mysql_select_db("blah"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM frontpage_news WHERE description LIKE '%$search%'"); //grab all the content while($r=mysql_fetch_array($result)) {   //the format is $variable = $r["nameofmysqlcolumn"];   //modify these to match your mysql table columns     $title=$r["title"];   $description=$r["description"];   $user=$r["user"];   $date=$r["date"];   $id=$r["id"];     //display the row echo "<h2>".$title."</h2>"; echo "<h3>".$date." by ".$user."</h3>"; $description = explode($search, $description); foreach ($description as $part) { echo $part; $num = count($description) for ($i=0; $i < $num; $i++) { echo $part[$i]; if ($i != ($num-1)) { echo "".$search.""; } }} echo "<hr>"; } ?>[/code] But i get this error Parse error: syntax error, unexpected T_FOR in /home/jcardus1/public_html/search.php on line 77 This was the code before I edited it: [code]<? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","pass"); //select which database you want to edit mysql_select_db("blah"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM frontpage_news WHERE description LIKE '%$search%'"); //grab all the content while($r=mysql_fetch_array($result)) {   //the format is $variable = $r["nameofmysqlcolumn"];   //modify these to match your mysql table columns     $title=$r["title"];   $description=$r["description"];   $user=$r["user"];   $date=$r["date"];   $id=$r["id"];     //display the row echo "<h2>".$title."</h2>"; echo "<h3>".$date." by ".$user."</h3>"; $description = explode($search, $description); foreach ($description as $part) { echo $part; echo "<b>".$search."</b>"; } echo "<hr>"; } ?> [/code] thanks for all the help so far
  15. Ah ok. I can understand the problem now, so we need to get the php to realise the last value and not to display the term. Since I dont know how to code php from scratch im guessing this could be a problem?  :'( ::)
  16. this script works perfect thanks for the help. But all thats wrong is the repeated search term at the bottom  ??? if i search any random word, the word is nicely made bold in the post where it appears, but then the word just reappears at the bottom  :( Thanks for making it work better
  17. Sure  :) [code]<? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","pass"); //select which database you want to edit mysql_select_db("db"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM frontpage_news WHERE description LIKE '%$search%'"); //grab all the content while($r=mysql_fetch_array($result)) {   //the format is $variable = $r["nameofmysqlcolumn"];   //modify these to match your mysql table columns     $title=$r["title"];   $description=$r["description"];   $user=$r["user"];   $date=$r["date"];   $id=$r["id"];     //display the row echo "<h2>".$title."</h2>"; echo "<h3>".$date." by ".$user."</h3>"; $description = explode($search, $description); foreach ($description as $part) { echo $part; echo "<b>".$search."</b>"; } echo "<hr>"; } ?>[/code]
  18. yea but this makes it so that only the repeated search term at the bottom is highlighted  :-\
  19. This seems to screw it up  :( It dosent matter if its bold, as long as its different in style. However the search term keeps appearing at the bottom  :o. Its because after all the search terms are made bold there is still: [code]echo "<b>".$search."</b>"; [/code] At the bottom of the script, witch repeats the search term. Is there any way to get around this without stopping the search term being bold in the actual post? Thanks
  20. ahh, my bad, i know what was making the random symbols. They were out of the php, probarbly just some of the old code that didnt get fully deleted. Here is the code: [code]<? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","password"); //select which database you want to edit mysql_select_db("database"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM frontpage_news WHERE description LIKE '%$search%'"); //grab all the content while($r=mysql_fetch_array($result)) {   //the format is $variable = $r["nameofmysqlcolumn"];   //modify these to match your mysql table columns     $title=$r["title"];   $description=$r["description"];   $user=$r["user"];   $date=$r["date"];   $id=$r["id"];     //display the row echo "<h2>".$title."</h2>"; echo "<h3>".$date." by ".$user."</h3>"; $description = explode($search, $description); foreach ($description as $part) { echo $part; echo "<b>".$search."</b>"; } echo "<hr>"; } ?> [/code]
  21. ah, now its working much better. i replaced the old echo $search with the new one to make it bold. Now all the terms that were searched in the post appear bold. However, if you look at the bottom of the page once you search, there is the search term repeated for no reason, in this case "Billy" and this random selection of symbols ""; } ?>" Maybye they somehow escaped the PHP? Thanks for making this work so far! :)
  22. Thanks for the help so far. Now I sort of understand whats going on in the last snippet of code that I changed. But no highlighting is happening still  ???. You can see the problem if you search on seski for the word Billy for example. At the bottom of the page it just says "billy" then some random code appears  :-\ I dont know how to get around this
  23. [quote author=chiprivers link=topic=117195.msg477881#msg477881 date=1165161471] Just had a quick look at how to use explode() and it would be slightly different to what I said.  When exploding a string you set a delimiter for which it searches for and uses to split up the original string into the array. In doing this, it removes the delimiter altogether so you would not end up with any values in the array equal to the search keyword, this actually makes it a bit simpler as you know that between every two values in the array, there should be your keyword. so try this: [code] $description = explode($search, $description); foreach ($description as $part) { echo $part; echo $search; // add any highlighting in this section } [/code] This will all need to fit in where you have displayed $description.  It may need some slight alteration, it is not something i have done before. [/quote] I put this in the echo where I display the search results. however nothing is highlighted. You can see at www.seski.co.uk and search for "Billy". Here is the code when i added the new snippet [code]<? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","password"); //select which database you want to edit mysql_select_db("database"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM frontpage_news WHERE description LIKE '%$search%'"); //grab all the content while($r=mysql_fetch_array($result)) {   //the format is $variable = $r["nameofmysqlcolumn"];   //modify these to match your mysql table columns     $title=$r["title"];   $description=$r["description"];   $user=$r["user"];   $date=$r["date"];   $id=$r["id"];     //display the row   echo " <h2>$title</h2> <h3>$date by $user</h3> $description = explode($search, $description); foreach ($description as $part) { echo $part; echo $search; // add any highlighting in this section } <hr> "; } ?> [/code]
  24. Thanks for the quick reply Chiprivers. If this approach works that would be great. The thing is, I would not know where to start when It comes to implementing this into the origional code.  :(. Thanks again
  25. Hey all, I'm new to PHP, and I've just found this PHP search script. I've edited so it works fine. But I was wondering if anyone knew how to actually highlight the search term once the articles containing this search word are found. For example, If you search for "Hello" then the php finds all the mysql entries with the word "Hello" in the $description feild. However, I would like to highlight the word "Hello" in the found articles. The php code is below: [code]<? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","user","password"); //select which database you want to edit mysql_select_db("database"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM frontpage_news WHERE description LIKE '%$search%'"); //grab all the content while($r=mysql_fetch_array($result)) {   //the format is $variable = $r["nameofmysqlcolumn"];   //modify these to match your mysql table columns     $title=$r["title"];   $description=$r["description"];   $user=$r["user"];   $date=$r["date"];   $id=$r["id"];     //display the row   echo " <h2>$title</h2> <h3>$date by $user</h3> $description <hr> "; } ?> [/code] Thanks for your time
×
×
  • 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.