PHP - Word Count Function
I am writing a function to count the words that have been typed into a text box. I originally had it working when I first wrote it but it was counting all of the punctuation as a word so I I tried adding some code to eliminate that. Now it is not working. Could someone help me?
Here is my code Code: [Select] function count_words($description){ $word_count = 0; $description = trim(preg_replace("/\s+/"," ",$description)); $word_array = explode(" ", $description); for($i=0; $i < count($word_array); $i++){ if (preg_match("[0-9A-Za-z]", $word_array[$i])) { $word_count++; } return $word_count; } } Similar TutorialsI've been trying to come up with a way to accurately count a word string which includes punctuation marks. I've got close but the white-space is causing a problem. I have used a couple of functions such as str_replace and explode and I can now get an accurate count for texts with most punctuation and 'normal' white space. BUT.. If I put in three extra spaces between words the count adds 1 to the total. $words2 = str_replace("-", "", $string); // strips a hypen $words3 = str_replace(' ', ' ', $words2); // strips double spaces $words = explode(' ', $words3); This is obviously NOT a script - rather a string of text being passed through three functions to cleanse it. But as you can see it will strip two white spaces when they occur but no more. So three, four, five etc. will be counted as extra words. What else could I try to give me an accurate count? I am very raw at php. thanks Richard How to COUNT the number of records (pulled from a db)which contains the word "APPROVED". This code doesn't work though. $result1; $result2; $result3; $approvedApplicants = COUNT($result1=='Approved', $result2=='Approved', $result3=='Approved') echo ($approvedApplicants) I'm using the code below to on echo certain words based on their index/key value, this works fine however, im trying to only do this in exploded quotes... the problem is, exploding quotes turns the portion into an array which cant be passed to str_word_count... how can i do the same thing only inside quotes. So that hello world "this is a test" would become: Code: [Select] Hello World This [0] => Is [1] => a [2] => Test [3] Im trying to always remove say the 4th word in quotations, or maybe the 3rd and 4th, whatever i want to omit i leave out from the echo, so echo $data[0].' '.$data[3].'; would output "This Test" omitting "Is A" Code: [Select] $data = 'hello world "this is a test"'; $data = str_word_count($data, 1); echo $data[1].' '.$data[2].' '.$data[0]; I have no idea why but no matter what the eventid is, the label always returns 20 and I"m not sure why. Is my synatx wrong? $eventid = (int)$_GET['eventid']; $result = mysqli_query($dbc, "SELECT count(label) FROM `events` WHERE `event_id` = '$eventid'"); $label = $result + 1; echo $label; This is a dummy question but i cant get multiple criteria in the count function.
This is what i'm trying to do:
SELECT COUNT(Name, Expansion, Foil) AS NameCheck FROM Osiris WHERE Name="$name" Expansion="$expansion" Foil="$foil"I have Colums named: `Name` `Color` `Type` `Subtype` `Power` `Toughness` `Manacost` `Rarity` `Expansion` `Foil` `Stock`I want to check before i enter a new record if its not already there, by checking the Name, Expansion and Foil colum on the same record. I think i have just messed up that code line but i cant seem to find any solution on the web. Thanks in advance! Hi, I want the user to be able to go to one page and hit a button, once he hits the butten I want a count down to start from 10 minutes. When the user goes to the page within those 10 minutes, I want it to show him a live countdown until those ten minutes run out. Any ideas how I would go about doing this? Code: [Select] function width2($noid) { $getwidth = mysql_query("SELECT * FROM block WHERE sid='$theid'",$this->connect); while($row1 = mysql_fetch_assoc($getwidth)) { $this->width2($noid); } } how do i count how many times the function loops? How can I modify the following code to not display $hash_row['total'], but to display the sum of the counted "total" value + 1? Is there a way that I can assign that variable in the "select query" area (for instance, "COUNT(hr.hasher_id) + 1 as total1"), and then call $hash_row['total1] in the result table? I'm not sure if the syntax exists to add an integer value to a COUNT value and assign to a new variable... Code: [Select] <?php include "modules/dbase_connection.php"; #create MySQL connection $sql_connection = sql_connect("blah","blah","blah","blah"); # select the Hashers and hashes by total number<br /> $hash_query = " SELECT ha.*, COUNT(hr.hasher_id) as total FROM hashers as ha, hash_records as hr WHERE hr.hasher_id = ha.hasher_id GROUP BY hr.hasher_id ORDER BY total DESC "; $hash_result = mysql_query($hash_query) or die(mysql_error()); $x = 1; while($hash_row = mysql_fetch_array($hash_result)) { #display the table header if($x == 1) { echo ' <br /> <table align="left"> <br /> <tbody> <tr><br /><td colspan="2"><strong>Potential On-Sec</strong></td><br /></tr>'; $x++; } echo '<tr><br /><td>' . $hash_row['hasher_name'] . '</td><br /><td>' . $hash_row['total'] . '</td><br /><td>- ' . $hash_row['real_name'] . '</td><br /></tr>'; } echo '</tbody></table></td><br />'; ?> Hi All, I have a script that i bought and a part of it has a share icon with an email icon so if the user clicks the email icon then it opens up your email client and adds the details of the deal to the email. The problem is that it seems to break each word up by placing a + between them. So for example you get this... Come+and+check+out+Welcome+to+theSocialDeal,+they+have+this+great+local+deal,+if+we+all+buy+it+then+we+get+it+cheaper! Today's+Deal:+4+hours+of+extreme+MTB+action+at+John+Doe+Extreme+Trail+Centre+for+the+price+of+1+hour Click+this+link+to+check+it+out:+ which should be this... Come and check out Welcome to theSocialDeal, they have this great local deal, if we all buy it then we get it cheaper! Today's Deal: 4 hours of extreme MTB action at John Doe Extreme Trail Centre for the price of 1 hour Click this link to check it out: Here is the php function, does anyone know what this could be and how i can stop it? function share_mail($team) { global $login_user_id; global $INI; if (!$team) { $team = array( 'title' => $INI['system']['sitename'] . '(' . $INI['system']['wwwprefix'] . ')', ); } $pre[] = "Come and check out {$INI['system']['sitename']}, they have this great local deal, if we all buy it then we get it cheaper!"; if ( $team['id'] ) { $pre[] = "Today's Deal: {$team['title']}"; $pre[] = "Click this link to check it out: "; $pre[] = $INI['system']['wwwprefix'] . "/team.php?id={$team['id']}&r={$login_user_id}"; $pre = mb_convert_encoding(join("\n\n", $pre), 'UTF-8', 'UTF-8'); $sub = "The Deal: {$team['title']}"; } else { $sub = $pre[] = $team['title']; } $sub = mb_convert_encoding($sub, 'UTF-8', 'UTF-8'); $query = array( 'subject' => $sub, 'body' => $pre, ); $query = http_build_query($query); return 'mailto:?'.$query; } Write a function Counter() that keeps track of the number of times it is called. This function should not take any parameters and return the number of times that it has been called. I know there has to be a better way to count how many entries I have in my mysql db than what I'm currently using. Let me just show you what I'm trying to do and it will make better sense. http://batads.com/display.php You see how I am echoing the number of each category on one page? I am sure the current script I am using is insanely inefficient and as my DB grows I think it will cause me problems. Any suggestions on how to do this more efficiently? Below is what is currently running that page. Thank you. Code: [Select] <td><h4>Public Ads</h4><br> <?php echo '<a href="browse1.php?cat=1">Bill Boards<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='1'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=2">Transportation<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='2'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=4">Shopping Centers<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='4'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=3">Posters / Signs<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='3'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=5">Bus Stops<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='5'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=6"> Other-Public<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='6'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Event Sponsorship</h4><br> <?php echo '<a href="browse1.php?cat=7">Concerts<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='7'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=8">Fairs<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='8'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=10">Sports<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='10'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=9">Trade Shows<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='9'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=11">Other-Event<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='11'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Online Ads</h4><br> <?php echo '<a href="browse1.php?cat=12">Banner Space<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='12' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=13">Social Media<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='13' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=14">Email Lists<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='14'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=15">Blog Articles<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='15'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=16">Ezine Articles<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='16'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1area.php?cat=17">Other-Online<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='17'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </tr> <tr> <td><h4>Print Ads</h4><br> <?php echo '<a href="browse1.php?cat=18">Magazine<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='18'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=19">Newspaper<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='19'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=20">Brochure<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='20'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=21">Press Release Print<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='21'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=22">Other-Print<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='22'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Broadcasting Ads</h4><br> <?php echo '<a href="browse1.php?cat=23">TV / Commercial<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='23'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=24">Radio<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='24'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=27">Movies<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='27'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=25">Mobile Phone<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='25'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=28">Cinema<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='28'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=26">Press Release TV<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='26'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=29">Other-Broadcast<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='29' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Commercial Space</h4><br> <?php echo '<a href="browse1.php?cat=33">Private Property<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='33'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=34">Vehicle Wrap<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='34'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=35">Front Yard<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='35'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=36">Self Promotion<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='36'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=37">Other-Commercial<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='37'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </tr> <tr> <td><h4>Business Ads</h4><br> <?php echo '<a href="browse1.php?cat=30">Window Display<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='30'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=31">Interior Ads<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='31'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=32">Point of Sale Ads<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='32'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=41">Other-Business <a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='41'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </td> <td><h4>Misc</h4><br> <?php echo '<a href="browse1.php?cat=38">Creative Advertising<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='38'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=39">Video Games<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='39'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=40">Other-Misc<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='40'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> </td> </tr> </table> Hi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles Hey guys i found this script that works great for what i need .. se i have this script that i did for my body (loan application) now i would like to export the info in a word doc <?php $ExcelFileName="test.doc"; header("Content-type: application/x-ms-download"); header("Content-Disposition: attachment; filename=$ExcelFileName"); header('Cache-Control: public'); $content=<<<EOD echo 'php'; whatever you want to write here including a php script it will be included in a string and then go in the output for a doc file EOD; echo $content; ?> so im trying to eco all the content in the database.. i tryed all the DB connection is there.. ao i place this after the (echo 'php' while($info = mysql_fetch_array($fileLIST)){; echo $info['PERS_F_NAME']; }; i get this? Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/autosspe/public_html/admin/loan/word.php on line 21 I have this code below the browser shows correct data but when i export to word I see $proc output not the switch data like on the the browser page
How should code be written to show the same on word doc .
I'm new to this learning by trial and error Please go easy on me .
Thanks
<td> <? I'm going to post the code that I am currently using and then explain what I'm trying to do. I hope I can explain it well enough. <?php if (!isset($_POST['submit'])) { echo'<leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"> <center><form name="fairlistlist" method="POST" action="'.$_SERVER['PHP_SELF'].'"> <TABLE width="450" height="119" border=0 cellPadding=3 cellSpacing=2 bgcolor="#fff568"> <TBODY> <TR> <TD class=mainText width="100"><b>Event Name</b></TD> <TD width="305" class=frmInput> <INPUT class=mainFormBox style="WIDTH: 320px" type="text" name=" fairname"></TD> </TR> <TR> <TD class=mainText width="100"><B>Event Address</B></TD> <TD class=frmInput> <INPUT name="fairadd" type="text" class=mainFormBox id="fairadd" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event City</b></TD> <TD class=frmInput> <INPUT name="faircity" type="text" class=mainFormBox id="faircity" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event County</b></TD> <TD class=frmInput> <INPUT name="faircty" type="text" class=mainFormBox id="faircty" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event State</b></TD> <TD class=frmInput> <INPUT name="fairstate" type="text" class=mainFormBox id="fairstate" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Country</b></TD> <TD class=frmInput> <INPUT name="fairctry" type="text" class=mainFormBox id="fairctry" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Opening Date</b></TD> <TD class=frmInput> <INPUT name="fairopen" type="text" class=mainFormBox id="fairopen" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Closing Date</b></TD> <TD class=frmInput> <INPUT name="fairclose" type="text" class=mainFormBox id="fairlose" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Contact Email</b></TD> <TD class=frmInput> <INPUT name="fairmail" type="text" class=mainFormBox id="fairmail" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Website</b></TD> <TD class=frmInput> <INPUT name="fairweb" type="text" class=mainFormBox id="fairweb" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=frmDescription width="56"> </TD> <TD class=frmInput> <div align="right"> <input type="submit" name="submit" value="Add my Event" /> </div></TD> </TR> </TBODY> </TABLE> </form></center> </body>'; //note that I added a new field called submit and it's hidden .. } else { /*I added addslashes() so it escape any special char in the form .. if you want to show your inserted record , you need to use stripslashes() to remove any slashes from the record .. this is only to avoid some security problems in the query ..*/ $fairname=trim(addslashes($_POST['fairname'])); $fairadd=trim(addslashes($_POST['fairadd'])); $faircity=trim(addslashes($_POST['faircity'])); $faircty=trim(addslashes($_POST['faircty'])); $fairstate=trim(addslashes($_POST['fairstate'])); $fairctry=trim(addslashes($_POST['fairctry'])); $fairopen=trim(addslashes($_POST['fairopen'])); $fairclose=trim(addslashes($_POST['fairclose'])); $fairmail=trim(addslashes($_POST['fairmail'])); $fairweb=trim(addslashes($_POST['fairweb'])); include("Connections/local.php"); $link = mysql_connect($hostname_local,$username_local, $password_local) or die("Could not connect"); mysql_select_db('fair123') or die("Could not select database"); $insert=mysql_query("INSERT INTO events (fairidnum, fairname, fairadd, faircity, faircty, fairstate, fairctry, fairopen, fairclose, fairmail, fairweb) VALUES('NULL', '$fairname', '$fairadd', '$faircity', '$faircty','$fairstate', '$fairctry','$fairopen', '$fairclose', '$fairmail', '$fairweb')")or die('couldn\'t Insert record into database :'.mysql_error()); header( 'Location: event_added.php' ) ; } ?> Especially look at the code part here $insert=mysql_query("INSERT INTO events (fairidnum, fairname, fairadd, faircity, faircty, fairstate, fairctry, fairopen, fairclose, fairmail, fairweb) VALUES('NULL', '$fairname', '$fairadd', '$faircity', '$faircty','$fairstate', '$fairctry','$fairopen', '$fairclose', '$fairmail', '$fairweb')")or die('couldn\'t Insert record into database :'.mysql_error()); header( 'Location: event_added.php' ) ; } ?> this is where I am having problems it was reading echo your record has been successfully added to the database What I want is for it to open up a new page with my menu and my css and all that good crap to a page where it will read the following Your information has been added to our database We have added Event name = "whatever the event's name was" Event address = "address:" so on and so on for all the fields in my form that was submitted to the database. with just using the echo command it always opened to just a blank page no formatting and no css as well as no all important links Can you please tell me what I'm doing wrong or where I can find a good guideline that Is easy to understand on how to do this? Thanks in advance Oh also I don't care if that page get's indexed by google or yahoo or not actually prefer it don't get indexed to be honest |