Jump to content

etsted

Members
  • Posts

    274
  • Joined

  • Last visited

Posts posted by etsted

  1. this is the script that takes in several post elements

     

    $errors = array(); if(empty($_POST['to'])) { $errors = "fill out the to input<br>"; } else if( preg_match("%^[a-z, 0-9]+$%i", $_POST['to']) == 0) { $errors = "the list of names you gave is not valid<br>"; } else { // seperate each user by the "," $user_name = explode(",", $_POST['to']); // trim each user for extra white space foreach($user_name as &$name) { $name = trim($name); }

     

    // this is the function that goes wrong $user_ids = fetch_user_id($user_name); if(count($user_ids) != count($name) ) { $errors = "the following user could not be found " . implode(', ', array_diff($user_name, array_keys($user_ids) ) ) . "<br>"; } } if(empty($_POST['subject'])) { $errors .= "fill out the subject input <br>"; } if(empty($_POST['body'])) { $errors .= "fill out the body input <br>"; } if ( isset($errors) ) { if ( empty($errors) ) { echo "<div class='msg success'> your message has been sent <a href='index2.php?page=inbox'>Return to your inbox</a> </div>"; } else { echo "<div class='msg error'>" . $errors . "</div>"; } }

     

    and here is the function i have set

     

    // check to see if multiple users existfunction fetch_user_id($user_name){ global $con; foreach ($user_name as &$name) { $name = mysqli_real_escape_string($con, $name); } $sql = "SELECT user_id, user_name FROM users WHERE user_name IN ('". implode("','", $user_name) ."')"; $result = mysqli_query($con, $sql); $names = array(); while ( ($row = mysqli_fetch_assoc($result)) != false) { $names[$row['user_name']] = $row['user_id']; } return $names;}

     

    the script i have at top i supposed to display any person that was typed in to the $_POST['to'] variable, that does not exist in the DB, on to the screen. If i type in a user that does not exist, then the correct error message is displayed, but as soon as i type in a user that does exist, it displays a message telling me that "your message has been sent", which is what it is not supposed to do

  2. i am having trouble with uploadify script.

     

    this lais inside uploadify/uploads.php

     

    $verifyToken = md5('unique_salt' . $_POST['timestamp']);if (!empty($_FILES) && $_POST['token'] == $verifyToken) { $tempFile = $_FILES['Filedata']['tmp_name']; // this makes every file name unique $fileName = $_FILES['Filedata']['name']; $kaboom = explode(".",$fileName); $ext = ""; $ext = end($kaboom); $ext = strtolower($ext); $fileName = date("YmdjzHhisu") . rand(10000000,99999999) . ".$ext"; // defines what the ext can be $imageTypes = array('jpg','jpeg','gif','png'); $videoTypes = array('mp4','webm','ogg'); $audioTypes = array('mp3','ogg','wav'); $tittel = $_POST['tittel']; $description = $_POST['description']; $username = $_POST['username']; // include DB connection include_once ("../connect.php"); // use the pathinfo to match the ext of the uploaded file $fileParts = pathinfo($_FILES['Filedata']['name']); $fileParts = $fileParts['extension']; $fileParts = strtolower($fileParts); if (in_array($fileParts,$imageTypes)) { // this is for images // insert into DB $sql = "INSERT INTO images VALUES('', '$tittel', '$description', '$username', '$fileName' , NOW())"; $query = mysqli_query($con, $sql); move_uploaded_file($tempFile, "u_image/" . $fileName); echo '1'; } else if(in_array($fileParts, $videoTypes)){ // this is for videos // insert into DB $sql = "INSERT INTO videos VALUES('', '$tittel', '$description', '$username', '$fileName' , NOW())"; $query = mysqli_query($con, $sql); move_uploaded_file($tempFile, "videos/" . $fileName); echo '1'; } else if(in_array($fileParts,$audioTypes)){ // this is for audios // insert into DB $sql = "INSERT INTO mp3 VALUES('', '$tittel', '$description', '$username', '$fileName' , NOW())"; $query = mysqli_query($con, $sql); move_uploaded_file($tempFile, "audio/" . $fileName); echo '1'; } else { echo "Invalid file."; }}?>

     

    i have tried to copy everything to another file, then make a temporary form tag within that file, and it worked, what am i missing out here? And i doesnt display any errors

     

    the input form i am currently using: uploads.php

     

    <?php

     

    // this is the upload form $uploadForm = "<h1>Upload</h1>"; $uploadForm .= "<form action='' method='post' id='uploadForm' enctype='multipart/form-data'>"; $uploadForm .= "Tittel: <input type='text' name='tittel' size='55' id='tittel'> <br>"; $uploadForm .= "Description: <textarea rows='5' id='description' cols='55' name='description'></textarea> <br><br>"; $uploadForm .= "<input style='display:none;' type='text' name='username' id='username' value='$u'>"; $uploadForm .= "<div id='queue'></div>"; $uploadForm .= "<input id='file_upload' name='file_upload' type='file'>"; $uploadForm .= "</form>";

     

    ?>

     

    <head>

     

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> <script src="uploadify/jquery.uploadify.min.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="uploadify/uploadify.css"> <style type="text/css"> body { font: 13px Arial, Helvetica, Sans-serif; } #uploadForm > #tittel{ margin-left: 37px; } </style> <script type="text/javascript"> <?php $timestamp = time();?> $(function() { $('#file_upload').uploadify({ 'formData' : { 'timestamp' : '<?php echo $timestamp;?>', 'token' : '<?php echo md5('unique_salt' . $timestamp);?>' }, 'multi' : false, 'swf' : 'uploadify/uploadify.swf', 'uploader' : 'uploadify/uploads.php', 'onUploadStart' : function(file) { $("#file_upload").uploadify("settings", "formData", {"tittel": $("#tittel").val(), "description": $("#description").val(), "username": $("#username").val()} ); }, 'debug' : true }); }); </script>

     

    </head>

     

    <div style="margin-left:30%;"><?php echo $uploadForm;?></div>

  3. if(isset($_GET['submit']) && !empty($_GET['s']) OR !empty($_GET['pn']) ) { include_once ("connect.php"); // this contains the information the user has typed in $search = trim($_GET['s']); $search = mysqli_real_escape_string($con, $search); // this is the table the user wishes to do a search in $type = preg_replace("%[^a-z0-9]%i", "", $_GET['type']); if(!preg_match("%(images|mp3|videos|register)%", $type)) { echo "something went wrong"; exit; } // searches for a macht in the DB, with what the user typed in, and selected //makes sure that only u_name is present, when the user selects the register type, bcz the register table should only search for usernames function which_type($type, $search){ if($type == "register") { // if the selected type was register $sqlCommand = "SELECT * FROM $type WHERE u_name LIKE '%$search%' "; } else { // if the selected type was not equal to register $sqlCommand = "SELECT * FROM $type WHERE description LIKE '%$search%' OR username LIKE '%$search%' OR tittel LIKE '%$search%' "; } return $sqlCommand; } // this will register what the selected type was from the search bar $sqlCommand = which_type($type, $search); // check to see if there are any results in the DB $query = mysqli_query($con, $sqlCommand) or die(mysqli_error($con)); $count = mysqli_num_rows($query); if($count > 1){

    // okey procced

    } else {

    // something went wrong

    }

     

    }

     

    when i select a type that is not equal to "register" and search something from the DB, i get files displayed from the DB

    and when i echo the sql result, it looks like this

    SELECT * FROM images WHERE description LIKE '%g%' OR username LIKE '%g%' OR tittel LIKE '%g%'

     

    but if i were to select "register", then the "else statement" will display telling me "no resulst were found" even though i have searched something from the DB

  4. i want the divs to be stacked vertically in a straight line, so when the line they are on doesnt have any more room, they will jump down to the next line, but insted of stacking in a straight vertical line the somehow go down, little by little, i mean the first divs has the right position, but then the next div will start at a position 20 extra px from the top, then the div after that will start at 40 extra px from the top, and so on

  5. i want "tittel LIKE '%$search%' OR" to be a part of the $sql statement if the $type variable of the "which_type" function is not equal to register. The error i get when i try to run this script is:

     

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') { tittel LIKE '%g%' OR } ' at line 2

     

    So im guessing that it is not recieving the input from the $search variable, but i dont know why.

     

     

    $sqlCommand = "";

     

    $type = $_GET['type']; // stores the selected type, from a select drop down box

    $search = $_GET['s']; // stores the input, the user has typed in // this contains the information the user has typed in $search = trim($_GET['s']); $search = mysqli_real_escape_string($con, $search); // this is the table the user wishes to do a search in $type = preg_replace("%[^a-z0-9]%i", "", $_GET['type']); if(!preg_match("%(images|mp3|videos|register)%", $type)) { echo "something went wrong"; exit; } // searches for a macht in the DB, with what the user typed in function which_type($type, $search){ $sqlCommand = "SELECT * FROM $type WHERE if($type != 'register') { tittel LIKE '%$search%' OR } description LIKE '%$search%' OR username LIKE '%$search%'"; return $sqlCommand; } $sqlCommand = which_type($type, $search); $query = mysqli_query($con, $sqlCommand) or die(mysqli_error($con));

  6. <div id="middleDiv"><div><h2>images files: <strong>8</strong></h2><p style='border:2px red solid;'>page <strong>1</strong> of <strong>1</strong></p><div class='files' id='file_10'><a href='watch.php?f=C:/wamp/www//u_image/2014042727116170529180000006231689.MP4'><img src='images/avatardefault.png' height='60' width='60' alt='123'> Click here</a><br><span style=' text-overflow:ellipsis; '>Tittel: 123</span><br><span>Uploaded by: <a href='user.php?u=george'>george</a></span><br><br><div style='width: 298px; text-overflow:ellipsis;'>Description: ewq</div><br><span >Upload date: 2014-04-27</span><br><br></div><br> <br><div class='files' id='file_11'><a href='watch.php?f=C:/wamp/www//u_image/2014042727116180632040000003145629.png'><img src='images/avatardefault.png' height='60' width='60' alt=''> Click here</a><br><span style=' text-overflow:ellipsis; '>Tittel: </span><br><span>Uploaded by: <a href='user.php?u=george'>george</a></span><br><br><div style='width: 298px; text-overflow:ellipsis;'>Description: </div><br><span >Upload date: 2014-04-27</span><br><br></div><br> <br><div class='files' id='file_12'><a href='watch.php?f=/u_image '><img src='images/avatardefault.png' height='60' width='60' alt=''> Click here</a><br><span style=' text-overflow:ellipsis; '>Tittel: </span><br><span>Uploaded by: <a href='user.php?u=george'>george</a></span><br><br><div style='width: 298px; text-overflow:ellipsis;'>Description: </div><br><span >Upload date: 2014-04-29</span><br><br></div><br> <br><div class='files' id='file_13'><a href='watch.php?f=/u_image '><img src='images/avatardefault.png' height='60' width='60' alt=''> Click here</a><br><span style=' text-overflow:ellipsis; '>Tittel: </span><br><span>Uploaded by: <a href='user.php?u=george'>george</a></span><br><br><div style='width: 298px; text-overflow:ellipsis;'>Description: </div><br><span >Upload date: 2014-04-29</span><br><br></div><br> <br><div class='files' id='file_14'><a href='watch.php?f=/u_image '><img src='images/avatardefault.png' height='60' width='60' alt=''> Click here</a><br><span style=' text-overflow:ellipsis; '>Tittel: </span><br><span>Uploaded by: <a href='user.php?u=george'>george</a></span><br><br><div style='width: 298px; text-overflow:ellipsis;'>Description: </div><br><span >Upload date: 2014-04-29</span><br><br></div><br> <br><div class='files' id='file_15'><a href='watch.php?f=Array'><img src='images/avatardefault.png' height='60' width='60' alt=''> Click here</a><br><span style=' text-overflow:ellipsis; '>Tittel: </span><br><span>Uploaded by: <a href='user.php?u=george'>george</a></span><br><br><div style='width: 298px; text-overflow:ellipsis;'>Description: </div><br><span >Upload date: 2014-04-29</span><br><br></div><br> <br><div class='files' id='file_16'><a href='watch.php?f=/u_image/20140429291181212413500000075324707.gif'><img src='images/avatardefault.png' height='60' width='60' alt=''> Click here</a><br><span style=' text-overflow:ellipsis; '>Tittel: </span><br><span>Uploaded by: <a href='user.php?u=george'>george</a></span><br><br><div style='width: 298px; text-overflow:ellipsis;'>Description: </div><br><span >Upload date: 2014-04-29</span><br><br></div><br> <br><div class='files' id='file_17'><a href='watch.php?f=C:/wamp/www//u_image/20140429291181212520300000080238342.png'><img src='images/avatardefault.png' height='60' width='60' alt=''> Click here</a><br><span style=' text-overflow:ellipsis; '>Tittel: </span><br><span>Uploaded by: <a href='user.php?u=jacop'>jacop</a></span><br><br><div style='width: 298px; text-overflow:ellipsis;'>Description: </div><br><span >Upload date: 2014-04-29</span><br><br></div><br> <br><div></div></div></div>
  7. i validted the json code, and it had no errors, but i still get 4 errors when i run the code.

     

    TypeError: vendor is undefined hotels.php:1174

    The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range.

    The character encoding of the page must be declared in the document or in the transfer protocol. json_tutorial.htmlTypeError: results is undefined json_tutorial.html:19TypeError: vendor is undefined

     

     

    my json_script.htm

     

    <!DOCTYPE html><html><head><script type="text/javascript">function ajax_get_json() {var results = document.getElementById("results"); var hr = new XMLHttpRequest(); hr.open("GET", "mylist.json", true); hr.setRequestHeader("Content-type", "application/json", true); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var data = JSON.parse(hr.responseText); var results = document.getElementById(data); console.log(data); results.innerHTML = data.user; } } hr.send(); results.innerHTML = "requesting...";}</script></head><body><div id="results"></div><script type="text/javascript">ajax_get_json();</script></body></html>

     

     

    my mylist.json

     

    { "user":"John", "age":"22", "country":"United States" }

  8. my keeps staking oblique, any special reasion?

     

    $files .= "<div class='files' id='file_".$id."'>n <a href='watch.php?f=$file_url'><img src='$avatar' height='60' width='60' alt='$tittel'> Click here</a> <br> <span style=' text-overflow:ellipsis; '>Tittel: $tittel</span>n <br> <span>Uploaded by: <a href='user.php?u=$username'>$username</a></span> <br><br> <div style='width: 298px; text-overflow:ellipsis;'>Description: $description</div>n <br> <span >Upload date: $upload_date</span> <br> <br> </div>n <br> <br>n";

     

     

    <style type="text/css"> .files{ float: left; width:200px; } /* style the links inside where we store the files */ .files > a{ color: #004000; text-decoration: none; } .files > span > a{ color: #004000; text-decoration: none;margin-left: 10px; } </style>

     

     

    <p><?php echo $files;?></p>

    php

    $username = $row['u_name']; $avatar = $row['avatar']; $gender = $row['gender']; $lastlogin = $row['lastlogin'];

     

    // count all of their videos, images and audios function select_images($tabell){ global $username; $sql = "SELECT COUNT(id) FROM $tabell WHERE username='$username'"; } $num_images = select_images("images");

     

    causes Cannot redeclare select_images() (previously declared in C:wampwwwsearch.php:165)

  9. this div "<div style='border:1px red solid;width: 298px; text-overflow:ellipsis;'>Description: $description afdfdsafdasfdsdafdfdsdddfssdffdsdfsdfdfsfdsafdsdfddsf</div>" will only make the tekst go beyond the border, instead of starting on a new line

  10. when content overflows a div i want i text to be able to be able to continue on the next line automaically if the width of the div is to small. I am not talking about the overflow property.

  11. this audio tag keeps duplicating my mp3 files

     

    $mp3 = ""; // get all the mp3 files from the DB $sql = "SELECT * FROM mp3"; $query = mysqli_query($con, $sql); while($row = mysqli_fetch_array($query) ) { $id = $row['id']; $tittel = $row['tittel']; $description = $row['description']; $username = $row['username']; $file_url = $row['file_url']; $upload_date = $row['upload_date']; $mp3 .= "<audio width='320' height='240' controls>n <source src='$file_url' type='audio/mpeg'>n </audio>n"; echo "$mp3"; }

     

    i only have 4 mp3 files in the DB, but wheni run this code it shows me 10 different mp3 files, i have checked the file source, and the print_r, but there is nothing wrong, i think, it just stands that some of my mp3 are being duplicated, why?

  12. any reason to why json wont work localy or on my server?

     

    i am trying this code:

     

    // this is my json_script.htm

     

    <!DOCTYPE html><html><head><script type="text/javascript">function ajax_get_json(){var results = document.getElementById("results"); var hr = new XMLHttpRequest(); hr.open("GET", "mylist.json", true); hr.setRequestHeader("Content-type", "application/json", true); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var data = JSON.parse(hr.responseText); results.innerHTML = ""; var results = document.getElementById("results"); results.innerHTML = data.user; } } hr.send(null); results.innerHTML = "requesting...";}</script></head><body><div id="results"></div><script type="text/javascript">ajax_get_json();</script></body></html>

     

     

    // this is my mylist.json

     

    { "user":"John", "age":22, "country":"United States" };

  13. // this is how i get the files from the DB

    $mp4 = ""; // get all the mp3 files from the DB $sql = "SELECT * FROM mp3"; $query = mysqli_query($con, $sql); while($row = mysqli_fetch_array($query) ) { $id = $row['id']; $tittel = $row['tittel']; $description = $row['description']; $username = $row['username']; $file_url = $row['file_url']; $upload_date = $row['upload_date']; $mp4 .= "<video width='320' height='240' controls>n"; $mp4 .= "<source src='$file_url' type='audio/mpeg'>n"; $mp4 .= "</video>n"; }

     

    // the url from the DB look like this

    videos/2014042727116180637260000009088958.mp4

     

    // this is how the echo part look like

     

    <div><?php echo $show;?></div>

×
×
  • Create New...