HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
How about make it auto-increment but start it on something random like 4932. Nobody will be any the wiser then! [code]ALTER TABLE table_name ADD column_name INT UNSIGNED NOT NULL AUTO_INCREMENT=4932[/code] That should do it. Regards Huggie
-
OK, give this a try and run with it... [code]$urlpattern = "/<a[^>]+href=(?:\"|')?([^'\">]+)/i";[/code] [b]Edit:[/b] I've tested this and it seems to work fine. Regards Huggie
-
OK, let's do away with the multiple functions and go for the code direct and see what happens... I'll put some comments and debug in there too. [code]<?php // Firstly check there's something in your session variable *debug* print_r($_SESSION['cart']); // Lets put each of the product_id's (pids) into a new array with single quotes around them foreach ($_SESSION['cart'] as $pid => $qty){ $pid_array[] = "'$pid'"; } //makes the query easier if we put the pid's in a list $pid_string = implode(', ', $pid_array); print_r($pid_string); // should give us a list in the format 'id1', 'id2', 'id3' etc *debug* // OK, let's do the database stuff $connection = db_connect(); //connect $sql = "SELECT product_id, dl_link FROM products WHERE product_id IN ($pid_string) ORDER BY product_id"; $result = mysql_query($sql) or die ("Sorry, unable to execute $sql: " . mysql_error()); // execute the query // Loop through the results array, putting the values in to a new array keyed on pid while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $links[$row['product_id']] = $row['dl_link']; // Here's the magic } // Lets see if the array is as we expected *debug* print_r($links); ?>[/code] Let me know how you get on with that. Regards Huggie
-
That's correct. Huggie
-
I'll see if I can create you a nice little function... Huggie
-
[quote author=onlyican link=topic=124534.msg516096#msg516096 date=1170081728] Its 3072px Wide BY 2048px High 300DPI but only 768kb [/quote] The quality of that must be extremely poor! As for setting the quality to 72dpi, I'd suggest looking through all the [url=http://uk.php.net/manual/en/ref.image.php]image functions[/url]. Huggie
-
At the very end... [code]else { if ( $delete ) { $mode = 'delete'; } else if ( $move ) { $mode = 'move'; } else if ( $lock ) { $mode = 'lock'; } else if ( $unlock ) { $mode = 'unlock'; } }[/code] Regards Huggie
-
You could create a little function to do this using the strtotime(), date() and mktime() functions. Regards Huggie
-
The closing tags should always be [color=green]?>[/color] If the php_ini settings allow, you can use short tags to open php, so you can use [color=green]<?[/color] instead of [color=green]<?php[/color] but it's never advisable as it's installation specific and makes the code less portable. Regards Huggie
-
It should be as simple as [code=php:0]$timestamp = strtotime("-15 min"); $time_fifteen_mins_ago = date("Y-m-d H:i:s", $timestamp);[/code] Regards Huggie
-
[SOLVED] Very VERY simple php variable trouble
HuggieBear replied to Snooble's topic in PHP Coding Help
My pleasure... Huggie -
[quote author=onlyican link=topic=124534.msg516057#msg516057 date=1170079144] I know I can set the Memory Limit higher, but I want to know WHY I am getting this message. [/quote] The GD library uses a lot of memory. I included a link in a [url=http://www.phpfreaks.com/forums/index.php/topic,121661.msg500680.html#msg500680]previous post[/url] that details this. Regards Huggie
-
OK, if I understand the code correctly, then it's over complicating itself and acting rather strangely... Why are you passing the string '[color=red]product_id[/color]' into the [color=blue]display_dl_link2()[/color] function when you straight away overwrite it with a different value? Regards Huggie
-
[SOLVED] Very VERY simple php variable trouble
HuggieBear replied to Snooble's topic in PHP Coding Help
That makes it much clearer... Try this code: [code]<?php $host="***********"; // Host name $username="*******"; // Mysql username $password="*******"; // Mysql password $db_name="************"; // Database name $tbl_name="web_members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password") or die ("cannot connect: " . mysql_error()); mysql_select_db("$db_name") or die("cannot select DB: " . mysql_error()); $sql = "INSERT INTO web_members (Email, Password) VALUES ('" . $_POST['email'] . "', '" . $_POST['pass'] . "')"; mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); echo '<form action="index.php" method="post"> <input type="hidden" name="email" value="'.$_POST['email'].'"> <input type="hidden" name="fname" value="'.$_POST['fname'].'"> <input type="hidden" name="sname" value="'.$_POST['sname'].'"> <input type="hidden" name="pass" value="'.$_POST['pass'].'"> <input type="hidden" name="passtwo" value="'.$_POST['passtwo'].'"> <input type="hidden" name="llno" value="'.$_POST['llno'].'"> <input type="hidden" name="mobno" value="'.$_POST['mobno'].'"> <input type="hidden" name="addno" value="'.$_POST['addno'].'"> <input type="hidden" name="addone" value="'.$_POST['addone'].'"> <input type="hidden" name="addtwo" value="'.$_POST['addtwo'].'"> <input type="hidden" name="addthree" value="'.$_POST['addthree'].'"> <input type="hidden" name="city" value="'.$_POST['city'].'"> <input type="hidden" name="other" value="'.$_POST['other'].'"> <input type="hidden" name="country" value="'.$_POST['country'].'"> <input type="hidden" name="noc" value="'.$_POST['noc'].'"> <input type="hidden" name="ccno" value="'.$_POST['ccno'].'"> <input type="hidden" name="expdate" value="'.$_POST['expdate'].'"> <input type="hidden" name="cvv" value="'.$_POST['cvv'].'"> <input type="image" src="register.gif" name="submit" alt="Log In" value="Log In" />'; $pass = $_POST['pass']; $email = $_POST['email']; $passtwo = $_POST['passtwo']; $fname = $_POST['fname']; $sname = $_POST['sname']; $llno = $_POST['llno']; $mobno = $_POST['mobno']; $addno = $_POST['addno']; $addone = $_POST['addone']; $addtwo = $_POST['addtwo']; $addthree = $_POST['addthree']; $city = $_POST['city']; $postcode = $_POST['postcode']; $other = $_POST['other']; $title = $_POST['title']; $country = $_POST['country']; ?> [/code] Regards Huggie -
[SOLVED] Very VERY simple php variable trouble
HuggieBear replied to Snooble's topic in PHP Coding Help
OK, this code is a little off the mark. You need to imagine the way a page flows... Step 1 - Present a form for the user to fill out Step 2 - Form is filled out and submitted Step 3 - Validation occurs and if failed returned to form, if ok, continue (Optional step) Step 4 - Process the information and insert into the database Step 5 - Confirm to the user that they've registered. Would you agree that the above is what you're trying to achieve? Regards Huggie -
OK, give this a try... [code] <?php $dl_link = display_dl_link2($_SESSION['cart'], 'product_id'); function display_dl_link2($cart,$product_id){ foreach ($cart as $product_id => $qty){ echo "The value of $product_id is $qty<br />"; //debug to check have prod ids shows } //The value of 2 is 1 //The value of 3 is 1 if (!$product_id || $product_id==''){ return false; } $connection = db_connect(); $query = "select dl_link from products where product_id='$product_id'"; $result = mysql_query($query); if (!$result){ mysql_error(); return false; } else { $result_array = db_result_to_array($result); return $result_array; } } //results to array function function db_result_to_array($result_resource){ $res_array = array(); while ($row = mysql_fetch_array($result_resource, MYSQL_ASSOC)){ $res_array[] = $row; return $res_array; } } ?> [/code] Regards Huggie
-
Ted, The OP wants their images displayed in a table, not just one after the other on the page. So rather than this: [color=green]image.jpg image.jpg image.jpg image.jpg image.jpg image.jpg[/color] They want: [color=green]image.jpg image.jpg image.jpg image.jpg image.jpg image.jpg[/color] Regards Huggie
-
[SOLVED] Very VERY simple php variable trouble
HuggieBear replied to Snooble's topic in PHP Coding Help
OK, maybe you should show us the code you do have. Huggie -
My advice would be to create a php page that looks like this: [code]<?php print_r($_POST); ?>[/code] ave the flash file call this page to check the variables that it's actually passing to the PHP script. Regards Huggie
-
[SOLVED] Very VERY simple php variable trouble
HuggieBear replied to Snooble's topic in PHP Coding Help
OK, firstly that code can be simplified to: [code]<?php $sql = "INSERT INTO web_members (Email, Password) VALUES ('" . $_POST['email'] . "', '" . $_POST['pass'] . "')"; ?>[/code] If that's not working then add some error checking to your mysql_query() line like this: [code]<?php $result = mysql_query($sql) or die ("Can't execute $sql: " . mysql_error()); ?>[/code] This will output the error from mysql if it fails to run the query for any reason. You should also sanitise your user input to prevent SQL injection. Regards Huggie -
Excellent, make sure that you mark the topic as 'SOLVED'. Regards Huggie
-
You're redefining the $result resource by mistake with this line... [code=php:0]$result = mysql_fetch_assoc($result);[/code] Change it to something like: [code=php:0]$row = mysql_fetch_assoc($result);[/code] Regards Huggie
-
Try this: [code]$urlpattern = "/<a[^>]+href=(?:\"|')([^'\"]+)/i";[/code] Regards Huggie
-
[quote author=ProjectFear link=topic=124471.msg515749#msg515749 date=1170028544] well to do it graphicly you would have to use GD [/quote] Why would you? Why not create an image for each number, 0 through 9 and then use a little function to replace any number with that of it's counterpart image. This would be really simple, especially if you gave the images numbers as names, e.g. 0.gif, 1.gif, 2.gif..... Get the idea? Regards Huggie
-
[quote author=ProjectFear link=topic=124464.msg515746#msg515746 date=1170028081] are the codes and everything already written out in a file, like: 0001:Book Store,0002:Train Station etc etc. :) then just get the contents of the file, use the explode function on it to split them all into just 0001:Book Store Then in a for or foreach loop explode them again then create the drop down list. Then use ajax for the rest. [/quote] I was just going to write a bit of example code that did just that... [code]<?php // Get the code passed from the form field $mmc = $_GET['mmc']; // Path to your code file $filepath = 'mmc_codes.txt'; // Create an array of the file contents $codes = file($filepath); // Loop through the results foreach ($codes as $code){ list($c, $d) = explode(' ', $code); // Split the line on a space ($c is code, $d is description) if ($code == $mmc){ echo $d; } } ?>[/code] You can add additional checks into the php, and hey presto. Regards Huggie