-
Posts
9,409 -
Joined
-
Last visited
-
Days Won
1
Everything posted by MadTechie
-
Using multiple select boxes.......but problem in ajax code
MadTechie replied to gagan22's topic in Javascript Help
okay i have broken down your code and re-written it, a little this runs from 1 file, let me know if theirs any part you don't understand <?php if(!empty($_GET['country'])) { $country=intval($_GET['country']); $link = mysql_connect('localhost', 'root', ''); //changet the configuration in required if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('db_ajax'); if(!empty($_GET['state'])) { $state = intval($_GET['state']); echo "<option>Select City</option>"; $query="SELECT id,statename FROM city WHERE countryid='$country' AND stateid='$state'"; }else{ echo "<option>Select State </option>"; $query="SELECT id,statename FROM state WHERE countryid='$country'"; } $result = mysql_query($query,$link) or die('Query failed. ' . mysql_error()); while($row=mysql_fetch_array($result,MYSQL_BOTH)) { echo "<option value=\"{$row['id']}\">{$row['statename']}</option>"; } exit; }else{ $country = 0; } ?> <html> <head> <title>Roshan's Triple Ajax dropdown code</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="javascript" type="text/javascript"> function getXMLHTTP(){ //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); }catch(e){ try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e1){ xmlhttp=false; } } } return xmlhttp; } var country; function getState(countryId) { var strURL="?country="+countryId; var req = getXMLHTTP(); country = countryId; if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('state').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } function getCity(stateId) { var strURL="?country="+country+"&state="+stateId; var req = getXMLHTTP(); alert(strURL); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('city').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body> <form method="post" action="" name="form1"> <table width="60%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="150">Country</td> <td width="150"> <select name="country" onChange="getState(this.value)"> <option value="">Select Country</option> <option value="1">USA</option> <option value="2">Canada</option> </select> </td> </tr> <tr style=""> <td>State</td> <td > <select id="state" name="state" onChange="getCity(this.value)"> <option>Select Country First</option> </select> </td> </tr> <tr style=""> <td>City</td> <td > <select id="city" name="city"> <option>Select State First</option> </select> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form> </body> </html> -
Last_access should be `last_access` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP then you should let SQL update it, don't update from PHP time, when the record is created or updated the time will change the following code will change the status to 1 or 0 if(UNIX_TIMESTAMP(last_access)+(60*15) > NOW(),1,0) if(contition,true,false) so if UNIX_TIMESTAMP(last_access)+(60*15) > NOW() is true return 1 else return 0
-
see here http://www.phpfreaks.com/forums/index.php/topic,37442.0.html
-
do you want javascript validation or php validation ?
-
[SOLVED] how do i fwrite a user profile AKA an entire php page?
MadTechie replied to emopoops's topic in PHP Coding Help
you would use fwrite($fp, '<strong>Hello</strong> MadTechie'); just as you would do echo '<strong>Hello</strong> MadTechie'; But thats not how myspace do it, or any "good" websites do it the data is held in a database and the page is built dynamically, ie <?php //connect to DB etc $SQL = sprintf("SELECT * FROM users WHERE user='%s' LIMIT 1",mysql_real_escape_string($_GET['user'])); $query = mysql_query($SQL) or die(mysql_error()); $user = mysql_fetch_array($query); echo "<strong>Hello</strong> ".$user['UserName']; ?> then use an apache rewrite to redirect /profile/MadTechie to profile.php?user=MadTechie -
Run PHP Script at specified time (HH:MM:SS)
MadTechie replied to milosh012's topic in PHP Coding Help
As your new to PHP and cron is technically a unix function, i thouight i'll give you some php to solved it this script will run for 1 hour and allow you set any condition you like that gets checked every second, so you could run it every hour on the hour via cron jobs <?php set_time_limit(0); $endtime = time()+(1*60*60); while(time()<$endtime) { /* if(condition) //time etc { do something } */ sleep(1); } ?> -
Depends what you mean "php based" can you create a cron job that runs a php script every hour and that script have 10 seconds intervals of sleep
-
What do the error logs say ? for that matter whats echo $last_line; say
-
well sorry to say this but <?php $url="http://www.ipingus.com/myFactors.php"; header("Location: $url"); ?> works fine!
-
got it, ID 13 works fine, you got some other id's i can test, (jpegs, or even the link to upload)
-
thats because the value is still in the database, you could update the if statement to check both, if(empty($row['logo_image']) || !file_exists("admin/venues/files/{$row['logo_image']}")) { echo "<img src='admin/venues/files/noimage.gif'>"; // no image }else{ echo "<img src='admin/venues/files/{$row['logo_image']}'>"; // found image }
-
if you send me a link (PM if you want) i'll take a look at the outputs
-
lol i'm a dumbarse if(function urlExists('www.google.co.uk')) { echo "worked"; } should be if(urlExists('www.google.co.uk')) { echo "worked"; }
-
to do have this on a live server ? Well it really does depends, but yeah by defaut i would go for file and folder, but their have been cases where a database blob was better.
-
[SOLVED] Need some help passing info from FORM to Database
MadTechie replied to Mike Smith's topic in PHP Coding Help
Well heres mine version, <?php #include('header.php'); ?> <div class="contentwide"> <div class="contentwrap"> <form method="post" action="voted.php"> <?php $query = "SELECT id, name, url FROM photos ORDER BY RAND() LIMIT 3"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { ?> <div class="picturewrap"> <img src="<?php echo $row['url']; ?>" alt="<?php echo $row['name']; ?>" /> <div class="formwrapper"> <input type="radio" name="images[<?php echo $row['id']; ?>]" value="spoon"> </div> <div class="formwrapper"> <input type="radio" name="images[<?php echo $row['id']; ?>]" value="fork"> </div> <div class="formwrapper"> <input type="radio" name="images[<?php echo $row['id']; ?>]" value="knife"> </div> </div> <?php } ?> <div class="submitform"> <input type="image" src="images/button_submit.jpg" class="button_submit" value="Submit"><br/ > </div> </form> </div> </div> <?php mysql_close($link); ?> <?php #include('footer.php'); ?> <?php // Connects to your Database $link = mysql_connect('localhost', '', ''); mysql_select_db("") or die(mysql_error()); ?> <?php $IDS = implode(",",array_keys($_POST['images'])); //security filters $IDS = preg_replace('/[^,\d]/s', '', $IDS); $valid = array("spoon","knife","fork"); $query = "SELECT id FROM photos WHERE ID IN ($IDS)"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $images = mysql_real_escape_string($_POST['images'][$row['id']]); if(!in_array($images,$valid)) die("ERROR"); $update = sprintf("UPDATE photos SET {$images}={$images}+1 WHERE id=%d LIMIT 1",$row['id']); mysql_query($update) or die(mysql_error()); } ?> -
Sure, please note the last code i account for that, (note the last if statement) for the other code a function would probably work best ie <?php if(function urlExists('www.google.co.uk')) { echo "worked"; } function urlExists($url) { $handle = fopen($url, "r"); if($handle) { $contents = fread($handle, 10); fclose($handle); if (preg_match('/^<?xml/s', $contents)) { return true; } } return false; } ?>
-
flush and ob_flush() basically dump all the last echos to apache to output to the browser,, if you run the code, without them, then run it again with them, your notice that without them it delays for a second or 2 and them dumps everything to screen, while with them it dumps them part at a time.. hope that makes sense,
-
Try this <?php $curl = curl_init(); $url = 'http://www.idontexist.co.uk'; //No domain $url = 'http://www.google.co.uk'; //no RSS $url = 'http://www.telegraph.co.uk/news/uknews/rss'; //valid $valid = false; curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl,CURLOPT_TIMEOUT, 5); curl_setopt($curl, CURLOPT_HEADER, TRUE); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, FALSE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($curl); $header = curl_getinfo($curl); if ($header['http_code']=='200') { //echo "Found page<br>\n"; if(stripos($header['content_type'],'text/xml')!==false) { //echo "Valid XML"; $valid = true; } } curl_close($curl); if($valid) { //Blar echo "$url will work"; } ?>?> i have added 3 urls, for an example Note the timeout is set to 5 seconds, if the server is slow then it may fail which a short timeout like that
-
Okay i'm not sure but are you trying to do something like this <?php $racerArray = array( array("Name" => "Errant", "damage" => 0, "cheat" => false), array("Name" => "Shadow", "damage" => 0, "cheat" => false), array("Name" => "MadTechie", "damage" => 0, "cheat" => true) ); $stillraceing = true; ob_start(); while($stillraceing) { foreach($racerArray as $RacerKey => $Racer) { $stillraceing = (count($racerArray) > 1); //race until last person if(!$stillraceing) break; //take damage $damage = (rand(1,10) * rand(1,10)); $racerArray[$RacerKey]['damage'] = ((!$Racer['cheat']))?$Racer['damage'] + $damage:$Racer['damage']; echo $Racer['Name']." Take $damage damage, ".(100-$racerArray[$RacerKey]['damage'])." Remaining<br>\n"; //remove them if($racerArray[$RacerKey]['damage'] >= 100) { echo $Racer['Name']." is out of the race<br>\n"; unset($racerArray[$RacerKey]); } flush(); ob_flush(); } } $winner = current($racerArray); echo $winner['Name']." Wins"; ?> PS: i always win EDIT: updated the damage message
-
Sighs! okay well the fix is if(empty($row['logo_image'])) { echo "<img src='admin/venues/files/noimage.gif'>"; // no image }else{ echo "<img src='admin/venues/files/{$row['logo_image']}'>"; // found image } thats how you display the image a default image if the value in the database is empty the red cross means it can't find the image, (double check the path and the image name)
-
Yes that would be fine $handle = fopen($url, "r"); if($handle) { $contents = fread($handle, 10); fclose($handle); if (preg_match('/^<\?xml/s', $contents)) { echo "valid"; } } EDIT: as a note i this will only read 10 bytes this is fine for checking its XML (infact 5 is okay) but not for checking its RSS