jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
How about posting your form, that way we will know how to build the query.
-
How would I implement this version of a dynamic search?
jcbones replied to yoursurrogategod's topic in PHP Coding Help
You would be better off (if it is a large recordset) to create your abbr links, then get the description via AJAX (which calls back to the server). -
insert doesn't work - help please! ...and thank you.
jcbones replied to perplexia's topic in PHP Coding Help
You are not connected to the database, the error tells you the source of the problem is the connection, and the reason is that the object is closed. You need to go back and check your connections to see why it isn't open. -
You'll notice the line above it says: //include("file_upload_script.php"); //include the upload script if the form was submitted. You need to un-comment it like: include("file_upload_script.php"); //include the upload script if the form was submitted. And remove the test4.php include. My mistake, thought I removed that.
-
Here is you something to play around with. This will let you choose a directory, or make a new one. index.php <?php //get directories for images. /******NOTE (point this variable to your image directory, it will find all subfolders) *************/ $image_directory = 'test'; //Where do you want to look for image directories at? /********************************************************************************************************/ foreach (glob($image_directory . DIRECTORY_SEPARATOR . "*", GLOB_ONLYDIR) as $dir) { //this will find ONLY directories. $directories[] = substr($dir,(strpos($dir,DIRECTORY_SEPARATOR) + 1)); //$directories array will only be set IF there are directories inside of the specified $image_directory. } ?> <!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-Language" content="da" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> .style1 { text-align: left; } </style> <script type="text/javascript"> function newInput() { var place = document.getElementById('dir').innerHTML = '<br /><label for="dir">New Directory</label><br /><input name="dir" type="text" /><br />'; } </script> </head> <body> <p>UPLOAD FILE</p> <form enctype="multipart/form-data" method="post" > <div class="style1"> Choose file:<br /> <input name="file1" type="file" /><br /> Choose Directory: <span style="font-size: .83em; line-height: 0.5em; vertical-align: baseline; position: relative; top: -0.4em;">(Leave blank for base directory.)</span> <br /> <?php echo $image_directory . DIRECTORY_SEPARATOR; ?> <span id="dir"> <select name="dir"> <option></option> <?php if(!empty($directories)) { foreach($directories as $folder) { echo '<option>' . $folder . '</option>' . PHP_EOL; } } ?> </select><br /> <a href="javascript:void(0);" onclick="newInput();">Add a Directory?</a> </span><br /> <input type="submit" value="Go" /> <input type="reset" value="Reset" /> </div> </form> </body> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { //check to see if the form was submitted. //include("file_upload_script.php"); //include the upload script if the form was submitted. include('test4.php'); } //ends the if statement. ?> file_upload_script.php <?php // Set local PHP vars from the POST vars sent from our form using the array // of data that the $_FILES global variable contains for this uploaded file $fileName = $_FILES["file1"]["name"]; // The file name $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["file1"]["type"]; // The type of file it is $fileSize = $_FILES["file1"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true $directory = (empty($_POST['dir'])) ? NULL : DIRECTORY_SEPARATOR . strip_tags($_POST['dir']); //if the form dir is empty, then make this variable null, otherwise set it as the directory. if($directory != NULL && !is_dir($image_directory . $directory)) { //if $directory is NOT null, and it IS NOT a directory, if(!mkdir($image_directory . $directory, 0775)) { //try to make the directory, if it fails to make. echo "ERROR: Unable to create directory, please make $image_directory is readable and writeable, and the owner has execute permission."; //throw an error, AND exit(); //stop the script. No file upload. } } $path = $image_directory . $directory . DIRECTORY_SEPARATOR . $fileName; //if everything has passed, make the path. (if directory was empty, the path will be to the main $image_directory. // Specific Error Handling if you need to run error checking if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } else if($fileSize > 524288000) { // if file is larger than we want to allow echo "ERROR: File size restriction. File larger than 500mb."; unlink($fileTmpLoc); exit(); } // Place it into your "uploads" folder mow using the move_uploaded_file() function move_uploaded_file($fileTmpLoc, "$path"); // Check to make sure the uploaded file is in place where you want it if (!file_exists("$path")) { echo "ERROR: File not uploaded. $fileName alreadt exists.<br /><br />"; exit(); } // Display things to the page so you can see what is happening for testing purposes echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />" . "The file path is " . $path . '<br /><br />'; echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />"; echo "It is a <strong>$fileType</strong> type of file.<br /><br />"; echo "The Error Message output for this upload is: <br />$fileErrorMsg"; ?>
-
Wow, this advice is all over the place. Lets keep it simple, and keep running with the code you have. There are NO changes to be made in file_upload_script.php. index.php Note*: form action removed, other changes at bottom of the script (commented). <!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-Language" content="da" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> .style1 { text-align: left; } </style> </head> <body> <p>UPLOAD FILE</p> <form enctype="multipart/form-data" method="post" > <div class="style1"> Choose file:<br /> <input name="file1" type="file" /><br /> <input type="submit" value="Go" /> <input type="reset" value="Reset" /> </div> </form> </body> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { //check to see if the form was submitted. include("file_upload_script.php"); //include the upload script if the form was submitted. } //ends the if statement. ?>
-
Did you read the manual for header? I ask because the second line under the function description is:
-
I do not understand either. I will give you this bit of info though. for loops for($do_this_before_the_first_loop_starts;$do_another_loop_if_this_condition_is_met;$do_this_after_each_loop) So, I'm not sure if: for ($i = 1; $i = $num_matches; $i++) is infinite, or just won't run period.
-
When a query to MySQL fails, then MySQL throws an error, PHP's function mysql_query will return FALSE. The functions that rely on mysql_query() will then fail, because they are NOT designed to handle a FALSE resource. This is why I can be confident in telling you: your query is failing with an error. There are a couple of ways to handle this. 1. echo out your query, and run it in a database console, or software (phpMyAdmin). 2. code in a de-bugger that will show what the error is. Like: $sorgu2 = mysql_query($sorgu1) or trigger_error( $sorgu1 . ' has encountered an error. <br />' . mysql_error() );
-
I always use the full URL for any pictures, CSS, JS, etc. Then I don't have to worry about a path issue.
-
When Return False is added, script doesn't execute
jcbones replied to iseriouslyneedhelp's topic in PHP Coding Help
Try: <form method="post" action="/cms/scripts/delete-mult.php" onSubmit="return removemult();" name="updateleads" id="updateleads"> <table> <tbody> while ($stmt->fetch()) { echo'<tr> <td><input type="checkbox" name="checked[]" value="'.$ID.'"></td> <td><a href="/cms/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td> </tr>'; </tbody> </table> <input name="remove" type="submit" value="Delete"> </form> function removemult() { if (confirm("Are you sure you want to delete these leads?")) { return true; } return false; // If removed, no matter if ok or cancel is clicked, the rows are deleted. Leave it in and cancel works, // but if ok is clicked, it goes to /cms/scripts/delete-mult.php but it's just a blank white page, no errors, nothing. } -
2 problems. 1. There is no query string ($_GET) in your URL to NetWorkToolBox.php. 2. In the top script, you should call the function with echo PingTest(); Edit: I think you can fix #1 by making it. setInterval($(".ribbon-wrapper").load("php/NetWorkToolBox.php","FuncName=InternetAccessTest"),0);
-
Psycho went into great detail in his first reply. Please don't waste that post, as the info is very accurate. Follow the first example, marked by 1.(one), and it will work.
-
Or, you could just go back up to mine, because that is still wrong. //wrong banana LIKE = 'yes%'; //right banana LIKE 'yes%';
-
1.Make sure all string data is escaped using the mysqli class, PDO, mysqli_real_escape_string, or mysql_real_escape_string. Which ever database method you are using. 2.Make sure all integer, or float data is cast to the right data type with Converting to Integer, or Converting to Float. You could also return the form if the integer data was not of ctype_digit, if you are not using 2 above.
-
$result = mysql_query("SELECT * FROM tbl WHERE apple LIKE 'yes%' AND banana LIKE 'yes%' ")
-
That is no different than what he has currently. To the OP, you are overwriting your $location variable. Change the variable name that holds your GeoIP info, and echo the region using that variable. Then the button element should work. Don't forget to follow Xyph's advice, and turn on error_reporting and display_errors.
-
How many rows is the query returning?
-
Includes take a little overhead, but with the savings you have in de-bugging, or adding without sorting through 1 gigantic file it is worth it. Voting for smaller files.
-
mysql_fetch_array() expects parameter 1 to be resource, boolean given
jcbones replied to chrismcf's topic in PHP Coding Help
Sure: $sql = mysql_query("SELECT id, username, firstname FROM myMembers Where email_activated='1' ORDER BY RAND() LIMIT 9") or trigger_error(mysql_error()); -
Try this: (1 query) $sql = "SELECT f.f1,f.f2,p.fighter_id,p.winner FROM fights AS f JOIN betting AS p ON f.id = p.fight_id WHERE f.event='$viewevent' AND p.user_id='$user->id' ORDER by f.id ASC" $showevent = mysql_query($sql) or trigger_error(mysql_error());
-
No, I suppose (as most forums, chatboxes, or reply post do) you store a user_id to the post as well as the time posted. <?php $sql = "SELECT COUNT(id) FROM forum WHERE user_id = $current_user AND '00:00:30' > TIMEDIFF(NOW(),`timestamp_column`)"; //30 second control. $result = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($result) > 0) { exit(' You can only post 1 time per minute.'); }