PHP - One Of Those Days, Strange Mysql Behavior On Mysql_fetch_array
Ok so I have a simple database table set up, and I am trying to get the results into an HTML table, however I have a question. One loop I write in a for loop will dump the data I want to the table, the other returns no results. For example I have the code...
Code: [Select] //SQL Lookup //SQL Lookup $sqlAppt = mysql_query("SELECT * FROM Appointment WHERE TTUNumber = \"$TTUNumber\" && ShippingNumber = \"$ShippingNumber\" LIMIT 1") or die('Could not execute SQL statement ' . mysql_error()); $numbRows = mysql_num_rows($sqlAppt); echo "<p>Number of rows found: $numbRows </p>\n"; So When I create the first whlile loop, i do not get any results from my database. Code: [Select] while($r=mysql_fetch_array($sqlAppt)){ $ApptDate=$r['Date']; $ApptTime=$r['Time']; $ApptNumber=$r['ApptNumber']; $ApptDock=$r['Dock']; echo '<h1>I got here</h1>'."\n"; echo "<table>\n"; echo "<tr><td>Date</td><td>$ApptDate</td></tr>\n"; echo "<tr><td>Time</td><td>$ApptTime</td></tr>\n"; echo "<tr><td>Appt Number</td><td>$ApptNumber</td></tr>\n"; echo "<tr><td>Dock</td><td>$ApptDock</td></tr>\n"; echo "</table>\n"; } The Results is this: Quote Number of rows found: 1 I got here Date Time Appt Number Dock However, when I create a different loop structure... Code: [Select] for($i = 0; $i < $numbRows; $i++) { $r=mysql_fetch_array($sqlAppt); $ApptDate=$r['Date']; $ApptTime=$r['Time']; $ApptNumber=$r['ApptNumber']; $ApptDock=$r['Dock']; echo '<h1>I got here</h1>'."\n"; echo "<table>\n"; echo "<tr><td>i:</td><td>$i</td></tr>\n"; echo "<tr><td>Date</td><td>$ApptDate</td></tr>\n"; echo "<tr><td>Time</td><td>$ApptTime</td></tr>\n"; echo "<tr><td>Appt Number</td><td>$ApptNumber</td></tr>\n"; echo "<tr><td>Dock</td><td>$ApptDock</td></tr>\n"; echo "</table>\n"; } Naturally I get a different result! Quote Number of rows found: 1 I got here i: 0 Date 1982-12-26 Time 08:00:00 Appt Number 123 Dock 34 I can't figure out why for the life of me that my while loop would not return anything on here>? Does anyone have any idea's? Thanks Similar TutorialsI'm returning a table row that contains information about a file, but it seems in IE versions older than 10, it is cutting off some of the returned json when being used.
The data is being returned properly as seen in the following json:
{"file_name":"<i class='video'><\/i> <a href=\"\/Development\/test(4).mp4\" class=\"is_file\" target=\"_blank\">test(4).mp4<\/a>"}But when you use it, it cuts off the html. A simple alert will return </i> test(4).mp4</a>and same when appending it and the sort. It is also happening for another part of HTML that is being returned properly in the json. It is working for everything else that is returned. I have been searching around for a very long time trying to find why this is happening. Has anyone other than me encountered this? So i am currently coding database connection class and i have encountered very strange behavior from my script. base.class.php: Code: [Select] <?php class base{ private $settings; function get_settings(){ $settings["dbhost"] = 'localhost'; $settings["dbuser"] = '*****'; $settings["dbpass"] = '*****'; $settings["dbname"] = 'core'; return $settings; } } ?> database.class.php Code: [Select] <?php require_once 'base.class.php'; class database extends base{ private $query_now; private $link; public function __construct(){ $settings = base::get_settings(); $dbhost = $settings["dbhost"]; $dbuser = $settings["dbuser"]; $dbpass = $settings["dbpass"]; $dbname = $settings["dbname"]; $this->link = mysql_connect($dbhost, $dbname, $dbpass) or die ("Could not connect to the mysql database"); mysql_select_db($dbname, $this->link) or die ("Could not select the database"); } function query($query){ $this->query_now = $query; return mysql_query($query, $this->link); } function getArray($result){ return mysql_fetch_array($result); } } ?> When i try to create an instance of database class, i get mysql_connect error. I have tried to echo my array and it seems that correct information is being passed over. Now the strange thing is if i remove my password from the base class i don't get a mysql_connect error but this time instead i get "Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'core'@'localhost' (using password: YES) " In case you are wondering, does my mysql database user has a password, the answer is: yes for sure... (Also i have tried to setup a simple script for connecting to my database and everything worked fine) So any ideas? Hi guys, In my connection.php I have: $db->query("DROP TABLE IF EXISTS mydata") ; $db->query("CREATE TABLE mydata ( ID INT AUTO_INCREMENT NOT NULL PRIMARY KEY, guid INT, title VARCHAR(100), body LONGTEXT, term VARCHAR(100) )"); and my query code : $myarray = array ( guid => 100, title => "title test", body => "just a test", term => "term test", ); $myplaceholders[] = '(' . implode (", ", array_fill(0, count($myarray), '?')) . ')'; //also tried '(?,?,?,?)' $mykeys = implode(', ', array_keys($myarray)); array_push($values, ...array_values($myarray)); //also tried $values = array_values($myarray) ; $res = $db->prepare("INSERT INTO mydata ($mykeys) VALUES " . join(', ', $myplaceholders)) ; if ($res->execute($values)) { echo 'data inserted'; } else { echo 'error in query'; } After executing the code, the table is created but no data is inserted. The strange thing is when I leave the create table statement out of the connection.php and run the code the data is inserted. Any ideas where I'm going wrong? Current time when testing was: 1291064453 I run the following: echo date('m/d/y', strtotime('first day', 1291064453)); Expecting: 11/1/10 What I actually get: 11/30/10 Can anyone explain this? This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=331683.0 Hey all, when job_title property is equal to null, I want this to happen: Welcome to the blog of John Merlino. If it is not null then: Welcome to the blog of John Merlino, a web designer. //where web designer refers to the value stored in job_title So I come up with this: Code: [Select] echo "Welcome to the blog of " . $blogger->first_name . ' ' . $blogger->last_name . (!is_null($blogger->job_title)) ? ', ' . $blogger->job_title . '.' : '.'; But when job_title is null, all the page renders is this: Code: [Select] , . That's right. Just a comma, then a space, and then a period. What am I missing here? Thanks for response. I am working with the Amazon API, and I am trying to display a default image if a product does not have an image associated with it. The query is coming back as an array. Typically, each product image array looks like this: $d = SimpleXMLElement Object ( http:// => [url]http://ecx.images-amazon.com/images/I/51aUIul6XjL._SL160_.jpg [Height] => 160 [Width] => 112 ) The code goes like this: Code: [Select] if ($d=$E->MediumImage) { $iu=$d->URL; $ih=$d->Height; $iw=$d->Width; echo count($d); if (strlen($iu) > 0) {echo "<center><a href='$url' target='_blank'><img src='images/amazon_noimage.jpg' width='175' height='175' border='0'></a></center>";} else {echo "<center><a href='$url' target='_blank'><img src='$iu' width='$iw' height='$ih' border='0'></a></center>";} } However, images/amazon_noimage.jpg never shows up (even though it is linked correctly, as I've tested this link). I have tried the following: if (strlen($iu) > 0) if (count($iu) > 0) if (strlen($d->URL) > 0) if (count($d->URL) > 0) if (isset($d)) if (!isset($d)) etc ... If I display the following, where there is no image, I get nothing displayed: echo $iu; print_r($iu); echo $d->URL; etc ... However, if there is an image, I get a link, such as the following: http://ecx.images-amazon.com/images/I/51c2BFpDN0L._SL160_.jpg There seems to be NOTHING that I can do to trigger the 'ELSE' part of the if statement. This is a total enigma to me ... any ideas?? hello; my webhost made a change to my php.ini file yesterday. since then php is escaping single quotes that it receives from flash. Code: [Select] //-- AS3 var myVariables:URLVariables = new URLVariables(); myVariables.pvs_params = "'h'e'l'l'o" ; var myURLRequest:URLRequest = new URLRequest("mysql_task_mgr.php"); myURLRequest.data = myVariables ; myURLRequest.method = "get" ; navigateToURL( myURLRequest, '_blank' ) ; Code: [Select] //-- php print( $_GET[ "pvs_params" ] ) ; // --> \'h\'e\'l\'l\'o any thoughts? my webhost is stumped; I'm trying to have a running total of the number of views an image gets. My test file works perfectly every time. The actual file, image_win.php, does not and after much testing can't see what's wrong. This files STRANGENESS: the first two views count fine, with 1 added the total in the field image_visit. But every time after that 2 is added to the total in image_visit. Very bizarre. Thanks for taking a look -Allen Code: [Select] <?php ////////TEST IMAGE_WIN //////////THIS WORKS include_once "scripts/connect_to_mysql.php"; include_once "scripts/paths.php"; $art_id = 372; $QUERY="SELECT user_id FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num >0){ while($row = mysql_fetch_array($res)){ $owner_id = $row['user_id']; } } mysql_query("UPDATE userInfo SET image_visit = image_visit +1 WHERE user_id = '$owner_id'"); ?> <?php //////// image_win.php /////////THIS DOES NOT WORK $user_id=$_SESSION['user_id']; include_once "scripts/connect_to_mysql.php"; include_once "scripts/paths.php"; $image_link = $_GET['image_link']; $art_id = $_GET['art_id']; ?> <!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=utf-8" /> <meta name="viewport" content="width=device-width, height=device-height, target-densityDpi=device-dpi"> <title>Image Window</title> </head> <body bgcolor="#000000" leftmargin="0"> <div align="center" > <img src="slir/w640-h535/<?php echo $path.$image_link.$postCat; ?>" /> <?php $QUERY="SELECT user_id FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num >0){ while($row = mysql_fetch_array($res)){ $owner_id = $row['user_id']; } } mysql_query("UPDATE userInfo SET image_visit = (image_visit +1) WHERE user_id = '$owner_id' "); ?> MOD EDIT: code tags added. I need to display the last 30 days entries from database in PHP and here is the code that i am currently using, but its not working. While entering the data in database, the date format that i am using is this... Code: [Select] $subon = date("F j, Y, g:i a"); And to display the code i am using this query... Code: [Select] $start_date = date("F j, Y, g:i a", strtotime('-30 days')); $curr_date = date("F j, Y, g:i a"); $sql = "SELECT * FROM table WHERE status = 'approved' AND subon BETWEEN '$start_date' AND '$curr_date' ORDER BY ID DESC LIMIT 0, 5"; And then i am using the usual stuff to display the data but its not working. Somebody please help me... Thanks in advance. I am getting an error message. Quote mysql_fetch_array(): supplied argument is not a valid MySQL result My Sql seems to work fine. But I kept on getting this error message whenever I try to view orderid. I have option to view different field such as orderid, orderdate, price and profit. When the page loads its fine. But when I try to view orderdate the orderid I get the error message Error code is on the first line and the other places where it says $result. Code: [Select] while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='left'>" . $row['orderid'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['orderdate'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['updated'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['name'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['price'] . "</td>"; echo "<td align='left'>" . $row['salesman'] . "</td>"; echo "<td align='left'>" . $row['origsalesman'] . "</td>"; echo "<td align='left'>" . $row['status'] . "</td>"; echo "<td align='left'>" . $row['product'] . "</td>"; echo "<td align='left'>£" . $row['profit'] . "</td>"; echo "</tr>"; echo "<tr><td colspan='10'><hr></td></tr>"; } if ( mysql_num_rows( $result ) == 0 ) echo "<tr><td colspan='10'>No orders found<hr></td></tr>"; echo "</table></form>"; mysql_free_result( $result );code] Please help me. Hi Guys, I have been working on a recursive select box that will allow sub-categories and keep getting the error: <b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>test.php</b> on line <b>22</b><br / i have a table as follows: Code: [Select] CREATE TABLE IF NOT EXISTS `ost_help_topic` ( `topic_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `isactive` tinyint(1) unsigned NOT NULL DEFAULT '1', `noautoresp` tinyint(3) unsigned NOT NULL DEFAULT '0', `priority_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `dept_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `CatParent` bigint(11) unsigned DEFAULT NULL, `topic` varchar(32) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`topic_id`), UNIQUE KEY `topic` (`topic`), KEY `priority_id` (`priority_id`), KEY `dept_id` (`dept_id`) ) Code: [Select] <?php $db_host = "localhost"; $db_un = "user"; $db_pass = "pass"; $Item_DB = "data"; $table = "ost_help_topic"; $link = mysql_connect($db_host, $db_un, $db_pass); $tab = " "; // this is 8 spaces, which works as a pseudo-tab character inside the <option>s $tablvl = 1; function print_kids($pos) { // $pos is the current position inside the hierarchy (curr item's ID) global $link; global $tab; global $tablvl; $pos = ($pos?$pos:null); $query = "SELECT * from $table WHERE isactive=1 AND CatParent".($pos == null ? " IS NULL" : "=".$pos); // NULL parent == top level item. For 0-parents, replace " IS NULL" with "=0" $res = mysql_db_query($Item_DB, $query, $link); if (!$res) print(mysql_error()); while($row = mysql_fetch_array($res)) { $has_kids = mysql_fetch_array(mysql_db_query($Item_DB, "SELECT * from $table where isactive=1 AND CatParent=$row[0]", $link)) != null; print("<option value=\"$row[0]\">"); for ($i=0; $i<$tablvl; $i++) print($tab); print("$row[6]</option>\n"); if ($has_kids) { $tablvl++; print_kids($row[0]); // <span class="posthilit">recursive</span> call $tablvl--; } } } $numrows = 1; $res = mysql_db_query($Item_DB, "SELECT * FROM $table", $link); while (mysql_fetch_array($res)) $numrows++; // Yes, I'm sure there's a more efficient way to do this <img src="./images/smilies/icon_razz.gif" alt=":P" title="Razz" /> print("<select name=\"hierarchy\" size=\"$numrows\">\n"); print("<option value=\"null\" selected=\"selected\">Root of all items</option>\n"); print_kids(0); print("</select>"); mysql_close($link); ?> Hi, I am having problem with mysql and php.... when i test the database on my local host it didt produce any error but when i put it on my web host it gave me error messages... "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource" Please help me as i am new to php. Quote <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="http://www.hingloong.com/pricesearch/style.css" /> <title>Price Search Query</title> </head> <body> <form method=GET action="search.php"> <div id=container> <select name=general> <option value = all>Select</option> <option value = laptop>Laptop</option> <option value = mobile>Mobile</option> <option value = games>Games</option> <option value = camera>Camera</option> </select> <label><b>Brand:</b></label> <input type=text name=brand> <label><b>Model:</b></label> <input type=text name=model> <input type=submit name=search value=Search> </form> <br><br> <input type=button name=gamelist value=View Games onclick="location.href='gamelist.php'"> <input type=button name=mobilelist value=View Mobile onclick="location.href='mobilelist.php'"> <input type=button name=cameralist value=View Cameras onclick="location.href='cameralist.php'"> <input type=button name=laptoplist value=View Laptops onclick="location.href='laptoplist.php'"> </div> </body> </html> <?php include ("connect.php"); $general = $_GET['general']; $brand = $_GET['brand']; $model = $_GET['model']; if($general == 'mobile') { echo "<br>"; echo "<h3>Mobile Phone Prices</h3>"; echo "<div id=container>"; echo "<table>"; echo "<tr>"; echo "<td class=head>Phone Brand</td>"; echo "<td class=head>Phone Model</td>"; echo "<td class=head>Phone Loan</td>"; echo "<td class=head>Phone Buy</td>"; echo "<td class=head>Phone Sell</td>"; echo "<td class=head>Phone Rrp</td>"; echo "</tr>"; $query = "select * from mobilephones where phone_brand LIKE ('$brand%') AND phone_model LIKE ('$model%') "; $temp = mysql_query($query) or die(mysql_error()); } while ($row = mysql_fetch_array($temp)) { echo "<tr>"; echo "<td>" .$row['phone_brand']. "</td>"; echo "<td>" .$row['phone_model']. "</td>"; echo "<td>" .$row['phone_loan']. "</td>"; echo "<td>" .$row['phone_buy']. "</td>"; echo "<td>" .$row['phone_sell']. "</td>"; echo "<td>" .$row['phone_rrp']. "</td>"; } echo "</table>"; echo "</div>"; ?> I have this search script, that finds a username in a table and displays it. <form name="search" method="post" action="<?=$PHP_SELF?>"> Search: <input type="text" name="username" /> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <? //This is only displayed if they have submitted the form $searching = $_POST['searching']; $find = $_POST['username']; if ($searching =="yes") { echo "<h2>Results</h2><p>"; //If they did not enter a search term we give them an error if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT username FROM users WHERE upper($find) LIKE'%$find%'"); //And we display the results while($result = mysql_fetch_array( $data )) { echo $result['username']; echo "<br>"; echo "<br>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches= mysql_num_rows ($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> For some reason it does not work and gives this message: [b]Warning[/b]: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [b]C:\Program Files\EasyPHP5.2.10\www\yanille\users.php[/b] on line [b]153[/b] Error: Unknown column 'MI' in 'where clause' The reason it says MI is because I searched mi in the database which is part of the username in mike123 What would be the problem? I think I did make the query correct. Didn't I? Thanks for the help ahead of time. Hi, first post, and yes it is a question. I am stuck, and not by choice, this error has given me more headaches than I care to admit. I have a script that I am attempting here, that is very simple for now, all I want to show is the Added_By field to show it is accessing the database correctly and the right row/line all together. The page to test this at is he http://kaboomlabs.com/PDI/@dm!n/viewncmr.php?id=2 The Error is this: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pawz/public_html/kaboomlabs.com/PDI/@dm!n/viewncmr.php on line 18 This is row 18: $row = mysql_fetch_array($data); Now I know this is not a secure form yet, I am working on getting the basic functions down then I'll secure it, so please let me worry about that when the time comes. Here is the script, can anyone see a blatant issue or not? Thanks in advance. Code: [Select] <?php require_once('../connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '" . $_SESSION['id'] . "'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; $data = mysqli_query($dbc, $query); } if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysql_fetch_array($data); echo '<fieldset>'; if (!empty($row['Added_By'])) { echo '<div id ="added"><label>Added By:</label>' . $row['Added_By'] . '</div></fieldset>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your profile.</p>'; } mysqli_close($dbc); ?> In the following code, at the mysql query immediately following the <!--end accordianButton div-->, Some of the rows will echo out the content, while some of the rows will throw the Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... error. Any idea why? Go here to see what I mean: http://www.chalmerscommunitychurch.com/P2P_archives.php <!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=utf-8" /> <title>Pastor to People Blog Archives</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> </script> <script type="text/javascript" src="js/javascript.js"> </script> <style> .accordionButton { width: 100%; height:30px; float: left; background: url(../images/button.png); border-bottom: 1px solid #FFFFFF; cursor: pointer; } .accordionContent { width: 100%; float: left; display: none; } </style> </head> <body> <?php require("include.php"); $con = mysql_connect("$db_host","$db_username","$db_pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("chalmers_db", $con); $result = mysql_query("SELECT title, date FROM blog"); while($row = mysql_fetch_array($result)) { $title=$row['title']; $sqldate=$row['date']; $date=date('m-d-Y',strtotime($sqldate)); ?> <!--start accordionButton div--> <div class="accordionButton"><?php echo $title;?>, <?php echo $date;?> </div> <!--end accordianButton div--> <?php $query = mysql_query("SELECT content FROM blog WHERE title = '".$title."' ORDER BY date DESC"); while ($row = mysql_fetch_array($query)){ $content = $row['content']; ?> <!--start accordionContent div--> <div class="accordionContent" align="justify"> <?php echo $content;?> </div> <!--end accordionContent div--> <?php } ?> <?php } ?> <p><p><p><p><a href="http://www.chalmerscommunitychurch.com"><h3>Back to Chalmers Community Church</h3></a> </body> </html> Hi guys, for the life of me, what am I doing wrong, I cannot figure out this one, getting this error : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ......... search.php on line 36 my code : Code: [Select] $start = ($page-1)*$per_page; $sql = "SELECT productId, productCode, image, name, price, stock_level FROM inventory WHERE productCode LIKE '%".$searchp."%' OR name LIKE '%".$searchp."%' AND Seller_ID = '" . $_SESSION['SESS_SELL_ID'] . "' order by name limit $start,$per_page"; $rsd = mysql_query($sql); <?php while($row = mysql_fetch_array($rsd)) // ERROR OCCURS HERE : line 36 { $idpc=$row['productId']; $idc=$row['productCode']; $idi=$row['image']; $idn=$row['name']; $idp=$row['price']; $ids=$row['stock_level']; ?> all help appreciated as always. Hi I'm currently having a problem with my chat script each time I'm trying to insert " or brackets etc... I get the error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/u471530368/public_html/chat/page.php on line 201
Here is the lines at line 201
// check to see if a duplicate exists $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 30 )"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); if($myrow["StringyChat_message"] == "") { // Checks if record not matching in db // Save the record $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time)"; $result = mysql_query($sql); $theTo = $email_notification_to; $theSubject = "New StringyChat post at ".$domain_installed; $theMessage = "A new StringyChat post has been made.\n\n"; $theMessage .= $name . "\n"; $theMessage .= date("H:i - d/m/y", $post_time) . "\n"; $theMessage .= $message_emailable . "\n\n"; $theMessage .= "Visit ".$domain_installed." to view StringyChat and much more!"; $theHeaders = "From: StringyChat at ".$domain_installed." <".$email_notification_to.">\r\n"; mail($theTo,$theSubject,$theMessage,$theHeaders); } else { echo "<span style='color:#10ce59'>Duplicate post detected!</span><p>"; } } else { echo "<span style='color:#10ce59'>You can't send blanks!</span><br><br>"; }My full script is <?php define('TIMEZONE', 'Africa/Harare'); date_default_timezone_set(TIMEZONE); ?> <html><br> <b><u>Chat Beta:</u></b> <span style="color:#ff0000"><br>Errors may apply please send feedback with contact us regarding problems!</span> <br><a href="page.php">Reload</a> </html> <? // database connection info $conn = mysql_connect('*******','********','*****') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('*******',$conn) or trigger_error("SQL", E_USER_ERROR); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM StringyChat"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 20; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; /* * StringyChat * * Please refer to readme.txt supplied with the StringyChat distribution for information on * installing and configuring. * */ define('TIMEZONE', 'Africa/Harare'); date_default_timezone_set(TIMEZONE); include("chat_code_header.php"); $result = mysql_query("SELECT * FROM ".$ConfigTable, $db); $myrow = mysql_fetch_array($result); $domain_installed = $myrow["domain_installed"]; // The domain StringyChat is installed on $install_url = $myrow["install_url"]; // URL to install dir of StringyChat $name_size = $myrow["name_size"]; // Maximum size of the name $message_size = $myrow["message_size"]; // Maximum message size. Do not exceed 250 as this is the database limit. $line_length = $myrow["line_length"]; // Maximum length of words in a line. Anything above this value will be split. $ShowPostNum = $myrow["show_posts"]; // The number of historic posts to load and display. $email_notification = $myrow["email_notification"]; // Send email to administrator when new posts are made. 0 = No, 1 = Yes $email_notification_to = $myrow["email_notification_to"]; // The email address to send notifications to if ($_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['StringyChat_name'])) { $StringyChat_name = $_POST['StringyChat_name']; $StringyChat_message = $_POST['StringyChat_message']; } ?> <div id="StringyChat"> <? // Check if visitor's IP is banned. If so, do not display the form, // show a banned IP message instead. $name = $_SERVER["HTTP_X_MXIT_NICK"]; if(!isset($name)) { $name = "SYSOP"; } $ip = $_SERVER["REMOTE_ADDR"]; $sql = "SELECT * FROM StringyChat_IPBan WHERE ip=\"$ip\""; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); if($myrow["ip"] == "") { // Checks if IP not found in banned list ?> <html><form name="StringyChat_form" method="POST" action="<? echo $_SERVER['REQUEST_URI']; ?>"> <input type="hidden" name="StringyChat_name" class="StringyChatFrm" value="<?php echo $name ?>" size="20"> <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="1"></textarea> <br> <input name="StringyChat_submit" class="StringyChatFrm" type="submit" value="Post Message"> </form> </html> <? } else { echo "<span style='color:#10ce59'><u>Dear User, you have been banned from the Chat due to not following the rules. You will need to come back regularly to see if you were unbanned. Until then, goodbye!</u></span>"; } // Should we try to create a post? if (isset($StringyChat_name) && isset($StringyChat_message)) { // Remove whitespaces and slashes. $name = trim(stripslashes($StringyChat_name)); $message = trim(stripslashes($StringyChat_message)); // Check name and message have been entered. if (strlen($name) > 0 && strlen($message) > 0) { // Limit the size of the fields as per variable defnitions. if (strlen($name) > $name_size) { $name = substr($name, 0, $name_size); } if (strlen($message) > $message_size) { $message = substr($message, 0, $message_size); } // Remove new lines from name. $name = str_replace("\n", " ", $name); // Stripping out \r's so email formattnig appears correctly. $message = str_replace("\r", "", $message); // Create an email-friendly version of the message. $message_emailable = str_replace("<br>", "\n", $message); $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db); while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) { $the_word = $myrow_wordswap["word"]; $message_emailable = ereg_replace($the_word, "!*#$%",$message_emailable); } // Replace the new lines with encoded line breaks for HTML (thanks milahu). $message = str_replace("\n", "c#lb", $message); // Use HTML encoding on ame and message so database doesn't misinterpret data. $name = htmlentities($name); $message = htmlentities($message, ENT_COMPAT); // IP address of submitter and time of post. $ip = $_SERVER["REMOTE_ADDR"]; $name = $_SERVER["HTTP_X_MXIT_NICK"]; $msg = $_POST['StringyChat_message']; $post_time = date("U"); $mxitid = $_SERVER["HTTP_X_MXIT_LOGIN"]; if(!isset($mxitid)) { $mxitid = "DEFAULT"; } if(!isset($name)) { $name = "SYSOP"; } // check to see if a duplicate exists $sql = "SELECT * FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 30 )"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); if($myrow["StringyChat_message"] == "") { // Checks if record not matching in db // Save the record $sql = "INSERT INTO StringyChat (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time) VALUES (\"$ip\",\"$name\",\"$msg\",$post_time)"; $result = mysql_query($sql); $theTo = $email_notification_to; $theSubject = "New StringyChat post at ".$domain_installed; $theMessage = "A new StringyChat post has been made.\n\n"; $theMessage .= $name . "\n"; $theMessage .= date("H:i - d/m/y", $post_time) . "\n"; $theMessage .= $message_emailable . "\n\n"; $theMessage .= "Visit ".$domain_installed." to view StringyChat and much more!"; $theHeaders = "From: StringyChat at ".$domain_installed." <".$email_notification_to.">\r\n"; mail($theTo,$theSubject,$theMessage,$theHeaders); } else { echo "<span style='color:#10ce59'>Duplicate post detected!</span><p>"; } } else { echo "<span style='color:#10ce59'>You can't send blanks!</span><br><br>"; } unset($_POST["StringyChat_name"]); unset($_POST["StringyChat_message"]); unset($StringyChat_ip); unset($StringyChat_name); unset($StringyChat_message); unset($StringyChat_time); unset($mxit_id); } // get the info from the db $sql = "SELECT StringyChat_time, StringyChat_name, StringyChat_message FROM StringyChat ORDER BY id DESC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); function filterBadWords($str) { $result1 = mysql_query("SELECT word FROM StringyChat_WordBan") or die(mysql_error()); $replacements = ":-x"; while($row = mysql_fetch_assoc($result1)) { $str = eregi_replace($row['word'], str_repeat(':-x', strlen($row['word'])), $str); } return $str; } // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) //while (($pmsg = $list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message']) { // echo data //echo ($pmsg = ($list['StringyChat_message'] == $bwords) ? ":-x" : $list['StringyChat_message']) $admin = array('cobusbo','Admin+TT'); if (in_array($list['StringyChat_name'], $admin)) { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . '<span style="color:red">' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '</span>' . '<br />' . '<p>'; } else { print '<span style="color:#828282">' . '(' . date( 'D H:i:s', $list['StringyChat_time'] ) . ') ' . '</span>' . '<b>' . $list['StringyChat_name'] . '</b>' . ' : ' . filterBadWords($list['StringyChat_message']) . '<br />' . '<p>'; } } // Load up the last few posts. The number to load is defined by the "ShowPostNum" variable. $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC LIMIT " . $ShowPostNum,$db); include("sort_widths.php"); while ($myrow = mysql_fetch_array($result)) { $msg = $myrow["StringyChat_message"]; // Convert the encoded line break into an actual <br> tag (thanks milahu) $msg = str_replace("c#lb", "<br>", $msg); // Convert the encoded image tag into a html tag $msg = eregi_replace("im#([a-z]{3})", "<img src=\"http://".$install_url."images/\\1.gif\" alt=\"emoticon\">",$msg); // split the lines $msg = htmlwrap($msg, $line_length); $result_wordswap = mysql_query("SELECT * FROM ".$WordBanTable,$db); while ($myrow_wordswap = mysql_fetch_array($result_wordswap)) { $the_word = $myrow_wordswap["word"]; $msg = ereg_replace($the_word, ":-x",$msg); } } ?> <? // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?><br> <html> <span style="color:grey"><i>Type Your Message NOW!</i></span> <p><a href="page.php">Reload</a> | <a href="http://tt.2fh.co">Home</a><br></html>Any help please... If I send normal messages I don't get any errors... |