?? Make sure fields are not blank?
06-03-2008, 11:39 PM
|
?? Make sure fields are not blank?
|
Posts: 715
Name: John
Location: United States of America, California
|
How do I verify that a user has filled in all of the fields and they are not blank?
I need to check the $title the $descr and the $src and the upload file field are not blank and if they are show an error message.
PHP Code:
<?php $filepath = '/home/forbushj/www/vidtemp/'; $filetypes = array('video/x-ms-asf', 'video/x-msvideo', 'video/x-flv', 'video/quicktime', 'video/mp4', 'video/mpeg', 'video/x-ms-wmv'); $title = addslashes($_GET['title']); $descr = addslashes($_GET['descr']); $src = addslashes($_GET['src']); // Check for errors: if ($uploaded_size > 350000) $error_msg .= 'Your file is too large.<br />'; if (!in_array($uploaded_type, $filetypes)) $error_msg .= 'You may only upload movies.<br />'; if ($error_msg) { echo $error_msg . 'Sorry your file was not uploaded'; } else if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { $file = $_FILES['uploaded']['tmp_name']; $ext = substr($file, ((strrpos($file, '.') !== false) ? strrpos($file, '.') : strlen($file)), strlen($file)); $filename = date('Y-m-d-H-i-s') . '_' . str_replace(' ', '_', basename($file, $ext)); $filename = preg_replace('/[\\\/:*?"<>|]/', '', $filename); if (is_file($filepath . $file)) { $output = array(); exec('ffmpeg -i "' . escapeshellarg($file) . '" -an -ss 00:00:03 -t 00:00:01 -r 1 -y -s 150x100 -f mjpeg "/home/forbushj/www/pic/video/' . escapeshellarg($filename) . '.jpg"', $output, $exit_code_pic); exec('ffmpeg -i "' . escapeshellarg($file) . '" -ar 22050 -ab 32 -f flv -s 320x240 "/home/forbushj/www/vidd/' . escapeshellarg($filename) . '.flv"', $output, $exit_code_vid); if (!is_array($output)) $error_msg = 'Sorry, there was a problem uploading your file.'; if ($exit_code) { error_log('ffmpeg exec returned ' . $exit_code); $error_msg = 'Sorry, there was a problem uploading your file.'; } if (!$error_msg) { mysql_connect("localhost", "REMOVED", "REMOVED") or die(mysql_error()); mysql_query(" INSET INTO forbushj_onetest.video (title, descr, pic, locat, src) VALUES ( '" . mysql_real_escape_string($title) . "', '" . mysql_real_escape_string($descr) . "', '" . mysql_real_escape_string($filename . ".jpg") . "', '" . mysql_real_escape_string($filename . ".flv") . "', '" . mysql_real_escape_string($src) . "' ) "); echo "upload successful"; } } else { $error_msg = 'Sorry, there was a problem uploading your file.'; } } else { $error_msg = 'Sorry, there was a problem uploading your file.'; } if ($error_msg) echo $error_msg; ?>
|
|
|
|
06-04-2008, 04:41 AM
|
Re: ?? Make sure fields are not blank?
|
Posts: 61
|
Code:
if (empty ($title)) {
echo 'ERROR: Title is empty!';
} else {
echo 'There are no errors';
}
Or
Code:
if ($title=='') {
echo 'ERROR: Title is empty!';
} else {
echo 'There are no errors';
}
Is that what you wanted?
|
|
|
|
06-04-2008, 04:45 PM
|
Re: ?? Make sure fields are not blank?
|
Posts: 715
Name: John
Location: United States of America, California
|
Sort of but how do I stop it from executing the rest of the script.
|
|
|
|
06-04-2008, 05:26 PM
|
Re: ?? Make sure fields are not blank?
|
Posts: 579
Name: Mike
Location: United Kingdom
|
Use the die functions.
PHP Code:
<?php if(1 == 2){ // Something is wrong die(); } ?>
__________________
Website Services
PHP Code:
if(Added_Talkupation($post) == TRUE){iHug($you);}
Last edited by rogem002 : 06-04-2008 at 05:27 PM.
|
|
|
|
06-04-2008, 06:22 PM
|
Re: ?? Make sure fields are not blank?
|
Posts: 61
|
PHP Code:
<?php $filepath = '/home/forbushj/www/vidtemp/'; $filetypes = array('video/x-ms-asf', 'video/x-msvideo', 'video/x-flv', 'video/quicktime', 'video/mp4', 'video/mpeg', 'video/x-ms-wmv'); $title = addslashes($_GET['title']); $descr = addslashes($_GET['descr']); $src = addslashes($_GET['src']); // Check for errors: if (!empty ($title) || !empty ($descr) || !empty ($src) || !empty ($_FILES['uploaded']['tmp_name'])) { if ($uploaded_size > 350000) $error_msg .= 'Your file is too large.<br />'; if (!in_array($uploaded_type, $filetypes)) $error_msg .= 'You may only upload movies.<br />'; if ($error_msg) { echo $error_msg . 'Sorry your file was not uploaded'; } else if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { $file = $_FILES['uploaded']['tmp_name']; $ext = substr($file, ((strrpos($file, '.') !== false) ? strrpos($file, '.') : strlen($file)), strlen($file)); $filename = date('Y-m-d-H-i-s') . '_' . str_replace(' ', '_', basename($file, $ext)); $filename = preg_replace('/[\\\/:*?"<>|]/', '', $filename); if (is_file($filepath . $file)) { $output = array(); exec('ffmpeg -i "' . escapeshellarg($file) . '" -an -ss 00:00:03 -t 00:00:01 -r 1 -y -s 150x100 -f mjpeg "/home/forbushj/www/pic/video/' . escapeshellarg($filename) . '.jpg"', $output, $exit_code_pic); exec('ffmpeg -i "' . escapeshellarg($file) . '" -ar 22050 -ab 32 -f flv -s 320x240 "/home/forbushj/www/vidd/' . escapeshellarg($filename) . '.flv"', $output, $exit_code_vid); if (!is_array($output)) $error_msg = 'Sorry, there was a problem uploading your file.'; if ($exit_code) { error_log('ffmpeg exec returned ' . $exit_code); $error_msg = 'Sorry, there was a problem uploading your file.'; } if (!$error_msg) { mysql_connect("localhost", "REMOVED", "REMOVED") or die(mysql_error()); mysql_query(" INSET INTO forbushj_onetest.video (title, descr, pic, locat, src) VALUES ( '" . mysql_real_escape_string($title) . "', '" . mysql_real_escape_string($descr) . "', '" . mysql_real_escape_string($filename . ".jpg") . "', '" . mysql_real_escape_string($filename . ".flv") . "', '" . mysql_real_escape_string($src) . "' ) "); echo "upload successful"; } } else { $error_msg = 'Sorry, there was a problem uploading your file.'; } } else { $error_msg = 'Sorry, there was a problem uploading your file.'; } if ($error_msg) echo $error_msg; } else { echo 'You must fill out all fields!'; } ?>
Should work.
|
|
|
|
06-04-2008, 07:34 PM
|
Re: ?? Make sure fields are not blank?
|
Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
|
I prefer exit; to stop code from being executed.
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-05-2008, 02:04 AM
|
Re: ?? Make sure fields are not blank?
|
Posts: 61
|
What if you want a file like a footer to be called under that script?
|
|
|
|
06-05-2008, 02:17 AM
|
Re: ?? Make sure fields are not blank?
|
Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
|
Do something like
PHP Code:
if(empty($variable)){echo "<p>Oh dear lord! This is FUBAR! I've reported your IP to the FBI for attempted hacking!</p>"; require_once('footer.php');exit;}
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-05-2008, 02:02 PM
|
Re: ?? Make sure fields are not blank?
|
Posts: 61
|
I guess that would work.
Either way though, it's not like they can bypass the if/else statement.
|
|
|
|
|
« Reply to ?? Make sure fields are not blank?
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|