-
Posts
4,705 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Your executing your insert query twice: mysql_query($i) or die(mysql_error()); // <-- First here if (!mysql_query($i)) { //<-- Then again here That is why your getting a double insert.
-
include() returns true or false depending on whether the include was a success or not. If you file contains a 'return' statement it will return that instead. If you file just contains a bunch of echo's though and you want to capture that, you need to use output buffering. ob_start(); include 'file.php'; $output = ob_get_clean(); //write $output to file
-
Just use PHP as your template engine directly. There's no need to invent another language/syntax.
-
Your header redirect is not working because your processing the form using ajax. Your header redirect is just going to cause the background ajax request to be redirect, not the page that is displayed. If you want to redirect the page displayed, you need to output something which your ajax success handler can pick up and test for and then use JS to do your redirect. ex: echo json_encode(array( 'response' => 'redirect', 'url' => 'http://www.example.com' )); $.ajax({ url: "login.php", type: "GET", data: data, cache: false, success: function() { //Get the json response via some means //then... if (jsonObj.response == 'redirect'){ window.location.href = jsonObj.url; } } });
-
You give them unique names with which you can tie that box back to a particular cart item. The easiest way to manage that is to give them a name which will generate an array and use some id as the key, such as the product id: foreach ($_SESSION['cart'] as $productId=>$qty){ echo '<input type="text" name="quantities['.$productId.']" value="'.$qty.'">'; } Then on the receiving end: foreach ($_POST['quantities'] as $productId=>$qty){ $_SESSION['cart'][$productId] = intval($qty); }
-
Trouble getting output of a form to show in a specific way
kicken replied to bbw82's topic in PHP Coding Help
If your outputting to a browser, then it is going to see your construct as an HTML tag and try to render it as such. Chances are your creating an invalid tag so it just ignores it. If you want to display the < and > literally, you need to use their entities: < and >. You could either use them directly, or run your variable through the htmlentities() function when you output it. -
User comments in the manual say: If your going to test by fetching a row though, you do not need this function.
-
The documentation mention that: However I agree attempting to fetch a row is better than checking for num rows returned. Another alternative would be to use the COUNT(*) function which will always return a row and would have a value of 0 or 1 based on if there was a match found.
-
Validator Results (download.php) Validator Results (downloadprofile.php) Look at the validator results. In addition to other errors, you'll notice the results for download.php has on extra error complaining about a character before the doctype. You will also notice on both the warning about the Byte-Order Mark. This byte order mark is your problem most likely. Re-save the files as UTF-8 but without the BOM. What is probably happening is both your files have a BOM at the start of the file. When you access downloadprofile.php by itself, then there is no problem because the BOM is removed since the document is handled as utf-8. When you access it through download.php file, you end up with two BOM's (one from download.php, and one from downloadprofile.php). The first one is handled as part of the utf-8 decode process, the second one is invalid and causing problems.
-
$sql="UPDATE application SET Status = '$status' WHERE ID = '$member'"; $sql1="INSERT INTO table_members(name) SELECT application.Name FROM application WHERE application.ID = '$member'"; Those two queries imply that $member is an id, while if(mysql_num_rows(mysql_query("SELECT name FROM table_members WHERE name = '$member'"))) implies it is a name. It can't be both. Either your using the wrong variable or the wrong column in your query. As an alternative, you could use a unique key and then INSERT INTO ... ON DUPLICATE KEY UPDATE ... to handle it rather than separate queries.
-
If you want to check for number of rows, the result meta data is not the function you want. The result set that contains the row data (and thus number of rows) is the one returned by get_result(); mysqli_stmt_bind_param($this->statement, 's', $username); mysqli_stmt_execute($this->statement); $result = mysqli_stmt_get_result($this->statement); if(mysql_num_rows($result) > 0) { }
-
Can't figure out why is_numeric isn't working
kicken replied to floridaflatlander's topic in PHP Coding Help
$_GET['mem-items'] != $_GET['$mem-items'] You have an extra $. -
Using PHP to Export SQL Results into CSV & E-mail
kicken replied to SeanAC's topic in PHP Coding Help
You need to do two things. 1) Create a CSV format file. Right now your just making a html table. This is not too hard to do using fputcsv(). 2) Email the file to yourself. This involves creating a multipart mime email to attach the file. It can be a bit of a pain. I would recommend you get a class to do this for you, such as PHP Mailer or Mail::Mime $tmp = tmpfile(); //Output headers $csvLength = fputcsv($tmp, array( 'CONSUMER', 'DATE', 'TYPE', '...' )); while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { $csvLength += fputcsv($tmp, array( $row['DCONSUMER'], $row['DDATE'], $row['DTYPE'], $row['...'] )); } rewind($tmp); $csvContent = fread($tmp, $csvLength); fclose($tmp); //mail your file here with whatever method you choose. //$csvContent is the csv file, add it as an attachment. -
Correction, it was just as broken on the old one. You just had your error reporting level set to not show notices. Array keys which are strings have to be quoted: $course=$_GET['course']; echo $course;
-
There is no such function mysql_database. As such your script likely is failing with a fatal error to an undefined function. If your not seeing this error in your browser, then your server must be configured to not display errors (display_errors setting in php.ini) or some other configuration issue is preventing them from showing.
-
How do i use return to output more than one row of information?
kicken replied to newb's topic in PHP Coding Help
You can only return one value. If you want the results as a string, have the function build that string through concatenation and then return it. You could also store each result in an array and return the array. $ret = ''; $query = exec_mysql_query("SELECT * FROM av_genres WHERE id = $cid ORDER BY name DESC"); while ($row = mysql_fetch_assoc($query)) { $ret .= $row['name'].', '; } return $ret; -
There are different reasons for caching. One reason is to preserve bandwidth by letting browser store local copies of resources so they do not have to re-request them. This is something the browser manages automatically. Another reason is to cache the results of an expensive operation. For example, resizing a large image into a thumbnail is an expensive operation and can put a lot of stress on a server if it is constantly resizing an image. As such, it is beneficial to do the resize once and save the result in a file. That way for subsequent requests can simple use the cached results rather than having to repeat the resize. You can code your resize script so that it checks for the cached results file and if so, just outputs it. If it does not exist yet, then it can create it.
-
The terms hostname/servername typically are used to refer to the domain name. The http: part is the protocol or scheme. http://www.example.com/somepath/somefile.php http = Protocol / Scheme. http, https, ftp, etc www.example.com = Host name / Domain name / Server name /somepath/somefile.php = Path I am not aware of any specific term that is commonly used for the combination of the protocol and hostname. If I had to create a variable for it I would probably name it BASE_URL or similar.
-
Get contents of a URL and show only specific text
kicken replied to kapz22's topic in PHP Coding Help
Use DomDocument to parse the html into a dom tree, then you can traverse it and find what you need. -
I suppose you could call them the URL Root, though I'm not aware of any particular name for them. Generally you don't have to worry about them too much. If you have a link, such as <a href="/index.php">Home<a> And you access the page from say http://local.dev3/somedir/somefile.php then your browser will take that link URL and generate the url http://local.dev3/index.php If you accessed the page from http://www.mysite.com/somdir/somefile.php then your browser would generate the URL http://www.mysite.com/index.php It will automatically use whatever protocol (http vs https) and domain (www.mysite.com vs local.dev3) that you used when you requested the page containing the link. You almost never have to include that information in your links (and probably shouldn't generally) unless you need to force a particular protocol or domain name. Like you might use a full absolute url in a <form action=""> tag to send the user to a https url instead of a http url.
-
There's no need for your foreach() loop inside your while loop. In fact I would expect it to not work as $row['app_id'] wouldn't be an array. while($row = mysqli_fetch_array($result)) { $checked1[] = $row['app_id']; } That said, can you not just use a JOIN in your first sql query to achieve the desired results? Seems like it should be possible if your just getting ID's and re-querying.
-
IF in_array only check against the last value in my array ..
kicken replied to parapro's topic in PHP Coding Help
file() leaves the new lines on the end of each line by default. Each entry in your array then is going to have a newline sequence following it which is why your matches do not work. $date_array = file('test.txt', FILE_IGNORE_NEW_LINES); -
I do most my dev work in chrome and since they have always had that view source reload problem I got used to using Fiddler2 when I need to debug things like that. Using it you can just find whichever request your interested in and then view it's data. Works well when dealing with xhr requests and such too.
-
Web Root and Document Root are the same thing generally. They refer to the location from which your website is served by your webserver. Any file/directory below the web root has a corresponding URL from which it can be accessed. Filesystem root is where your filesystem on your hard drive begins. Such as C:\ on windows, or '/' on linux/unix/mac. Script Root could be whatever you want it to be, it doesn't really have any particular meaning. ----- You can define however many "root" directories as you want, just so long as you know what each one is referencing. That is why they are usually prefixed with some other word and not just 'root'. I usually define an includes root, uploads root, templates root, etc: define('DOCUMENT_ROOT', dirname(dirname(__FILE__))); define('TEMPLATE_ROOT', DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'templates'); define('INCLUDE_ROOT', DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'includes'); define('UPLOADS_ROOT', DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'Uploads'); What you just have to know and understand is that regardless of whether you define your own roots or not will have no effect on how a path is resolved unless you use those root constants in your paths. <?php require('/file.php'); ?> The / there will always refer to the filesystem root. If you want to use a different root, you have to prefix the path with the appropriate root constant: <?php require(INCLUDE_ROOT.'/file.php'); ?> Likewise in HTML. <a href="/index.php"></a> Will always refer to the web/document root. If you wanted some other root you would have to echo it out as a prefix.