PHP - Php And Mysql Probelm
i currently have this code...i got a problem calling out words from my database....my database name is "bad_replace" and the list of my bad words is "word"....my codes only pick out some of my bad words out of database and not all what i declared on my database....like when i post the word "motherfucker" it becomes "mother******" but if i post "tanga" which a bad word from our country it doesn't replace into "*****" since that word is also on my database.......please help... thanks.....
Code: [Select] <?php include('connect.php'); function swear_filter($string) { $bad_words = array(); $sql = mysql_query("SELECT * FROM bad_replace"); if (mysql_num_rows($sql) > 0) { while ($row = mysql_fetch_assoc($sql)) { $bad_words[] = '/\b' . $row['word'] . '\b/i'; $replacement[] =$row['replacement']; } } } $string_to_check = ""; $completed_filter = ""; $finished_filter = ""; if ($_POST['submit']) { echo swear_filter($_POST['string']); } ?> <hr /> <center><form action='swear_filter.php' method='POST'> <br><textarea name='text' rows="10" cols="75></textarea><br /> <input type='submit' name='submit' value='Post'></p></center> </form> Similar TutorialsIf I can get this fixed, I will have completed all but the admin login for this project - my first php/mysql project. Here is what I need. I have a list_records.php that list all the records in the table 'links' and the category each entry is in from the table 'categories'. Here are my table structures. Code: [Select] -- Table structure for table `categories` -- DROP TABLE IF EXISTS `categories`; CREATE TABLE IF NOT EXISTS `categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `categories` varchar(37) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=40 ; -- -------------------------------------------------------- -- -- Table structure for table `links` -- DROP TABLE IF EXISTS `links`; CREATE TABLE IF NOT EXISTS `links` ( `id` int(4) NOT NULL AUTO_INCREMENT, `catid` int(11) DEFAULT NULL, `name` varchar(255) NOT NULL DEFAULT '', `url` varchar(255) NOT NULL DEFAULT '', `content` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`), KEY `catid` (`catid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ; On the update.php file, I have a form that lets me make changes to the record. Here is the codes for update.php Code: [Select] <? include "menu.php" ?> <? include "db.php" ?> <?php $id=$_GET['id']; $sql = "select * from links where id =$id"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)){ $id = $row['id']; $catid = $row['catid']; $name = $row['name']; $url = $row['url']; $content = $row['content']; //we will echo these into the proper fields } mysql_free_result($query); ?> <table width="65%" align="center"> <tr><td align="left"> <form action="updated.php" method="post"> <input type="hidden" value="<?php echo $id; ?>" name="id"/> <br> <b>Website Name:</B><br> Change the name of the website listing.<br> <input type="text" value="<?php echo $name; ?>" name="name"/> <br> <br> <b>URL:</b><br> Change the URL of the website listing.<br> <input type="text" value="<?php echo $url; ?>" name="url"/> <br> <br> <b>Description:</b><br> Change the description of the website listing.<br> Limit 255 characters.<br/> <textarea name="content" cols="45" rows="4" wrap="soft"><?php echo($content);?></textarea> <br> <?php $result = mysql_query("SELECT id, categories FROM categories") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $id = $rows["id"]; $categories=$row["categories"]; $options.= '<option value="'.$row['id'].'">'.$row['id'].'-'.$row['categories'].'</option>'; }; ?> <SELECT NAME=catid> <OPTION VALUE=selected><? echo $catid; ?><? echo $options; ?></OPTION> </SELECT> <?php mysql_close(); ?> <div align="center"> <input type="submit" value="submit changes"/> </div> </form> <br> </td></tr></table> The part of he code I need help with is Code: [Select] <?php $result = mysql_query("SELECT id, categories FROM categories") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $id = $rows["id"]; $categories=$row["categories"]; $options.= '<option value="'.$row['id'].'">'.$row['id'].'-'.$row['categories'].'</option>'; }; ?> <SELECT NAME=catid> <OPTION VALUE=selected><? echo $catid; ?><? echo $options; ?></OPTION> </SELECT> I want it to default to the category that the entry is in. If you look, you will see in the select portion that I I have Code: [Select] <$ echo $catid; ?> which echos the proper category ID, but if I use Code: [Select] <? echo $categories; ?> it echos Writing, which is the last category in the list. Yet, the $options echo the catid and it corresponding category. How can I get the default option to echo BOTH the catid and category name while also listing all the other categories so that the records can be moved to a new category is needed? Any help will be appreciated. Thank you in advance. This topic has been moved to Installation in Windows. http://www.phpfreaks.com/forums/index.php?topic=332859.0 currently i faced an error with undefined index id at line 3 at class_student.php ... smth wrong with my $get_id = $_GET['id']; .. mind take a look thank..
class_student.php file
<?php include ('session.php'); ?> <?php $get_id = $_GET['id']; include('header.php'); $user_query = mysql_query("select * from student where student_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?> <?php $query_class = mysql_query("select * from class where class_id='$get_id'") or die(mysql_error()); $row_class = mysql_fetch_array($query_class); $teacher_id = $row_class['teacher_id']; $teacher_query=mysql_query("select *from teacher where teacher_id='$teacher_id'")or die(mysql_error()); $teacher_row= mysql_fetch_array($teacher_query); ?> <body> <?php include('navhead_student.php'); ?> <div class="container"> <div class="row-fluid"> <div class="span3"> <div class="hero-unit-3"> <div class="alert-index alert-success"> <i class="icon-calendar icon-large"></i> <?php $Today = date('y:m:d'); $new = date('l, F d, Y', strtotime($Today)); echo $new; ?> </div> </div> <div class="hero-unit-1"> <ul class="nav nav-pills nav-stacked"> <li class="nav-header">Links</li> <li> <a href="student_home.php"><i class="icon-home icon-large"></i> Home <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a> </li> <li class="active"> <a href="student_class.php"><i class="icon-group icon-large"></i> Class <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> </ul> </div> </div> <div class="span9"> <a href="student_class.php" class="btn btn-success"><i class="icon-arrow-left"></i> Back</a> <br><br> <div class="alert">Class:<a href="" > <strong><?php echo $row_class['course_id']; ?></strong></a> Subject:<a href=""> <strong><?php echo $row_class['subject_id']; ?></strong></a> Teacher::<a href=""> <strong><?php echo $teacher_row['firstname']." ".$teacher_row['lastname']; ?></strong></a> </div> <div class="hero-unit-3"> <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example"> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <strong><i class="icon-user icon-large"></i> Files</strong> </div> <thead> <tr> <th>File Name</th> <th>Description</th> <th>Date Uploaded</th> <th>Action</th> </tr> </thead> <tbody> <?php $query = mysql_query("select * from files where class_id = '$get_id'") or die(mysql_error()); while ($row = mysql_fetch_array($query)) { $file_id = $row['file_id']; ?> <tr class="odd gradeX"> <!-- script --> <script type="text/javascript"> $(document).ready(function(){ $('#d<?php echo $file_id; ?>').tooltip('show') $('#d<?php echo $file_id; ?>').tooltip('hide') }); </script> <!-- end script --> <td><?php echo $row['fname'] ?></td> <td><?php echo $row['fdesc']; ?></td> <td><?php echo $row['fdatein']; ?></td> <td width="50"> <a href="<?php echo $row['floc']; ?>" rel="tooltip" title="Download File" id="d<?php echo $file_id; ?>" role="button" data-toggle="modal" class="btn btn-info"><i class="icon-download-alt icon-large"></i></a> </td> </tr> <?php } ?> </tbody> </table> <!-- end slider --> </div> </div> </div> <?php include('footer.php'); ?> </div> </div> </div> </body> </html> create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) I have following piece of code below, and I would like to be able to express it pure SQL, something that could go into a .sql file :
$request_string='SELECT topic_forum_id FROM topic_table WHERE topic_id= 2014'; $query=database->prepare($request_string); $query->execute(); $data=$query->fetch(); $query->closeCursor(); $forum=$data['topic_forum_id']; $request_string='INSERT INTO post_table (post_topic,post_forum) VALUES (2014,:forum)'; $query=database->prepare($request_string); $query->bindValue(':forum',$forum,PDO::PARAM_INT); $query->execute(); $data=$query->fetch(); $query->closeCursor();Is it possible ? So i have this php as shown below. It should make a list of comments with comment replies below their comment respectively. The problem is that it only goes through and shows 1 comment and all the comment replies for that one comment. It should be showing all comments i have in the db for that article. If i remove the second while then it shows all the comments correctly but no comment replies then... How do i get this script to loop through the db for every comment but also loop through every comment reply for that $row[id]? If anyone has a better / more efficient way of what I am trying to do, please explain or show example (i am open to anything)... Code: [Select] // what article are we showing? $article_to_show_id = $_GET['article_id']; $active_is_set_text = "1"; // Active Column text that makes it okay to show // Finding the article $search_for_article = mysql_query("SELECT * FROM articles WHERE id = '$article_to_show_id' AND active = '$active_is_set_text'"); while($row = mysql_fetch_array($search_for_article)) { // format the last updated date right $update_date_edit = $row[update_date]; $update_date_edit = date('F j, Y \a\t h:ia', $update_date_edit); $row[update_date] = $update_date_edit; // format the submit updat date right $submit_date_edit = $row[submit_date]; $submit_date_edit = date('F j, Y \a\t h:ia', $submit_date_edit); $row[submit_date] = $submit_date_edit; echo ' <div> ', $row[title] ,' </div> <div> by: ', $row[author] ,' on ', $row[submit_date] ,' </div> <div> ', $row[content] ,' </div> <div> Last Updated: ', $row[update_date] ,' </div> <form action="article_reply.php" method="post"> <input type="hidden" name="article_id" value="', $row[id] ,'" /> <button name="article_reply" type="submit" value="submit">Reply</button> </form> '; } $comment_count = 0; $comment_reply_count = 0; // Finding all of the comments $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '0'"); while($row_comment = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_comment[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_comment[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT:<br> <div> By: ', $row_comment[username] ,' on ', $row_comment[comment_date] ,' </div> <div> ', $row_comment[comment] ,' </div> '; $comment_count++; // Finding all of the comment replies if any $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '$row_comment[id]'"); while($row_two = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_two[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_two[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT REPLY:<br> <div> By: ', $row_two[username] ,' on ', $row_two[comment_date] ,' </div> <div> ', $row_two[comment] ,' </div> '; $comment_reply_count++; } } Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! hello i am making a online cook for people to register and make and online cookbook on there account i want them to be able to add recipes and be able to see them on there file, i know how it would connect to the database and how to send the information but what tables would i use and what fields? this is my basic site now www.lachlanmcgrath.net, if you can help please reply here or even e-mail me at lmcgr44@me.com thank-you for your help I have been trying very hard to get this script to work but I am no good at arrays... Anyhow, the basic idea is that the script will read an RSS feed and post all that content to the database which will be used to display content on the site. <?php $doc = new DOMDocument(); $doc->load('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/rss.xml'); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); } include 'dbconnect.php'; foreach ($arrFeeds as $item) { $sql="INSERT INTO tb_rss (title, desc, link, date) VALUES ($item => title), $item => desc, $item => link, $item => date)"; if (!mysql_query($sql)){ die('Error: ' . mysql_error()); } } ?> Current error messege is: Code: [Select] 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 'desc, link, date) VALUES (Array => title), Array => desc, Array => link, Array =' at line 1 Help please? in php you have the following mysql API fetch commands: ■mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both ■mysql_fetch_assoc — Fetch a result row as an associative array ■mysql_fetch_field — Get column information from a result and return as an object ■mysql_fetch_lengths — Get the length of each output in a result ■mysql_fetch_object — Fetch a result row as an object ■mysql_fetch_row — Get a result row as an enumerated array If u use one of them for example i use mysql_fetch_object. Code: [Select] $run = mysql_query(SELECT `status` FROM `[settings]` WHERE `name`= *); $display = mysql_fetch_object($run); other example Code: [Select] $run = mysql_query(SELECT `status` FROM `[settings]` WHERE `name`= 'abusing' AND `name`= 'hacking' AND `name`= 'cracking'); $display = mysql_fetch_object($run); When i do Code: [Select] $display->somethingIt wil assign the SELECT condition i want to assign the WHERE condition. the value of it. like i want to do this Code: [Select] $display->WHERE->hackinghow to do this? Please consider this sql query & it is used to select data from sql. Code: [Select] $sql = mysql_query("SELECT * FROM `appz` WHERE `cid` = '1' ORDER BY `id` DESC LIMIT 3"); But i want to select all the values under the cid of 2,3,4,5 but my query only select the data which the cid under 1. Anyone can help me to make the changes in my query ? I'm having trouble working out a mysql query. I have two tables called "content" and "providers". Content Table content_id content_provider 1 Provider 1 2 Provider 2 3 Provider 1 Providers Table provider_name provider_url Provider 1 www.provider1.com Provider 2 www.provider2.com What I want to do is to select all of the information in the "providers" table but also to perform a count on the "content" table to get the number of content for each provider. So in this case it would show all of the information for provider 1 and also show that provider 1 has 2 pieces of content because they have 2 entries in the "content" table. I am able to get these results as two separate queries but I was wondering if it was possible to do it in one query. Thanks for any help. Hi in new to php with a work colleague we have been designing a php/mysql reporting system for the school i work at but need a help with a bug teachers can update reports when they do the code pouplates the textareas with what is in the DB they can then make changes no problem but if two do it at the same time or one opens a reports goes makes a tea another opens the same report makes a changes updates report lets say Science then and then the other teacher comes bak makes a change to Maths it rewights the old science over the top of the new one the othe teacher did a little while ago In short can you make a php statment that onchange of textarea then include into the mysql update query if no change the dont include that in the mysql update query Hey, I was wondering.. Is there any php functions or any way I can get some information from MySQL? I want to be able to echo out the uptime for MySQL, and some other things.. I've seen it done before so I know its possible lol. i have been trying to write a script to take an xml file from thetvdb and import the data into a mysql database, but it keeps saying: Code: [Select] Chuck Versus the Third Dimension (2D):Chuck Versus the Third Dimension (2D):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 'Versus the Third Dimension (2D):, Chuck foils a plan to kill Tyler Martin' at line 1 the sample.xml is this file http://www.thetvdb.com/api/217F7921A2EA56C0/series/80348/all/en.xml and here is my code: Code: [Select] <?php $tvdb_mirror = "http://www.thetvdb.com/api/"; $tvdb_time = "http://www.thetvdb.com/api/Updates.php?type=none"; $dbname = "mediadb"; $dbuser = "root"; $dbpass = ""; $dbserv = "127.0.0.1"; $rss = simplexml_load_file('sample.xml'); $showName = "Show Name = ".$rss->Series->SeriesName; mysql_connect('127.0.0.1', 'root', ''); @mysql_select_db('mediadb') or die("Unable to select database"); echo ' '; foreach ($rss->Episode as $item) { $seasonnum = $item->Combined_season; $EpisodeNumber = $item->EpisodeNumber; if($EpisodeNumber < 10){ $EpisodeNumber = "0".$EpisodeNumber; }; $EpisodeName1 = $item->EpisodeName; $EpisodeName1 = str_replace($array1, $array2, $EpisodeName1 ); echo $EpisodeName1; $EpisodeName = mysql_real_escape_string($EpisodeName1); echo $EpisodeName; $Overview1 = $item->Overview; $Overview = mysql_real_escape_string($Overview1); $airdate = $item->FirstAired; $tvdbid = $item ->id; $query = "INSERT INTO eppisodes VALUES('1', ".$EpisodeName.", ".$Overview.", ".$airdate.", '1', ".$tvdbid.", '-1', ".$seasonnum.", ".$EpisodeNumber.")"; mysql_query($query) or die (mysql_error()); print "<br />".$showName." - ".$seasonnum."x".$EpisodeNumber." - ".$EpisodeName." Overview:<br />".$Overview; } mysql_close(); ?> i think its to do with the contents of the xml file, i thing there are special charictors in there breaking out of the mysql, but iv tried html entaties and mysql special escape string and nither seem to work, i even tried to use str_replace to replace all the commas and stuff with ' and the like. not sure were to go from here. any help? please? I have this code I want to check to see if the id from table1 is in table2. Can anyone help me with that if($checkProfile) { $sql_chk_tbl_username = "SELECT id FROM members_profile WHERE id = '"$_SESSION['face']"'"; $rs_user_list = mysql_query($sql_chk_tbl_username); if(mysql_num_rows($rs_user_list) <= 0) } ?> I have a table that has a field called rating which can be from 0-100. I want to create a mysql query that will count the number of ratings between 0-20 then 21-40 then 41-60 etc. However I'm not really sure how to do this so any help would be great. I have the code snippet below trying to check my database if a variable exists, it seems to work for the username but not for the email. The database name is "communitycouch_users" table is "reg_vars" to check the row: email. the variable $email is coming from my form. Upon form submission it will submit the data into the database regardless it exists. Code: [Select] $email= $_POST['email']; $username= $_POST['username']; // Check if the email and username exist already if(MysqlVarExists("communitycouch_users", "reg_vars", "email", $email) == true) { $errors_code["existing_email"] = "That email is already being used."; } if(MysqlVarExists("communitycouch_users", "reg_vars", "username", $username) == true) { $error_code["existing_username"] = "That username is already in use."; } |