jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
Copy and paste the function above to your page. Then run your number through it. echo convertNumber($_POST['number']);
-
Oh, you don't know how bad you need validation. Try something like: <?php // Contact subject $subject ="Website enquiry"; // Details $message=trim(strip_tags($_POST['detail'])); $name = trim(strip_tags($_POST['name'])); $webste = trim(strip_tags($_POST['website'])); // Mail of sender $mail_from=trim(strip_tags($_POST['customer_mail'])); // From $header="from: $name <$mail_from>"; // Enter your email address $to ='robin@rdosolutions.com'; $message = $name . PHP_EOL . $website . PHP_EOL . $mail_from . PHP_EOL . $message; $send_contact=mail($to,$subject,$message,$header); // Check, if message sent to your email // display message "We've recived your information" if($send_contact){ echo "We've recived your contact information"; } else { echo "ERROR"; } ?>
-
Your two sql query's don't match, the count is coming from penapps, and your data is coming from numbers.
-
When I include files I do 2 things. 1. I define a constant, and then check it in the included file. index.php define('IN_PROGRAM',true); IncludedFile.php if(!defined('IN_PROGRAM')) { die('You cannot access this file directly!'); } 2. I use .htaccess in my include directory. I set it to deny all, so only the server can access those files. .htaccess order deny,allow deny from all It is better to be sure, so I use both.
-
You want the max score in score1? SELECT clan1 FROM {$table} ORDER BY score1 DESC LIMIT 1 OR, You want the clan with the highest score accumulation in score1? SELECT clan1, SUM(score1) as score FROM {$table} ORDER BY score DESC LIMIT 1
-
1. $s is not defined, it is used on line 30 for addition purposes, but nowhere is it's initial value set. 2. I'm thinking that $numrows is suppose to point back to Line 24, but that is set to $numresults. Change this name to $numrows as that variable is used more than once. 3.$PHP_SELF is only if Globals are on, which in later releases of PHP they are not. Change to $_SERVER['PHP_SELF']. 4. There is no $var in your script, they are $var1,$var2,$var3,$var4. Correct those 4 things, should get you well on your way.
-
Or, just call: mysql_fetch_assoc($info); //or mysql_fetch_row($info);
-
$result = mysql_query($query) or die(mysql_error()); //Add the following lines: if(mysql_num_rows($result) < 1) { echo 'The record could not be found.'; //to end the script un-comment the next line: //exit(); }
-
Try: $query = "SELECT a.entry_id, b.title FROM blog_catjoin as a, blog as b WHERE (a.entry_id = b.entry_id) AND a.cat_id='8'"; $result = mysql_query($query) or die($query . ' <br /> ' . mysql_error()); while($row = mysql_fetch_array($result)) { echo "<a href=/activities.php?id=" . $row['entry_id'] . " class=n>" . $row['title'] . '</a><br />' . "\n"; } mysql_close($con); ?> And let us know how it goes...
-
How to get pictures to start on a new line
jcbones replied to thereaper87's topic in PHP Coding Help
Check against $counter, not $resultNum $numCols = 5; $counter = 1; echo "<table>"; echo "<tr>"; //the table while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $url = $r['url']; echo "<td>Cell content</td>"; echo "<td><img src='$url' width='225' height='225'><br /><div align='center'><a href='test.php?act=view&id=$id'>$title</a></div></td>"; if ($counter % $numCols == 0) { echo "</tr>"; echo "<tr>"; } // end if $counter++; // This line } // end while echo "</tr>"; echo "</table></div>" -
Give us the table names, and the table structures. You can do this with one query using a table JOIN.
-
Try: <?php if(isset($_POST['customer_id'])){ $customer_id=$_POST['customer_id']; $query = "select * from customer where customer_id=" .$customer_id; $result = mysql_query($query) or die(mysql_error()); while ($row=mysql_fetch_array($result)){ ?> <tr> <td> </td> <td class="title02"> </td> <td> </td> <td> </td> </tr> <tr height="30"> <td width="2%" height="35"> </td> <td width="46%" class="title02" align="left">National ID</td> <td width="50%" class="attribute1" align="left"><input type="text" name="nic" size="30" class="attribute1" value="<?php echo $row['nic'];?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td height="33"> </td> <td width="46%" class="title02" align="left">Full Name</td> <td width="50%" class="attribute1" align="left"><input type="text" name="full_name" size="30" class="attribute1" value="<?php echo $row['full_name'];?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td height="34"> </td> <td class="title02" align="left">Name With Initials</td> <td width="50%" class="attribute1" align="left"><input type="text" name="name_with_initials" size="30" class="attribute1" value="<?php echo $row['name_with_initials'];?>"></td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Address</td> <td width="50%" class="attribute1" align="left"><label> <textarea name="address" id="textarea" cols="45" rows="5"><?php echo $row['address']; ?></textarea> </label></td> <td width="2%"> </td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Contact Number</td> <td width="50%" class="attribute1" align="left"><input type="text" name="contact_number" size="30" class="attribute1" value="<?php echo $row['contact_number']?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Sex</td> <td width="50%" class="attribute1" align="left"><p> <select name="gender" id="jumpMenu" > <option selected="selected"><?php echo $row['gender']; ?></option> <option>Male</option> <option>Female</option> </select> <td width="50%" class="attribute1" align="left"> </td> <br /> </p></td> <td width="2%"> </td> </tr> </table> <p align="center"> </p> <p align="center"> <label> </label> <label> <input name="button" type="submit" id="button" value="Approve Account" /> </label> <label> <a href="accsup_help.php"> <input name="button" type="submit" id="button" value="Help" /> </a></label> </td> </p> </fieldset> <td width="5%"> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> <tr> <td> </td> <td><font color="red" size="1" ></font></td> <td> </td> </tr> <?php } } ?>
-
Can't display text from MySQL on page
jcbones replied to brendansingleton's topic in PHP Coding Help
You need to verify that your installation has MySQL support. 1. make a test page with the following. testpage.php <?php phpinfo(); exit(); ?> Open this page and see if there is a section named MySQL. 2. IF IT DOESN"T, re-compile the installation with MySQL support. 3. IF IT DOES. Open up the file php.ini and make sure the line to enable MySQL support is un-commented. In Linux that line is: extension=mysql.so In Windows that line is: extension=php_mysql.dll Post back and let us know how it goes. -
mysql_query("UPDATE custom_pages SET title='$titlee' , content='$contente' WHERE id='$to'") or die (mysql_error());
-
No need to use a while loop, because the query is limited to return 1 row. If you want to show all the streaks, you can use a while loop, and remove the "LIMIT 1" from the end of the query.
-
SELECT COUNT(matchID) as count, clan1 from {$table} WHERE score1 > score2 group by clan1 order by count DESC LIMIT 1 Try that, and let me know how it goes. Be sure and add the table name into that query.
-
Mysql LIKE Search query - How to get most accurate row first.
jcbones replied to rahulephp's topic in PHP Coding Help
Couple of things. $kt=split(" ",$search_text);//Breaking the string to array of words => ***This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.*** //Instead use: $kt=explode(" ",$search_text);//Breaking the string to array of words If you only wanted rows relevant to the actual search parameters, you could include them all into 1 parameter separated by the wildcards. SELECT * FROM `products` WHERE name like '%Nintendo%DS%Lite%Pink%' -
Show us what you have tried, and we can help flesh it out.
-
And you were there for...?
-
Make sure it is a valid address, or some host will drop the email into the trash without sending it.
-
You need to call trim on each $var, not all of them together. As well, on line 39 you executed a query, then you used the resource to try and execute it again. THAT is a big no no, and you will get the response you received from PHP parser. Try this: <?php // Get the search variable from URL $var1 = trim(@$_GET['beds']); $var2 = trim(@$_GET['area']) ; $var3 = trim(@$_GET['price']) ; $var4 = trim(@$_GET['type']) ; // rows to return $limit=10; // check for an empty string and display a message. if ($var1 == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var1)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } $host = "localhost"; $username = "root"; $password = ""; //connect to your database ** EDIT REQUIRED HERE ** $link = mysql_connect($host, $username, $password) or die("Unable to connect to SQL Server"); //(host, username, password) $db = "property_db"; //specify database ** EDIT REQUIRED HERE ** mysql_select_db($db, $link) or die("Unable to select database"); //select which database we're using // Build SQL Query $results = "SELECT * FROM house_src"; // get results $result = mysql_query($results) or die("Couldn't execute query"); $numresults = mysql_num_rows($result); // display what the person searched for echo "<p>You searched for: ". $var4 . "property, with ". $var1 . " bedrooms, in the " . $var2 . "area, with a price range of " . $var3 .""; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?>
-
You are defining $pic on line 19 as an empty string. Line 22: You are calling a global on $pic to include it into the function displayPhotos(); Line 34: Is the next time you are calling $pic. You are asking it if $pic[1] (array) is set <= which will fail everytime as $pic is an empty string. Line 36 & 37: defines $sel, as this if loop on $pic[1] will always fail due to $pic being an empty string, and not an array, then $sel will NOT be defined. Thus the errors.
-
OK, so a whole new re-write. (not quite) 1. The expected input values for the date ("from" and "to") are YYYY-mm-dd, YYYY/mm/dd, or mm/dd/YYYY. Basically any combination that strtotime() accepts. 2. If it were me, I would use the jQuery datepicker to make sure these inputs get the correct values. http://jqueryui.com/demos/datepicker/ Here are the files. TABLE STRUCTURE -- -- Table structure for table `user` -- CREATE TABLE IF NOT EXISTS `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(20) NOT NULL, `lastname` varchar(20) NOT NULL, `age` int(3) NOT NULL, `hometown` varchar(25) NOT NULL, `job` varchar(25) NOT NULL, `birthday` date NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; index.php <?php include('config.php'); //Include the database connections in it's own file, for easy integration in multiple pages. $lastname_result = mysql_query("SELECT lastname FROM user GROUP BY lastname"); $result = mysql_query("SELECT * FROM user"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../themes/style.css" rel="stylesheet" type="text/css" media="print, projection, screen" /></link> <link href="../common.css" rel="stylesheet" type="text/css"></link> <script type="text/javascript" src="ajax.js"></script> <?php //link to ajax.js ?> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td width="160" valign="top"></td> <td width="732" valign="top"> <table width="90%" border="0" align="center"> <form action="test3.php" method="post"> <label for="startage">From</label> <input type="text" id="from" name="from" onkeyup="getNames();" /> <?php //added javascript function call to function located in "ajax.js" ?> <label for="endage">to</label> <input type="text" id="to" name="to" onkeyup="getNames();" /> <?php //added javascript function call to function located in "ajax.js" ?> <select id="selectbox" name="area" onchange="getResults(this.value);"> <?php //added javascript function call to function located in "ajax.js", and changed the id for content change via javascript. ?> <option value="">Select an lastname</option> <option value=""></option> <?php while(list($lastname)=mysql_fetch_array($lastname_result)) { echo "<option value='$lastname'>$lastname</option>"; } ?> </select> </form> </table> <table id="tablesorter" class="tablesorter" border="0" cellpadding="0" cellspacing="1"> <thead> <tr> <th>First Name</th> <th>Last Name</th> <th>Age</th> <th>Birthday</th> <th>Hometown</th> <th>Job</th> </tr> </thead> <tbody id="tableBody"> <?php //added id to the tbody so we could change the content via javascript ?> <?php while($row=mysql_fetch_assoc($result)){ ?> <tr> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['birthday']; ?></td> <td><?php echo $row['hometown']; ?></td> <td><?php echo $row['job']; ?></td> </tr> <?php } // End while loop. ?> </tbody> </table> <p> </p> <p> </p> <p align="right"> </p> </td> <td width="196" valign="top"> </td> </tr> </table> </body> </html> select.list.php <?php include('config.php'); //database connections. if(!isset($_GET['to']) && !isset($_GET['from'])) { //if the uri parameters are not there send em to google. header('Location: http://google.com'); exit(); } $from = (isset($_GET['from'])) ? date('Y-m-d',strtotime($_GET['from'])) : NULL; $to = (isset($_GET['to'])) ? date('Y-m-d',strtotime($_GET['to'])) : NULL; if($from != NULL && $to != NULL) { $where = " WHERE birthday BETWEEN '$from' AND '$to'"; } elseif($from != NULL) { $where = " WHERE birthday >= '$from'"; } elseif($to != NULL) { $where = " WHERE birthday <= '$to'"; } $query = "SELECT lastname FROM user $where GROUP BY lastname"; //write the query. //echo $query; $lastname_result = mysql_query($query) or die($query . ' ' . mysql_error()); //execute the query, or die trying. echo '<option value="">Select an lastname</option> <option value=""></option> '; while(list($lastname)=mysql_fetch_array($lastname_result)) { echo "<option value='$lastname'>$lastname</option>"; } ?> table.list.php <?php include('config.php'); //database connection. if(!isset($_GET['lastname'])) { //if the proper get parameter is not there, redirect to google. header('Location: http://google.com'); exit(); } $lastname = preg_replace('~[^A-Za-z]+~','',$_GET['lastname']); //strip out anything but alpha for the name. $lastname = trim($lastname); //trim the name from all whitespace. if($lastname != '') { //check against an empty string. could have just used "empty()". $where = ' WHERE lastname = \'' . $lastname . '\''; //write the where clause. } else { //if lastname is empty, the where clause will be to, and it will return all names. $where = NULL; unset($lastname); } $from = (isset($_GET['from'])) ? date('Y-m-d',strtotime($_GET['from'])) : NULL; $to = (isset($_GET['to'])) ? date('Y-m-d',strtotime($_GET['to'])) : NULL; if($from != NULL && $to != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthday BETWEEN '$from' AND '$to'"; } elseif($from != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthday >= '$from'"; } elseif($to != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthday <= '$to'"; } $query = "SELECT * FROM user $where"; $result = mysql_query($query); //get the database result. while($row=mysql_fetch_assoc($result)){ //loop and display data. ?> <tr> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['birthday']; ?></td> <td><?php echo $row['hometown']; ?></td> <td><?php echo $row['job']; ?></td> </tr> <?php } // End while loop. ?> No changes to ajax.js and no changes to config.php.
-
The problem with $sel is that it is only defined IF $pic[1] is defined, which it is NOT. $pic is defined as an empty string, and passed to the function via a global. Nowhere is $pic changed to an array, nor populated by anything. The email, and message indexes, are coming from the $_POST array. There is no check to make sure those variables are defined before working with them.
-
I'll add another Tutorial on here, as it was the one that helped me the most. http://www.tuxradar.com/practicalphp/6/0/0