-
Posts
9,409 -
Joined
-
Last visited
-
Days Won
1
Everything posted by MadTechie
-
file — Reads entire file into an array example <?php $lines = file('ftp://tgftp.nws.noaa.gov/data/observations/metar/decoded/KOJC.TXT'); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; } ?>
-
[SOLVED] Simple Mail Form-Need to break apart message
MadTechie replied to Boaz's topic in PHP Coding Help
updated.. this should work <?php $parts=str_split($Message,160); $count = count($parts); foreach($parts as $K=>$part) { if(!empty($part)) { $Body = "$part"; // send email $PSubject = $Subject." (".($K+1)." of $count)"; $success = mail($EmailTo, $PSubject, $Body, "From: <$EmailFrom>"); sleep(1); //wait 1 second } } ?> -
Help with PHP and data from myslq database
MadTechie replied to fernando68's topic in PHP Coding Help
change $result1 = mysql_query($qur1,$link); to $result1 = mysql_query($qur1,$link) or die("ERROR: $qur1".mysql_error()); it won't fix it but will tell you the problem.. post the results back here if your still not sure -
[SOLVED] Simple Mail Form-Need to break apart message
MadTechie replied to Boaz's topic in PHP Coding Help
Sorry replace the regex with $parts=str_split($Message,160); ie (its quicker) <?php $parts=str_split($Message,160); foreach($parts as $part) { if(!empty($part)) { $Body = "$part"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); } } ?> -
[SOLVED] Simple Mail Form-Need to break apart message
MadTechie replied to Boaz's topic in PHP Coding Help
Try this <?php preg_match_all('/.{0,160}/sim', $Message, $parts); $parts = $parts[0]; foreach($parts as $part) { if(!empty($part)) { $Body = "$part"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); } } ?> -
Due to a few PM's asking for a third box or example for the SQL side i have decided to update the script, i have tried to keep it simple.. i have include the SQL table structure and some sample data.. i hope it helps <?php /* -- SQL Data -- -- Table structure for table `list1` -- CREATE TABLE `list1` ( `ID` mediumint( NOT NULL auto_increment, `Name` varchar(15) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `list1` -- INSERT INTO `list1` (`ID`, `Name`) VALUES (1, 'Dogs'), (2, 'Trees'), (3, 'Apples'); -- -------------------------------------------------------- -- -- Table structure for table `list2` -- CREATE TABLE `list2` ( `ID` mediumint( NOT NULL auto_increment, `List1Ref` mediumint( NOT NULL, `Name` varchar(20) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; -- -- Dumping data for table `list2` -- INSERT INTO `list2` (`ID`, `List1Ref`, `Name`) VALUES (1, 1, 'Sleep in'), (2, 1, 'Bark at'), (3, 2, 'Grow'), (4, 2, 'Are'), (5, 3, 'are coloured'), (6, 3, 'Taste'); -- -------------------------------------------------------- -- -- Table structure for table `list3` -- CREATE TABLE `list3` ( `ID` mediumint( NOT NULL auto_increment, `List2Ref` mediumint( NOT NULL, `Name` varchar(20) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; -- -- Dumping data for table `list3` -- INSERT INTO `list3` (`ID`, `List2Ref`, `Name`) VALUES (1, 1, 'Baskets'), (2, 1, 'on the couch'), (3, 2, 'Cats'), (4, 2, 'Postmen'), (5, 3, 'slowly'), (6, 4, 'green'), (7, 5, 'Red'), (8, 5, 'Green'), (9, 6, 'Nice'), (10, 6, 'Not nice'); */ $hostname = "localhost"; $username = "root"; $password = ""; ?> <?php $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("ajax_test",$dbh); if( isset($_POST['Submit']) ) { echo "<pre>"; print_r($_POST); } if( isset($_GET['ajax']) ) { //In this if statement switch($_GET['ID']) { case "LBox2": $query = sprintf("SELECT * FROM list2 WHERE List1Ref=%d",$_GET['ajax']); break; case "LBox3": $query = sprintf("SELECT * FROM list3 WHERE List2Ref=%d",$_GET['ajax']); break; } $result = mysql_query($query); echo "<option value=''></option>"; while ($row = mysql_fetch_assoc($result)) { echo "<option value='{$row['ID']}'>{$row['Name']}</option>\n"; } mysql_close($dbh); exit; //we're finished so exit.. } if (!$result = mysql_query("SELECT * FROM list1")) { echo "Database is down"; } //for use with my FIRST list box $List1 = ""; while ($row = mysql_fetch_assoc($result)) { $List1 .= "<option value='{$row['ID']}'>{$row['Name']}</option>\n"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Simple Dymanic Drop Down</title> <script language="javascript"> function ajaxFunction(ID, Param) { //link to the PHP file your getting the data from //var loaderphp = "register.php"; //i have link to this file var loaderphp = "<?php echo $_SERVER['PHP_SELF'] ?>"; //we don't need to change anymore of this script var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch(e){ // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { //the line below reset the third list box incase list 1 is changed document.getElementById('LBox3').innerHTML = "<option value=''></option>"; //THIS SET THE DAT FROM THE PHP TO THE HTML document.getElementById(ID).innerHTML = xmlHttp.responseText; } } xmlHttp.open("GET", loaderphp+"?ID="+ID+"&ajax="+Param,true); xmlHttp.send(null); } </script> </head> <body> <!-- OK a basic form--> <form method="post" enctype="multipart/form-data" name="myForm" target="_self"> <table border="0"> <tr> <td> <!-- OK here we call the ajaxFuntion LBox2 refers to where the returned date will go and the this.value will be the value of the select option --> <select name="list1" id="LBox1" onchange="ajaxFunction('LBox2', this.value);"> <option value=''></option> <?php echo $List1; ?> </select> </td> <td> <select name="list2" id="LBox2" onchange="ajaxFunction('LBox3', this.value);"> <option value=''></option> <!-- OK the ID of this list box is LBox2 as refered to above --> </select> </td> <td> <select name="list3" id="LBox3"> <option value=''></option> <!-- OK the ID of this list box is LBox3 Same as above --> </select> </td> </tr> </table> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html> Same as above without MySQL <?php if( isset($_GET['ajax']) ) { //In this if statement switch($_GET['ID']) { case "LBox2": $Data[1] = array(10=>"-Tom", 20=>"Jimmy"); $Data[2] = array(30=>"Bob", 40=>"-MadTechie"); $Data[3] = array(50=>"-One", 60=>"Two"); break; //Only added values for -Tom, -MadTechie and -One (10,40,50) case "LBox3": $Data[10] = array(100=>"One 00", 200=>"Two 00"); $Data[40] = array(300=>"Three 00"); $Data[50] = array(1000=>"10000"); break; } echo "<option value=''></option>"; foreach($Data[$_GET['ajax']] as $K => $V) { echo "<option value='$K'>$V</option>\n"; } mysql_close($dbh); exit; //we're finished so exit.. } $Data = array(1=>"One", 2=>"Two", 3=>"Three"); $List1 = "<option value=''></option>"; foreach($Data as $K => $V) { $List1 .= "<option value='$K'>$V</option>\n"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Simple Dymanic Drop Down</title> <script language="javascript"> function ajaxFunction(ID, Param) { //link to the PHP file your getting the data from //var loaderphp = "register.php"; //i have link to this file var loaderphp = "<?php echo $_SERVER['PHP_SELF'] ?>"; //we don't need to change anymore of this script var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch(e){ // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { //the line below reset the third list box incase list 1 is changed document.getElementById('LBox3').innerHTML = "<option value=''></option>"; //THIS SET THE DAT FROM THE PHP TO THE HTML document.getElementById(ID).innerHTML = xmlHttp.responseText; } } xmlHttp.open("GET", loaderphp+"?ID="+ID+"&ajax="+Param,true); xmlHttp.send(null); } </script> </head> <body> <!-- OK a basic form--> <form method="post" enctype="multipart/form-data" name="myForm" target="_self"> <table border="0"> <tr> <td> <!-- OK here we call the ajaxFuntion LBox2 refers to where the returned date will go and the this.value will be the value of the select option --> <select name="list1" id="LBox1" onchange="ajaxFunction('LBox2', this.value);"> <?php echo $List1; ?> </select> </td> <td> <select name="list2" id="LBox2" onchange="ajaxFunction('LBox3', this.value);"> <option value=''></option> <!-- OK the ID of this list box is LBox2 as refered to above --> </select> </td> <td> <select name="list3" id="LBox3"> <option value=''></option> <!-- OK the ID of this list box is LBox3 Same as above --> </select> </td> </tr> </table> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html>
-
[SOLVED] extracting specific elements from array
MadTechie replied to rndilger's topic in PHP Coding Help
try this <?php $field_names = array(); $cols = mysql_query("SHOW COLUMNS FROM `map`"); while($fields = mysql_fetch_assoc($cols)) { $f = $fields['Field']; if(substr(0,4) == "mem_") { $field_names[] = $f; } } echo"<pre>";print_r($field_names); -
could you post the code that gives that message! it may even be a javascipt!
-
[SOLVED] Searching for multiple values in an array
MadTechie replied to unrelenting's topic in PHP Coding Help
<?php $colors = array("red", "green", "blue", "orange", "purple", "yellow"); $find = array("red", "orange", "yellow"); $found = count($find); //3 foreach($find as $f) { if(in_array($f, $colors)) { found--; } } if(found==0) echo "Found all"; ?> -
Your right their is an error Update to $insertpost = "INSERT INTO posts_grp (`grpid`, `grpname`, `userid`, `username`, `grppost`,` month`, `day`, `year`) VALUES ('$groupid', '$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')";
-
[SOLVED] MySQL Update problem ( checkbox values )
MadTechie replied to plodos's topic in PHP Coding Help
LOL Opps, But i think you got the idea.. if not try this <?php $delete = "DELETE FROM reviewer_research_field WHERE user='{$_SESSION['id']}' "; mysql_query($delete) or die(mysql_error()); foreach($_POST['state'] as $newstate) { #$write = "update reviewer_research_field as r set r.id='{$newstate}' where r.user='{$_SESSION['id']}' "; #mysql_query($write) or die(mysql_error()); $insert = "INSERT INTO reviewer_research_field (`id` ,`user`) VALUES ('{$newstate}' , '{$_SESSION['id']}');"; mysql_query($insert) or die(mysql_error()); } ?> -
[SOLVED] MySQL Update problem ( checkbox values )
MadTechie replied to plodos's topic in PHP Coding Help
Well the problem is simple.. lets review whats happening $write = "update reviewer_research_field as r set r.id='{$newstate}' where r.user='{$_SESSION['id']}' "; the line above repeats 3 times as follows update reviewer_research_field as r set r.id='5' where r.user='22' update reviewer_research_field as r set r.id='8' where r.user='22' update reviewer_research_field as r set r.id='9' where r.user='22' Each affect 3 records, thus the last one updates all 3 to the last value (9) How so solve this, well the easy way is to do this <?php foreach($_POST['state'] as $newstate) { $delete = "DELETE FROM reviewer_research_field WHERE user='{$_SESSION['id']}' "; mysql_query($delete) or die(mysql_error()); #$write = "update reviewer_research_field as r set r.id='{$newstate}' where r.user='{$_SESSION['id']}' "; #mysql_query($write) or die(mysql_error()); $insert = "INSERT INTO reviewer_research_field (`id` ,`user`) VALUES ('{$newstate}' , '{$_SESSION['id']}');"; mysql_query($insert) or die(mysql_error()); } ?> -
[SOLVED] mysql query select order by alpabets??
MadTechie replied to yami007's topic in PHP Coding Help
Sorry for late reply Mark Baker is correct if you used "SELECT name FROM singers ORDER BY name" the code should of worked i didn't know the field names being used and i don't really test the code i just enter it directly.. anywho glade you got it sorted -
Little problem in encrypting passwords (PHP and SQL)
MadTechie replied to Twister1004's topic in PHP Coding Help
Humm the SHA should be 5e5cedf57e5cf4ed008bee8f095a0fc24b0f1c58 Lets try this <?php $PreHASH = strtoupper($username)."$password"; echo "TESTING:"; echo sha1($PreHASH); $sql = mysql_query("INSERT INTO `passwords` (`name`, `password`) VALUES (UPPER('$username'), SHA1('$PreHASH') ") or die("Error in the encryption! " . mysql_error()); /* $sql = mysql_query("INSERT INTO `passwords` (`name`, `password`) VALUES (UPPER('$username'), 'SHA1(CONCAT(UPPER('$username') , ('$password')))') ") or die("Error in the encryption! " . mysql_error()); */ ?> Okay.. bad recommendation But to be trueful its a only little more secure but its also a little slower, SHA and MD5 are very old and lets face it.. the someone gains access to the HASH no matter which one you pick, it won't matter lol.. ROFL @ redarrow's $password=md5(sha1(md5($_POST['password']))); //encoded. Surelly you know that will cause more collisions, encrypting a 160bit password with 128bit password is a bad idea! -
Little problem in encrypting passwords (PHP and SQL)
MadTechie replied to Twister1004's topic in PHP Coding Help
$sql = mysql_query("INSERT INTO `passwords` (`name`, `password`) VALUES (UPPER('".$username."'), SHA1(CONCAT(UPPER('".$username."') , ('".$password."')))") or die("Error in the encryption! " . mysql_error()); should be $sql = mysql_query("INSERT INTO `passwords` (`name`, `password`) VALUES (UPPER('$username'), 'SHA1(CONCAT(UPPER('$username') , ('$password')))') ") or die("Error in the encryption! " . mysql_error()) ; But i would recommend using MD5 ie $sql = mysql_query("INSERT INTO `passwords` (`name`, `password`) VALUES (UPPER('$username'), md5('$password')")) or die("Error in the encryption! " . mysql_error()); -
Using cookies works well <script type="text/javascript"> var myDate = new Date(); var myTime = myDate.toLocaleTimeString(); myDate.setDate(myDate.getDate()+1); setCookie('UserTime',myTime); function setCookie(c_name,value,expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); } </script> <?php list($hours, $minutes, $seconds) = explode(":",$_COOKIE['UserTime']); echo "Its $hours:$minutes:$seconds"; $time = ($hours < 12)?'morning'($hours < 17)?'afternoon':'evening'); echo $time; ?>
-
Finding text three characters before chosen string
MadTechie replied to eits's topic in PHP Coding Help
for 1 or 2 digits it should be <?php $html = "testing some test 12<beforethis>" if (preg_match('/(\d{1,2})<beforethis>/sim', $html , $regs)) { echo "found: ".$regs[1]; } ?> but DarkWater will grab ALL digits.. it depends how exact you want to be, i would probably use DarkWater's -
Lost connection to MySQL server during query
MadTechie replied to mariocesar's topic in PHP Coding Help
Your need to check with your New Host,, check theirs FAQ's -
[SOLVED] mysql query select order by alpabets??
MadTechie replied to yami007's topic in PHP Coding Help
Okay and whats the problem ? its basically a while loop check first char is its diffrent then echo the new one quick draft untested example $letter = ""; while($row = mysql_fetch_array($result)) { $fletter = substr($row['0'],0, 1); if($letter != $fletter) { $letter = $fletter; echo "$letter<br>"; } echo $row['0']."<br>"; } the rest is basically CSS/HTML -
Not sure what to say.. Okay your need to read the values in before you can use them.. if you just want int_1 v_255_9v_255_10 then set that ie $vehicles_oodle["title1"]="int_1 v_255_9v_255_10"; if your reading them in then concat them after reading them in ie $vehicles_oodle["title1"]=$veh["int_1"].$veh["v_255_9"].$veh["v_255_10"]; who wrote the code ?
-
[SOLVED] mysql query select order by alpabets??
MadTechie replied to yami007's topic in PHP Coding Help
Append "ORDER BY field name ASC" to the SQL statment -
Topic Solved button is bottom left (i think)
-
Opps missed "Location: " try this <?php $URL = $_GET['url']; $allowed_url = array("google.com","yahoo.com"); if(in_array($URL,$allowed_url)) { header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en"); }else{ header("Location: http://www.google.com/"); } ?>
-
Can you try this and post any errors your getting.. Note i added a space before the AND this should also tell us what ID is set to an $i <?php $where = $_POST['where']; $ID = mysql_result($result_getAccountID, $i, "account_id"); $query_getAccount="SELECT name, address FROM accounts WHERE id =$ID AND postalcode=$where"; $result_getAccount= mysql_query($query_getAccount) or die($query_getAccount." I = $i<br> ".mysql_error()); ?>