jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
Stocks are all about the money, so you have to pay to play. Provides XML data of stock prices -> I am not affiliated with them, nor have I used their products
-
When you are checking one line, for one occurrence, just use preg_match().
-
Take a minute, and go through . It will save you loads of time in the future. Go through all 9 video's. Then your database structure will be the most efficient that it could be.
-
Most web host require your email to be sent from an account that exist on their servers. So you would need to go to your cPanel, and make an email account. Then hard code that account as the "From: $email" inside the email function.
-
Did you try it???
-
I would look at my database table and make sure I didn't have any unique keys that were causing duplicates to be dropped. I would then step in and sanitize, and validate the code so that I wouldn't get a compromised database. It is wide open to injection attacks. I would then move the email code into the same if statement as the database code, and only run it if the query is successful. Returning a failed response to the user, if the database query fails. //insert code mysql_query("SET NAMES 'utf8'"); mysql_select_db($database_international, $international); // check which button was clicked // perform calculation $DepartureDate=$_POST['fromdate']; $ReturnDate=$_POST['todate']; $num_nights=$_POST['num_nights']; $num_nights= stripslashes($num_nights); $DepartureDate = stripslashes($DepartureDate); // sql inject clean $regex = "/[A-Z]/"; $DATETIME = date("Y-m-j"); $TotalNumber=$_POST['TotalNumberAdults']+$_POST['TotalNumberChildren']; if (empty($_POST['Main']) && !empty($_POST['CustomerEmail']) && !preg_match("/http/i",$_POST['RequestText']) && !preg_match($regex, $DepartureDate) && !preg_match("/http/i",$_POST['CustomerCellphone'])&& !preg_match("/http/i",$_POST['CustomerHomephone']) && !preg_match($regex, $num_nights)){ $query = sprintf("INSERT INTO contact_form(CustomerLastName,CustomerFirstName_heb,CustomerEmail,CustomerCellphone,CustomerHomePhone,CategoryID,CountryID,CityID,RegionID,TotalNumber,TotalNumberAdults,TotalNumberChildren,children_ages,RequestText,DepartureDate,ReturnDate,num_nights,FlightsRequired,CarRentalRequired,StatusID,DATETIME,Newsletter,Contact_Method) VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($_POST['CustomerLastName']), mysql_real_escape_string($_POST['CustomerFirstName_heb']), mysql_real_escape_string($_POST['CustomerEmail']), mysql_real_escape_string($_POST['CustomerCellphone']), mysql_real_escape_string($_POST['CustomerHomePhone']), mysql_real_escape_string($_POST['CatID']), mysql_real_escape_string($_POST['CountryID']), mysql_real_escape_string($_POST['CityID']), mysql_real_escape_string($_POST['RegionID']), mysql_real_escape_string($TotalNumber), mysql_real_escape_string($_POST['TotalNumberAdults']), mysql_real_escape_string($_POST['TotalNumberChildren']), mysql_real_escape_string($_POST['children_ages']), mysql_real_escape_string($_POST['RequestText']), mysql_real_escape_string($_POST['fromdate']), mysql_real_escape_string($_POST['todate']), mysql_real_escape_string($_POST['num_nights']), mysql_real_escape_string($_POST['FlightsRequired']), mysql_real_escape_string($_POST['CarRentalRequired']), mysql_real_escape_string($_POST['StatusID']), mysql_real_escape_string($DATETIME), mysql_real_escape_string($_POST['Newsletter']), mysql_real_escape_string($_POST['Contact_Method'])); //email code if(mysql_query($query)) { if(mail($to, $subject, $message, $headers) { $url_success = "confirmation.php"; echo("<meta http-equiv = refresh content=0;url=".$url_success.">"); } else { echo 'Mail failed!'; } } else { echo 'Database insert failed!'; } }
-
How did it "not work" for you?
-
<?php $str = '"<name>":<value>,"ID":20251,"ID2":2300,"ID3":2000'; $str = str_replace('"','',$str); $ex = explode(',',$str); //break str down by comma's. foreach($ex as $part) { //cycle through the comma's. $exp = explode(':',$part); //break each part down by colon. $arr[$exp[0]] = $exp[1]; //assign the section before the colon to the key, and the section after the colon to the value. } echo '<pre>'; print_r($arr); echo '</pre>'; //show the results. ?>
-
Make a simple file in the directory of the file you wish to get the size of, and call it from the browser. test.php <?php echo __FILE__; ?> Then copy that as the file path. Of course, change the filename at the end to the correct filename. This is the easiest method that I can think of, that will give YOU the filepath of your file. Otherwise, you could try all day with suggestions. Documentation
-
Problem with Livesearch tutorial at w3schools
jcbones replied to lilianev's topic in PHP Coding Help
Something tells me this isn't 100%, but you could tweak it from here (or post the exact problem you are getting, and we can help further). BTW, one of the best descriptions ever posted by a newbie. <?php $xmlDoc=new DOMDocument("1.0"); //"genxml-buildings-depts-050411.xml" $xmlDoc->load('http://pr107m.psur.utk.edu/~lilia/campusmap/genxml-buildings-depts-050411.xml'); $x=$xmlDoc->getElementsByTagName('locators'); //get the q parameter from URL $q= (isset($_GET['q'])) ? $_GET['q'] : NULL; //lookup all links from the xml file if length of q>0 if (!empty($q)) { $hint=""; for($i=0; $i<($x->length);$i++) { $y=$x->item($i)->getElementsByTagName('building'); for($n = 0; $n < ($y->length); $n++) { $z=$x->item($i)->getElementsByTagName('department'); for($num = 0; $num < ($z->length); $num++) { if ($p = $y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item($n)->nodeValue,$q) || stristr($z->item($num)->nodeValue,$q) ) { if ($hint=" ") { $hint = "<a href='#' target='_blank'>" . $z->item($num)->nodeValue . "</a> — ". $y->item($i)->nodeValue ."<br>"; if (stristr($y->item($n)->nodeValue,$q) ) { $hint .= "<a href='#' target='_blank'>" . $y->item($n)->nodeValue . "</a>"; } } else { $hint .= "<br /><a href='#' target='_blank'>" . $z->item(0)->nodeValue . "</a><br><a href='#' target='_blank'>" . $y->item(0)->nodeValue . "</a>"; } } } } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if (empty($hint)) { $response="no suggestion"; } else { $response=$hint; } //output the response echo $response; ?> -
In theory, your idea should work. I would try it, but first I would backup my database table -> FULLY!!! AS for better protection, well, you will get different answers on that on. Some say md5 is enough, some say sha1 is enough, others say not to mix the two. I say, if it works, and adds a little more buffer zone, then go for it.
-
I would tell you to use a class like SimpleImage.
-
You should use a datetime data type, and not just a date. A date data type will not have time associated with it.
-
You would set the field as a `timestamp` and populate it with ADDTIME(NOW(),'04:10:00'). INSERT INTO table(timestamp) VALUES (ADDTIME(NOW(),'04:10:00')); And retrieve by: SELECT * FROM table WHERE timestamp > NOW();
-
Passing Javascript Output in PHP Variable
jcbones replied to natasha_thomas's topic in PHP Coding Help
<?php $amacontent = file_get_contents('http://minimate.co.uk/master/scripts/content/amazonsearch.php?kw=noprodcamera&cat=Electronics'); if (strpos($amacontent, "No results for") === false) //if the string "No results for" IS NOT FOUND in $amacontent, then echo "Products found!". This line should read "if (strpos($amacontent, "No results for") !== false)" { echo "Products found!"; } else { echo "sorry no products found"; } echo $amacontent; ?> -
I believe that should be: echo "<p>" . $_SERVER['SERVER_NAME'] . "/" . strtolower(stripslashes(str_replace(" ","-",$row['name']))) .".php</p>";
-
using a new connection inside the function of a function
jcbones replied to violinrocker's topic in PHP Coding Help
Just copy the table over to your `main` database. -
Yes, the images will be DN'ld if the display is set to none. My preferred way for this to work is using AJAX to call the images as you need them. So, if you just used thumbnails on the page, and then on the mouseover (hover) you would download the full image and show it. Or, you could use something like lightbox.
-
You can format the date anyway you like, that is why I gave you an example, and then posted a link to the manual. The manual has listings that will give you any result you desire.
-
SELECT DATE_FORMAT(`timestamp`,'%W %M %Y') FROM `table`; MySQL date time functions
-
Try this: <?php session_start(); //start session. $sessionID = session_id(); if(isset($_GET['reset']) && $_GET['reset'] == 1) { //if you click the play again button, reset the session variables. unset($_SESSION['left']); unset($_SESSION['colors']); } $_SESSION['left'] = (isset($_SESSION['left'])) ? $_SESSION['left'] : 7; //if session left exists, use it, if not, then create it. if(!isset($_SESSION['colors'])) { //if session colors doesn't exists, make it an array. $_SESSION['colors'] = array(); } ?> <html> <head> <title>Rainbow</title> </head> <body> Do you know all the colors in the rainbow?<br /><br /> <form name="input" action="" method="POST"> Color: <input type="text" name="color" value="" /> <input type="submit" value="Guess!" name ="guess"/> </form> <?php // the goal of the game is to have a user enter a color in the form, // when it detects one of the correct 7 colors, it subtracts from // $_SESSION['left'], when $_SESSION['left'] = 0, the user wins if(isset($_POST['color'])) { //if form is submitted. $rainbowcolors = array ("red", "orange", "yellow", "green", "blue", "indigo", "violet"); if(!in_array($_POST['color'],$_SESSION['colors'])) { //if the color doesn't match the a color in the used colors array. $_SESSION['colors'][] = $_POST['color']; //add the color to the used colors array. if (in_array($_POST['color'],$rainbowcolors)) { //if the color exist in the rainbow array, then it is correct, subtract the session left variable.. $_SESSION['left']--; // correct guess! } else //if the color doesn't exist in the rainbow array, set a wrong answer variable. { $wrong = "Your guess '{$_POST['color']}' was wrong, try again."; } } else { //if the color exists in the used color array, set a wrong answer variable. $wrong = 'You have already guessed \''. $_POST['color'] . '\', try again.'; } // when the amount of remaining colors reaches 0, end the game if ($_SESSION['left'] == 0){ echo "Congratultions, you got them all! <br /><br />"; echo '<a href="?reset=1">Play again?</a>'; } else { echo "You have " . $_SESSION['left'] . " colors left to guess<br /><br />"; } if(isset($wrong)) { echo $wrong; } //if the wrong answer variable is set, print it to the screen. ?> <br /><br /> <?php // array info for debugging echo '<pre>'; print_r($_SESSION); echo '</pre>'; echo "<br /><br />Session ID: " . $sessionID; } ?> </body> </html>
-
Try: <?php session_start(); $sessionID = session_id(); $_SESSION['left'] = (isset($_SESSION['left'])) ? $_SESSION['left'] : 7; ?> <html> <head> <title>Rainbow</title> </head> <body> Do you know all the colors in the rainbow?<br /><br /> <form name="input" action="rainbow.php" method="POST"> Color: <input type="text" name="color" value="" /> <input type="submit" value="Guess!" name ="guess"/> </form> <?php // the goal of the game is to have a user enter a color in the form, // when it detects one of the correct 7 colors, it subtracts from // $_SESSION['left'], when $_SESSION['left'] = 0, the user wins if(isset($_POST['color'])) { $rainbowcolors = array ("red", "orange", "yellow", "green", "blue", "indigo", "violet"); if (in_array($_POST['color'],$rainbowcolors)) { $_SESSION['left']--; // correct guess! } else { $wrong = "Your guess '{$_POST['color']}' was wrong, try again."; } // when the amount of remaining colors reaches 0, end the game if ($_SESSION['left'] == 0){ echo "Congratultions, you got them all! <br /><br />"; echo '<a href="rainbow.php">Play again?</a>'; } else { echo "You have " . $_SESSION['left'] . " colors left to guess<br /><br />"; } if(isset($wrong)) { echo $wrong; } ?> <br /><br /> <?php // array info for debugging '<pre>'; print_r($_SESSION); echo '</pre>'; echo "<br /><br />Session ID: " . $sessionID; } ?> </body> </html> Let us know how it goes!
-
All of your problems could be solved much quicker, if you posted the actual code that you are working with. Your explanations are confusing, and you will not get desired info from the responses. FACTS: PHP is a server side programming language. Javascript is a client side programming language. HTML is a markup language that is interpreted by your browser. PHP can write HTML. Javascript can write HTML. Programming languages cannot interact with each other, they speak different languages, therefore they don't understand each other. Therefore: PHP cannot call Javascript, it can only write it to the browser. Javascript cannot call PHP, it can only send a request to the server. In the middle of that mix, is where you use AJAX (Asynchronous Javascript And XML), to send a request to the server (via javascript), to a php script, and print the returned value (from the php script) back to the HTML page (via javascript).
-
I need some help with this script, can't seem to find the problem.
jcbones replied to vet911's topic in PHP Coding Help
May help.