jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
I made a *few* changes, most importantly, I commented the code for you to see what is happening. <?php $email = strip_tags($_GET['email']); $name = strip_tags($_GET['name']); if (empty($email)) { //if the email string is empty. require_once ("xyz1.html"); //require the server to load the xyz1.html file,or else spit out an error. } else { //if $_GET['email'] is NOT empty. $pos = strrpos($email, "@"); //find out if email string has @ in it. if ($pos != false) { //if the position of the @ symbol is not the first character, and it IS in the string. $to = "email@address.com"; //identify your email address explicitly. $headers = "From: \"".$name."\"<".$email.">\n"; //add their email address in the from field. NOTE* Some hosts require this field to be poplulated by an email address that resides on YOUR server (ie. your email address). $message = " \n Name: $name , ..."; //build message. if(mail ($to, mailheadersubject, $message, $headers)) { //send mail. require_once ("send.html"); //if mail successfully sent, include this file. } else { die('There was an error sending the message'); //if mail failed to send message, tell us. } } else { require_once ("xyz2.html"); //if the @ symbol was not found, include this file. } }
-
Consider something along the lines of: <?php class armor { // Head public $head; public $torso; public $pants; public $gloves; public $boots; // new stuff here function __construct(array $items) { foreach($items as $k => $v) { $this->{$k} = $v; } } function set_head($head) { $this->head = $head; } function get_head() { return $this->head; } function set_torso($torso) { $this->torso = $torso; } function get_torso() { return $this->torso; } function set_pants($pants) { $this->pants = $pants; } function get_pants() { return $this->pants; } function set_gloves($gloves) { $this->gloves = $gloves; } function get_gloves() { return $this->gloves; } function set_boots($boots) { $this->boots = $boots; } function get_boots() { return $this->boots; } } $armor = new armor( array('head' =>'bucket','torso'=>'20cm chainmail','pants'=>'4cm plate','gloves'=>'gauntlet','boots'=>'leather') ); //for use with database /* $sql = "SELECT head,torso,pants,gloves,boots FROM armor WHERE id = '1'"; $result = mysql_query($sql) or trigger_error($sql . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $armor = new armor($row); } */ echo "You are wearing (head): " . $armor->get_head(); echo "<br />"; echo "You are wearing (torso): " . $armor->get_torso(); echo "<br />"; echo "You are wearing (pants): " . $armor->get_pants(); echo "<br />"; echo "You are wearing (gloves): " . $armor->get_gloves(); echo "<br />"; echo "You are wearing (boots): " . $armor->get_boots(); ?>
-
Post the complete error, and the complete script (or at least 5 lines before, and after the error).
-
<?php session_start(); //Make sure we are getting desired results from the post array. echo '<pre>'; print_r($_POST); echo '</pre>'; include('db_config.php'); $name=($_POST['name']); $telephone=addslashes($_POST['telephone']); $email=addslashes($_POST['email']); $code=md5($email.time()); $checkout_date=$_SESSION['checkout']; $checkin_unix=$_SESSION['checkin_unix']; $checkout_unix=$_SESSION['checkout_unix']; $roomtype=$_SESSION['roomtype']; $checkin_date=$_SESSION['checkin']; for ($stay_date=$checkin_unix; $stay_date < $checkout_unix; $stay_date=$stay_date+24*60*60) { //Moved if statement to 2nd parameter of for loop. mysql_query("INSERT INTO reservations VALUES( '', '$roomtype', 'pending', 'date ('d/m/Y', $stay_date)', '$stay_date', '$checkout_date', '$name', '$telephone', '$email', '$code' )") or trigger_error( mysql_error() ); //add error checking. } ?> Made some changes, You should get a printout at the head of the page with the contents of the _POST array. Make sure it contains what YOU think it does.
-
I would approach this as a table join. Something like this. UN-TESTED. <?php if(isset($_POST['search'])) { $tool = (isset($_POST['tool'])) ? $_POST['tool'] : 1; $sql = "SELECT a.id,a.tool,a.barcode,a.location, b.status,b.who,DATE_FORMAT(a.datechanged,'%b %e, %Y) AS datechanged1 FROM tools AS a JOIN toolout AS b ON a.id = b.toolid WHERE a.toolgroup LIKE '%$tool%' ORDER BY b.id, a.tool "; $result = mysql_query($sql) or trigger_error( mysql_error() ); if(mysql_num_rows($result) > 0) { echo "<table border='1' style='border-collapse: collapse' bordercolorlight='#000000' bordercolordark='#000000' width='98%' align='center'>"; echo "<tr><td width='100%' colspan='5' align='center'><b>Tool List - $tool</b></td></tr>"; echo "<tr> <th align='center'>Tool</th> <th>Location</th> <th>Status</th> </tr>"; while( $row = mysql_fetch_assoc($result) ) { extract($row); switch( (int) $status ) { case 1: $statusout="<font color='#0000FF' size='4'>IN</font><br /><a href='toolout.php?tool=" . $id . "' target='action'>SIGN OUT</a>"; break; case 2: $statusout="<font color='#FF0000' size='4'>OUT</font><br />$who - $datechanged1"; break; case 3: $statusout="<font color='#00FF00' size='4'>PENDING OUT</font><br />$who - $datechanged1"; break; case 4: $statusout="<font color='#00FF00' size='4'>PENDING IN</font><br />$who - $datechanged1"; break; default: $statusout = "Status Unkown!"; } echo "<tr>\n<td align='center'>" . $tool . "</td>\n" . "<td align='center'>" . $location . "</td>\n" . "<td align='center'>" . $statusout . "</td>\n</tr>\n"; } echo "</table>"; } else { echo 'Search Results returned NULL'; } } ?> Hit me back (with a db dump) if that query doesn't work, and I'll get it sorted for you.
-
When PHP parser gives you a line, always look at that line, and the lines above it. For instance, if you missed a semi-colon on line 23, then it will see the string on 24 as Un-expected.
-
The reason was that you where trying to use a variable inside of a single quoted string. PHP doesn't parse variables inside of a single quoted string, you must use a double quoted string.
-
Why not check the email, BEFORE it goes to paypal?
-
You could also try. SELECT a.title, a.url, a.parent_id, b.id, b.title AS baseTitle, b.url AS baseUrl FROM user_menu AS a LEFT JOIN user_menu as b ON b.id < a.parent_id WHERE a.url = '/products/microsoft/' Then sort the results, via PHP, to get the desired links.
-
SELECT a.title, a.url, b.title AS baseTitle, b.url AS baseUrl, c.title AS parentTitle, c.url AS parentUrl FROM user_menu AS a LEFT JOIN user_menu as b ON b.id = a.parent_id LEFT JOIN user_menu AS c ON c.id = b.parent_id WHERE a.url = '/products/microsoft/' UNTESTED!!! If the url belongs to a row that's parent ID is equal to an available ID, it will assign it to the `baseTitle` and `baseUrl`, and likewise if that tier also has a parent. This query will only go 3 layers deep, if it even works at all.
-
cant get simple php and ajax to work together :(
jcbones replied to busby's topic in PHP Coding Help
I don't believe you can get an option value out of a select box, with that javascript. You must use the one I posted above. Although, I have been known to be wrong up to 48 times per day, just ask the wife. -
How to redirect to another page on the submit button of the form???
jcbones replied to hmdnawaz's topic in PHP Coding Help
You could put the name of the page in the `action` attribute of the form element tag. -
Does your database column have enough space for a MD5 hash?
-
Here is an example of piecing the sql. if(isset($_GET['category']) { $where[] = 'category = \'' . mysql_real_escape_string($_GET['category']) . '\''; } if(isset($_GET['type'])) { $where[] = 'type = \'' . mysql_real_escape_string($_GET['type']) . '\''; } if(isset($_GET['colour'])){ $where[] = 'colour = \'' . mysql_real_escape_string($_GET['colour']) . '\''; } if(is_array($where)) { $sqlCommand = "SELECT * FROM products WHERE " . implode(' AND ',$where); }
-
No, MySQL DateTime accepts dates stored in the following format: YYYY-MM-DD HH:MM:SS. You can set MySQL's timezone for the client (if your build has a timezone table) by running a query of SET SESSION time_zone = $timezone You can pass the parameter to MySQL using PHP's date() function(if you can't by MySQL), as long as it is in the MySQL format. You can set PHP's timezone at runtime with date_default_timezone_set().
-
cant get simple php and ajax to work together :(
jcbones replied to busby's topic in PHP Coding Help
Post your updated code. -
This has been fixed through another thread.
-
cant get simple php and ajax to work together :(
jcbones replied to busby's topic in PHP Coding Help
Try changing: <select name="users" onchange="showMessage(this.value)"> To: <select name="users" onchange="showMessage(this.options[this.selectedIndex].value)"> -
addguestbook.php <?php $host="localhost"; // Host name $username="lxxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="xxxxx"; // Database name $tbl_name="xxxx"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); //DO NOT RELY ON GLOBALS, instead set your own variables. $name = (isset($_POST['name'])) ? mysql_real_escape_string($_POST['name']) : NULL; $email = (isset($_POST['email'])) ? mysql_real_escape_string($_POST['email']) : NULL; $comment = (isset($_POST['comment'])) ? mysql_real_escape_string($_POST['comment']) : NULL; $error = 0; //UN-COMMENT THIS BLOCK TO REQUIRE DATA// //NAME //if($name == NULL) { $error = 1; $tell[] = 'You MUST have a name!'; } //EMAIL //if($email == NULL || preg_match('~^\w+[\w-\.]*\@\w+((-\w+)|(\w*))\.[a-z]{2,3}$~',$email)) { $error = 1; $tell[] = 'Invalid email address'; } //COMMENT //if($comment == NULL) { $error = 1; $tell[] = 'Please type a comment'; } //END OF CHECKS. if($error != 0) { foreach($tell as $value) { echo $value . '<br />'; } } else { $sql="INSERT INTO $tbl_name(name, email, comment, datetime) VALUES('$name', '$email', '$comment', NOW())"; //NOW() is a database function that inserts the current timestamp. $result=mysql_query($sql); //check if query successful if($result){ echo "Successful"; echo "<BR>"; echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page } else { echo "ERROR"; } } mysql_close(); ?> Does your database table even have an 'id' column?
-
Something like this? <?php $order = (isset($_GET['o']) && in_array(strtoupper($_GET['o']), array('ASC','DESC'))) ? strtoupper($_GET['o']) : 'ASC'; $sql = mysql_query("SELECT * FROM tablename ORDER BY id $order"); $nr = mysql_num_rows($sql); if (isset($_GET['pn'])) { $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); } else { $pn = 1; } $itemsPerPage = 8; //number of rows per page $lastPage = ceil($nr / $itemsPerPage); if ($pn < 1) { $pn = 1; } else if ($pn > $lastPage) { $pn = $lastPage; } $centerPages = ""; $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '&o=' . $order . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '&o=' . $order . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '&o=' . $order . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '&o=' . $order . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '&o=' . $order . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '&o=' . $order . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '&o=' . $order . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '&o=' . $order . '">' . $add1 . '</a> '; } $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; $sql2 = mysql_query("SELECT * FROM tablename ORDER BY id $order $limit"); //second query $paginationDisplay = ""; if ($lastPage != "1"){ $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. ' '; if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '&o=' . $order . '"> Back</a> '; } $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '&o=' . $order . '"> Next</a> '; } } $outputList = ''; while($row = mysql_fetch_array($sql2)){ print "$row[permalink]"; print "$row[title]"; } ?> </div> <h2>Total Items: <?php echo $nr . '( <a href="?pn=' . $pn . '&o=ASC">Ascending</a>/<a href="?pn=' . $pn .'&o=DESC">Descending</a> )'; ?></h2> <?php echo $paginationDisplay; ?> <?php print "$outputList"; ?>
-
You may need to pass part of the string to the function. As the offset counts in bytes, which includes part of the pattern. I would use: $SetNumber = preg_match_all($Pattern,substr($Page,$NumberPosition),$Matches, PREG_OFFSET_CAPTURE);
-
cant get simple php and ajax to work together :(
jcbones replied to busby's topic in PHP Coding Help
Yep, run the code in firefox, and open up the error console (cntrl+shift+j). Clear the console, then submit the form. Look at the console, and it will de-bug the javascript for you. -
Database capscity calculation : Queries per page... ?
jcbones replied to inversesoft123's topic in PHP Coding Help
I think that would be limited by the server's memory allocation. The more memory, the more supported users. I think phpBB forums use around 20 queries per page, and some of those are very busy. As far as capacity, the documentation says that there are known databases with 2K tables, and over 5B rows. -
cant get simple php and ajax to work together :(
jcbones replied to busby's topic in PHP Coding Help
You are calling showMessage in your form, but you function name is showUser -
PREG_OFFSET_CAPTURE doesn't start in the middle of the string, it stores the offset, in the array, of each matched section. You can pass the function an offset as it's fourth argument. But, this is evaluated in bytes, and wouldn't be the same as passing it part of the string using the substr() function. It is explained here