Jump to content

kenrbnsn

Staff Alumni
  • Posts

    8,234
  • Joined

  • Last visited

Everything posted by kenrbnsn

  1. No, the return statement in the function ends the execution of the function. You check the validity of the email address by calling the function: <?php function checkEmail($email){ return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE; } $email_to_check = 'some@email.address.com'; if (!checkEmail($email_to_check)) { echo 'the email address is not correct'; } ?> Ken
  2. Why don't you post what's in your script, so we see what you're really trying to run. Ken
  3. That error is not saying that the array is empty, but that the variable is not an array, so before you do the merge, check to see if the variable is an array and make it an array if it's not: <?php $ary1 = (is_array($ary1))?$ary1:array($ary1); $ary2 = (is_array($ary2))?$ary2:array($ary2); $ary3 = array_merge($ary1,$ary2); ?> Ken
  4. Please post your code. You may have mis-typed my code. Ken
  5. Which code gives you the error & on which line? My suggested code snippet is error free. Ken
  6. To fix the code, you have to tell PHP where to find the value. Since it's coming from the URL, the value will be in the $_GET array: <?php // if topic selected, display the relevant content. if ($_GET['topic'] == 'page1') { include ("{$_GET['topic']}.php"); } elseif ($topic == 'page2') { include ("{$_GET['topic']}.php"); } // else wrong or no link selected. else { print "Go to the <A HREF = 'main.php'>Main page</A>"; } ?> But, I would re-write it as: <?php // if topic selected, display the relevant content. $valid_pages = array('page1','page2'); if (in_array($_GET['topic'],$valid_pages)) { include("{$_GET['topic']}.php"); } // else wrong or no link selected. else { print "Go to the <A HREF = 'main.php'>Main page</A>"; } ?> Ken
  7. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330652.0
  8. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=330649.0
  9. If you only want records where the username & password match those in the DB, do that via the query: <?php $query = "SELECT username, password FROM userTable where username='$username' and password='$password'"; ?> This assume that the values of $username & $password have been properly sanitized. Ken
  10. What are you trying to accomplish with this code? Ken
  11. When posting code, please surround the code with tags not tags. Ken
  12. You can either make your image in to a submit button or use Javascript/AJAX to submit the for when the link is clicked. Ken
  13. You can either use the glob function which returns the files already sorted, or put the files into an array and sort that array before generating the HTML. Something like: <?php $dir="/backup/Movies"; $files = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php") { $files[] = $file; } } closedir($handle); } sort($files) ?> <form action="listen.php" method="post" name="table"> <select name="Movie"> <p> <?php $tmp = array(); foreach ($files as $file) { $tmp[] = "<option value='$file'>$file</option>"; } echo implode("\n",$tmp) . "\n"; ?> </p> </select> </form> As for your other question, use 2 arrays and put the files in one array and the directories in the other array. Sort each array and then output the contents. Ken
  14. You're missing the parenthesis that enclose the entire "if" condition: <?php if((!isset($_POST['name']))||(empty($_POST['name']))||(trim($_POST['name']) == "")){echo "Please Provide your Name.";} // just making sure something is posted with the form ?> Ken
  15. You don't have any form tags in the form like "<input>" or "<textarea>". What are you trying to do? This is more of a general HTML question, since there is no PHP in the code at all. Ken
  16. How are you invoking your script? You need to use a URL like http://localhost/path/to/your/script.php Ken
  17. Actually, I almost missed seeing the original brackets and was about to say that you had the correct syntax... Ken
  18. Actually it's <?php $array = explode(" ", $query); echo $array[0]; // 10 echo $array[1]; // 14 echo $array[2]; // 52 ?> Ken
  19. Did you check to see what's in $_SERVER['HTTP_REFERER']? <?php echo '<pre>' . print_r($_SERVER,true) . '</pre>'; ?> It's very unlikely that the other site worked fine with that code. Ken
  20. Don't worry about it. I make the same mistake all the time... Ken
  21. You're missing a ")" on this line (line 41): <?php if(!isset($error) ?> it should be <?php if(!isset($error)) ?> Ken
  22. No, the location in the header goes to a different URL. The reason the message isn't showing up is that you're not passing any value via the URL, so there's nothing in the $_REQUEST['URL']. You probable want to use $_SERVER['HTTP_REFERER']. Echo it first to see what it is. Or put a value on the URL in the header: <?php header("Location: a_Photo_Edit.php?URL=a_Photo_Delete.php"); exit(); ?> Ken
  23. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330364.0
  24. You're always overwriting the value of $Chords_Loops_Lyrics in the loop. Change your code to <?php $Chords_Loops_Lyrics = array(); $result = mysql_query("SELECT * FROM Chords_Loops_Lyrics ORDER BY MusicFiles_ID ASC"); while($row = @mysql_fetch_array($result)){ $Chords_Loops_Lyrics[] = array($row['CCL_ID'] => $row['MusicFiles_ID'], $row['Type'], $row['FileName']); } ?> Or <?php $Chords_Loops_Lyrics = array(); $result = mysql_query("SELECT * FROM Chords_Loops_Lyrics ORDER BY MusicFiles_ID ASC"); while($row = @mysql_fetch_array($result)){ $Chords_Loops_Lyrics[$row['CCL_ID']] = array($row['MusicFiles_ID'], $row['Type'], $row['FileName']); } ?> Try it both ways and see which resultant array is easier to use. Ken
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.