-
Posts
9,409 -
Joined
-
Last visited
-
Days Won
1
Everything posted by MadTechie
-
Do you mean something likes this <form method="post" enctype="multipart/form-data"> <p>Pictures: <input type="file" name="pictures" /> <input type="text" name="Name" /> <input type="submit" value="Send" /> </p> </form> <?php if(isset($_POST['submit'])) { echo $_POST['Name']; //Create a folder called upload with write access $dir = dirname(__FILE__)."\upload"; $tmp_name = $_FILES["pictures"]["tmp_name"]; $name = $_FILES["pictures"]["name"]; move_uploaded_file($tmp_name, "$dir/$name"); } ?>
-
example of MySQL usage (from the manual) <?php $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result); ?>
-
MD5 is oneway if i MD5('HELLO') i would get 32 chars something like this A67864DF64C3268.. etc now you don't need decrypt this to check if the password is correct what you do is get the user input and MD5 it.. so HELLO will always appear as A67864DF64C3268.. etc and as that is stored in the database it will compare correctly but HellO will have a different MD5 result thus will be invalid.. inshort you can't decrypt it.. NOTE: to anyone whos going to say it can be: their a ton of post about decrypting it, which all point to the true fact it can NOT be decrypted.. so please don't turn this post into a bruteforce / rainbow table post (again!) Side note: your password it stored like this $passwords = strrev(md5(md5(strrev(md5("$getscores3[password]"))))); this isn't the best way of doing it, you should use salt but we will save that for another post i guess..
-
<?php $file = 'http://www.urmob.co.uk/feed/single.php?partner=mpdu&selection=A&cashback=A&fields=Offer.ID-Offer.PhoneCost-Offer.TotalCost-Offer.MonthlyCost-Offer.FreeGift-Offer.OfferCashback-Offer.AutoCashback-Offer.OfferRental-Offer.OfferLength-Offer.Link-Model.ID-Model.Make-Model.Name-Model.ImageLarge-Model.ImageSmall-Model.Popularity-Tariff.Name-Tariff.ContractLength-Tariff.Rental-Tariff.NiceName-Tariff.FreeMins-Tariff.FreeMinsType-Tariff.FreeTxts-Tariff.Allowance-Tariff.CostLLP-Tariff.CostLLO-Tariff.CostSNP-Tariff.CostSNO-Tariff.CostONP-Tariff.CostONO-Tariff.CostVMP-Tariff.CostVMO-Tariff.CostSMS-Tariff.CostMMS-Network.Name-Network.Image-Merchant.Name-Merchant.Image-Deal.Popularity&track=URMOB-xmake-xmodelx-xtariffx'; //file name here //we read the CSV file here $lines = file($file); //now we take each line and explode it then insert to DB foreach ($lines as $line) { $line = addcslashes($line, "'"); //Add this to clean up quotes $cols = explode('"', trim($line)); mysql_query("INSERT INTO deals (ID, PhoneCost, TotalCost, MonthlyCost, FreeGift, OfferCashback, AutoCashback, OfferRental, OfferLength, OfferLink, ModelID, MakeName, ModelName, ImageLarge, ImageSmall, ModelPop, TariffName, ContractLength, TariffRental, NiceName, FreeMins, FreeMinsType, FreeTxts, Allowance, LLP, LLO, SNP, SNO, ONP, ONO, VMP, VMO, SMS, MMS, NetworkName, NetworkImage, MerchantName, MerchantImage, DealPop) VALUES ('$cols[1]', '$cols[3]', '$cols[5]', '$cols[7]', '$cols[9]', '$cols[11]', '$cols[13]', '$cols[15]', '$cols[17]', '$cols[19]', '$cols[21]', '$cols[23]', '$cols[25]', '$cols[27]', '$cols[29]', '$cols[31]', '$cols[33]', '$cols[35]', '$cols[37]', '$cols[39]', '$cols[41]', '$cols[43]', '$cols[45]', '$cols[47]', '$cols[49]', '$cols[51]', '$cols[53]', '$cols[55]', '$cols[57]', '$cols[59]', '$cols[61]', '$cols[63]', '$cols[65]', '$cols[67]', '$cols[69]', $cols[71]', '$cols[73]', '$cols[75]', '$cols[77]')")or die(mysql_error()); } ?> Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) means out of memory maybe try increasing the memory ie ini_set("memory_limit","32M");
-
Sounds like you just need to use the same database settings for all (except localhost being the master site, maybe add some cacheing) as for what data goes where.. thats down to your own design.. i would probably have a table for contents tables for domains and a table to link them ie Contents ID - Contents 1. Hello World 2. Hello John 3. Hello Paul Domain ID - Name 1. SiteA 2. SiteB 3. SiteC CtoDLink ID - DomainID - ContentID 1. 1 - 1 2. 1 - 2 3. 1 - 3 4. 2 - 1 5. 2 - 2 6. 3 - 1 7. 3 - 3 So.. SiteA can see all contents SiteB can see Hello World & 2. Hello John SiteC can see Hello World & 2. Hello Paul
-
Try this, untested but should be ok, your need to mod it for PNG & GIF, as i pulled the CreateThumb function from an old project and tweeked it a little <?php $FTP_upload = dirname(__FILE__)."/FTP/";//From Dir $WWW_Images = dirname(__FILE__)."/images/"; //To Dir if(!$dh = @opendir($FTP_upload)) return; while (false !== ($obj = readdir($dh))) { if($obj=='.' || $obj=='..') continue; CreateThumb($FTP_upload.'/'.$obj, $WWW_Images.'/'.$obj,100,100) } } closedir($dh); function CreateThumb($name,$filename,$new_w,$new_h, $Qty=100) { ini_set("memory_limit","32M"); if (preg_match('/(?:\.jpg|\.jpeg)$/i', $name)) { $src_img=imagecreatefromjpeg($name); } if( $src_img === false || $src_img === NULL) { echo "Failed:<br>"; return false; } $old_x=imageSX($src_img); $old_y=imageSY($src_img); //dont resize up. if( ($new_w > $old_x) && ($new_h > $old_y)) { $thumb_w=$old_x; $thumb_h=$old_y; }else{ if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } } $dst_img=imagecreatetruecolor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); imagejpeg($dst_img,$filename, $Qty); imagedestroy($dst_img); imagedestroy($src_img); } ?>
-
i think you want "0744" for the access if you want everyone to read it! "0755" for read and execute
-
after a very quick look please read comments <?php $Itemname = $rs->Fields[Title]; //Constant ? or should it be 'Title' $ItemId = $rs->Fields[Product_ID]; //Constant or should it be 'Product_ID' $Price = $rs->Fields['Price']; $Time = date(time()); $Date = date("d/m/y : H:i:s"); $Small = $rs->Fields['Small']; //$username isn't set at all! //$ItemID isn't set but $ItemId is //$price isn't set but $Price is //$time isn't set but $Time is $sql = "INSERT INTO Cart (Username, Count, ItemName, ItemID, Price, Time, Date, Small) VALUES ('$username', '$count', '$Itemname', '$ItemID', '$price', '$time', '$Date', 'Small')"; ?>
-
could be the space at the end of isn't a valid path from the root maybe try this <?php mkdir(dirname(__FILE__)."/html/pages/folder1", 0700); ?>
-
Can you till me whats wrong with line 39
MadTechie replied to designedfree4u's topic in PHP Coding Help
the single quote array_push($error, 'You didn't supply a username'); change to array_push($error, 'You didn\'t supply a username'); or array_push($error, "You didn't supply a username"); -
change $time = date('h:i a',$i) . "<br>\n"; to $time = date('h:i a',$i); as that will messup the compare you can add it back in after the compare if( !in_array($time, $exclude) ) { $time = date('h:i a',$i) . "<br>\n"; $myinfo[0] .= "<option value=\"".$time."\">".$time."</option>"; }
-
i think the key points are 1. pulling data from a database and displaying it on screen, 2. using relationships ie users table, product table (linked via sales table) 3. session for keeping track of the logged in user. and what they have selected before they have logged in, no idea if that helps!
-
lol you may want to add a semicolon to some of my lines ie $excludeStart = "7:10" $excludeEnd = "7:40" should be $excludeStart = "7:10"; $excludeEnd = "7:40";
-
if pass field blank dont update sql on the slected fields
MadTechie replied to jesushax's topic in PHP Coding Help
Sorry didn't understand the first post i assumed you didn't want to update if their was no password basic translation to php <?php $strUserID = $_SESSION["UserID"]; $strFirstName = mysql_real_escape_string($_POST["txtFirstName"]); $strlastName = mysql_real_escape_string($_POST["txtLastName"]); $strUserName = mysql_real_escape_string($_POST["txtUserName"]); $strUserPass = md5($_POST["txtUserPass"]); $strEmail = mysql_real_escape_string($_POST["txtEmail"]); $SQL = "UPDATE table SET UserName ='".$strUserName."', FirstName ='".$strFirstName."', "; if (isset($_POST["txtUserPass"]) && !empty($_POST["txtUserPass"])) { $SQL = $SQL." UserPassword='".$strUserPass."', "; } $SQL = $SQL." UserEmail='".$strEmail."' WHERE UserID='".$strUserID."' "; //Connect to database etc mysql_query($SQL) or die(mysql_error()); Updated to make it look as close to asp code as i could -
Basically just have an if statement to control it.. *Note code below was written online and is untested here is an example for a range of dates <?php $start = "7:00"; $finish = "12:00"; $st = strtotime(date('Y-m-d') . $start); $en = strtotime(date('Y-m-d') . $finish); //create a exclude range $excludeStart = "7:10" $excludeEnd = "7:40" $eStart = strtotime(date('Y-m-d') . $excludeStart; $eEnd = strtotime(date('Y-m-d') . $excludeEnd; $int = 10 * 60; $myinfo[0] = "<select name=\"time\" id='listboxes'>"; for ($i = $st; $i <= $en; $i += $int) { $time = date('h:i a',$i) . "<br>\n"; //if NOT in the exclude range then add a value if( !($time > $eStart && $time < $eEnd) ) { $myinfo[0] .= "<option value=\"".$time."\">".$time."</option>"; } } ?> another example for singles <?php $start = "7:00"; $finish = "12:00"; $st = strtotime(date('Y-m-d') . $start); $en = strtotime(date('Y-m-d') . $finish); //create a exclude single/s $exclude[] = "7:10" $exclude[] = "7:40" $int = 10 * 60; $myinfo[0] = "<select name=\"time\" id='listboxes'>"; for ($i = $st; $i <= $en; $i += $int) { $time = date('h:i a',$i) . "<br>\n"; //if NOT in the exclude array then add a value if( !in_array($time, $exclude) ) { $myinfo[0] .= "<option value=\"".$time."\">".$time."</option>"; } } ?>
-
maybe this one http://www.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart ( i did a google for "php shopping cart tutorial") it looks ok
-
it really depends on the rule, if you just wanted to add an space before the # you can use thorpes code but if the MUST have a number after it you can use the code below, <?php $data = "design#8"; $data = preg_replace('/(#\d+)/', ' \1', $data); echo $data; ?> Please note thorpe code will be quicker, but won't take into acount it requires a number after the #
-
if pass field blank dont update sql on the slected fields
MadTechie replied to jesushax's topic in PHP Coding Help
<?php $strUserName = mysql_real_escape_string($_POST["txtUserName"]); $strFirstName = mysql_real_escape_string($_POST["txtFirstName"]); $strlastName = mysql_real_escape_string($_POST["txtLastName"]); $strTel = mysql_real_escape_string($_POST["txtTel"]); $strHomePage = mysql_real_escape_string($_POST["txtHomePage"]); $strCompanyName = mysql_real_escape_string($_POST["txtCompanyName"]); $strUserPass = md5($_POST["txtUserPass"]); $strEmail = mysql_real_escape_string($_POST["txtEmail"]); $strUserID = $_SESSION["UserID"]; if(!strlen($strUserName)){ echo '<p style="color:#FF0000;">Error: Username Was Left Blank</p>'; } elseif(!strlen($strEmail)){ echo '<p style="color:#FF0000;">Error: Email Was Left Blank</p>'; } else{ //empty is what your looking for if(!empty($_POST["txtUserPass"]))// if not empty then process { mysql_query("Update tblUsers Set UserName='".$strUserName."', UserPassword='".$strUserPass."', UserEmail='".$strEmail."', UserCompanyName='".$strCompanyName."', UserFirstName='".$strFirstName."', UserLastName='".$strlastName."', UserTel='".$strTel."', UserHomePage='".$strHomePage."' WHERE UserID='".$strUserID."'") or die(mysql_error()); } ?> -
need more info.. try this code with the debug code (it should help) <?php //this script outputs the data in table format. mysql_connect("localhost",$user,$password); mysql_select_db($database) or die( "Unable to select database"); $vars = Array(); // Append to the array, the variable 'where' query, if the variable exists. if(isset($_POST['sfirst']) && !empty($_POST['sfirst'])){ $vars[] = "`sfirst`='".mysql_escape_string($_POST['sfirst'])."'"; } if(isset($_POST['slast']) && !empty($_POST['slast'])){ $vars[] = "`slast`='".mysql_escape_string($_POST['slast'])."'"; } if(isset($_POST['sphone']) && !empty($_POST['sphone'])){ $vars[] = "`sphone`='".mysql_escape_string($_POST['sphone'])."'"; } if(isset($_POST['smobile']) && !empty($_POST['smobile'])){ $vars[] = "`smobile`='".mysql_escape_string($_POST['smobile'])."'"; } if(isset($_POST['sfax']) && !empty($_POST['sfax'])){ $vars[] = "`sfax`='".mysql_escape_string($_POST['sfax'])."'"; } if(isset($_POST['semail']) && !empty($_POST['semail'])){ $vars[] = "`semail`='".mysql_escape_string($_POST['semail'])."'"; } if(isset($_POST['sweb']) && !empty($_POST['sweb'])){ $vars[] = "`sweb`='".mysql_escape_string($_POST['sweb'])."'"; } // echo "value of sfirst is $sfirst<br>\n" ; // echo "value of slast is $slast<br>\n" ; // echo "value of sphone is $sphone<br>\n" ; // echo "value of smobile is $smobile<br>\n" ; // echo "value of sfax is $sfax<br>\n" ; // echo "value of semail is $semail<br>\n" ; // echo "value of sweb is $sweb<br>\n" ; // echo "value of vars is $vars<br>\n" ; // If user did not submit any queries... if(!isset($vars[0])){ exit("Please Choose At Least One Filter"); } // Count how many where queries is requested if(count($vars) > 1){ // If there is more than 1 where query then 'implode' the array with " and ", (convert to str and insert " and " between each item) //echo "vars was greater than 1<br>\n" ; $where = "WHERE ".implode(" and ",$vars); }else{ // Otherwise assume there is only 1 where query //echo "vars was less than 1<br>\n" ; $where = "WHERE ".$vars[0]; } //echo "the value of where is $where<br>\n" ; // Make the Query $query="SELECT * FROM `contacts` $where LIMIT 30"; //added debug code echo "<pre>"; echo $where; echo "<br>"; print_r($vars); echo "<br>"; $result = mysql_query($query) or die("SQL='$query' <br> ".mysql_error()); //end debug code echo("result is: "); print_r($result);echo("<br />\n"); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif">Mobile</font></th> <th><font face="Arial, Helvetica, sans-serif">Fax</font></th> <th><font face="Arial, Helvetica, sans-serif">E-mail</font></th> <th><font face="Arial, Helvetica, sans-serif">Website</font></th> </tr> <?php while ($row = mysql_fetch_assoc($result)) { $first = $row["first"]; $last = $row["last"]; $phone = $row["phone"]; $mobile = $row["mobile"]; $fax = $row["fax"]; $email = $row["email"]; $web = $row["web"]; /*personal dislike of this style of code $i=0; while ($i < $num) { $first =mysql_result($result,$i,"first"); $last = mysql_result($result,$i,"last"); $phone = mysql_result($result,$i,"phone"); $mobile = mysql_result($result,$i,"mobile"); $fax = mysql_result($result,$i,"fax"); $email = mysql_result($result,$i,"email"); $web = mysql_result($result,$i,"web");*/ //echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>"; ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo $first." ".$last; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $phone; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $mobile; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $fax; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $email; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $web; ?></font></td> </tr> <?php //$i++; //noted needed } // close while mysql_free_result($result); echo "</table>"; ?>
-
the problem about using unmanaged offsite images is your can not get the size of the images unless you use getimagesize(); which timesout as it need to connect to the other sites.. i guess your need to look into a CSS solution or download the images to your site.. EDIT: oh that code won't work if mine timesout so will that code, they both relie on getimagesize()
-
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
i don't think height will work on a <tr> tag, maybe line height, but to sumup yes you can use styles -
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
as i said this is a HTML/CSS issule not really php one, you may wany to look into CSS later (but i think its better yet a little harder), you can style the tables ie <table width="100%" border="0" cellspacing="5" cellpadding="10"> <tr> <td width="25%">add</td> <td width="25%">add</td> <td width="25%">add</td> <td width="25%">add</td> </tr> <tr> <td width="25%">add</td> <td width="25%">add</td> <td width="25%">add</td> <td width="25%">add</td> </tr> <tr> <td width="25%">add</td> <td width="25%">add</td> <td width="25%">add</td> <td width="25%">add</td> </tr> </table> -
woohoo 2 thread solved within minutes of each other your welcome,
-
insert HTML code into sql table via php form
MadTechie replied to Alexhoward's topic in PHP Coding Help
i'll take that as its working:) -
change from // print the navigation link echo $first . $prev . $nav . $next . $last; } } else { echo '<p>There are no search results with the search criteria you entered.</p>'; } ?> to // print the navigation link echo $first . $prev . $nav . $next . $last; } if($numrows < 1) echo '<p>There are no search results with the search criteria you entered.</p>'; } ?> thats from "// print the navigation link" to the end of the code "?>" thats should do it