Jump to content

etsted

Members
  • Posts

    274
  • Joined

  • Last visited

Posts posted by etsted

  1. I have live chat that is supposed to display the "sender" and the "message", but instead give me some weird result.

     

    script:

     

    function get_msg(){ global $con; $query = "SELECT Sender, Message FROM chat"; $run = mysqli_query($con, $query); $messages = array(); while($message = mysqli_fetch_assoc($run)){ $messages = array('sender' => $message['Sender'], 'message' => $message['Message']); } return $messages; }

     

    <div id="messages"> <?php $messages = get_msg(); foreach($messages as $sender => $message){ echo "Sender: " . $sender . "<br >"; echo "Message: " . $message . "<br />"; } ?></div>

     

    this is what it outputs:

     

    Message has been sent.

    Sender: senderMessage: hiSender: messageMessage: message

  2. this is a little reference from my live chat script, but it wont work. The error message is variable $con is not defined, but it is clearly defined.

     

    $con = mysqli_connect("localhost","root","123","chat") or die(mysqli_error($con));function get_msg(){ $query = mysqli_query($con, "SELECT Sender, Message FROM chat"); $run = mysqli_query($con, $query); $messages = array(); while($message = mysqli_fetch_assoc($run)){ $messages = array('sender' => $message['Sender'], 'message' => $message['Message']); } return $messages; }

  3. this is an animation script that works fine, but i notize that the init() function only works if the brackets are not included. Why?

     

    <html><head><title>JavaScript Animation</title><script type="text/javascript"><!--var imgObj = null;function init(){ imgObj = document.getElementById('myImage'); imgObj.style.position= 'relative'; imgObj.style.left = '110px';}function moveRight(){ imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';}window.onload =init ; // works

    window.onload = init(); // doesnt work//--></script></head><body><form><img id="myImage" src="smiley.gif" /><p>Click button below to move the image to right</p><input type="button" value="Click Me" onclick="moveRight();" /></form></body></html>

  4. this is a uploader script. in my phpmyadmin the image is stored in a type = blob.

    it works, the image is being uploaded to phpmyadmin, but i still get an error.

     

    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 '1' at line 1

     

    <?phpinclude "conn.php";$name = mysqli_real_escape_string($con, $_POST['name']);$details = mysqli_real_escape_string($con, $_POST['details']);$photo = addslashes(file_get_contents($_FILES['photo']['tmp_name']));$image = getimagesize($_FILES['photo']['tmp_name']);$imagetype = $image['mime'];echo "<br/>";$q = mysqli_query($con, "INSERT INTO animal VALUES('','$name','$details','$photo','$imagetype')") or die(mysqli_error($con));$r = mysqli_query($con, $q);if($r){ echo "information stored";}else{ echo mysqli_error($con);}?>

  5. Databases can save any type of data. The BLOB field stands for Binary Large OBject and can be used to store the contents of any file including image or video.

     

    Given that, I still find it preferrable to store file data in the filesystem rather than the database.

    do u mean in a folder?

  6. this is an uploading system from uploadify that i have tried to change so that i can pass inn information into the DB, but it wont work. Can somebody change it so that i would pass is data to a DB?

     

    <?php/*UploadifyCopyright © 2012 Reactive Apps, Ronnie GarciaReleased under the MIT License <http://www.opensource.org/licenses/mit-license.php>*/// Define a destination$targetFolder = '/uploads'; // Relative to the root$verifyToken = md5('unique_salt' . $_POST['timestamp']);if (!empty($_FILES) && $_POST['token'] == $verifyToken) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('jpg','jpeg','gif','png', 'MP4'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; }

     

    // my code below

    // this is my code below, but it only insert some data to the database, and gives no error away.

     

    include "../conn.php";if (!empty($_FILES) && $_POST['token'] == $verifyToken){ $name = $_FILES['file']['name']; $tmp = $_FILES['file']['tmp_name']; move_uploaded_file($tmp,"uploaded/".$name); $url = "localhost/uploaded/$name"; mysqli_query($con,"INSERT INTO video VALUES('','$name','$url')");}}?>

  7. when people upload image or video to my site, do i store them in any special type in phpmyadmin?

    are you supposed to use BLOB?

    What is BLOB?

    Which of them do i use? I would guess they can store different amount of data, how much do each of them store?

  8. is there any mediaplayer out there that i can use to upload videos to my website? not including jwplayer.

    please show link to tutorials as well.

  9. Does anyone know of a good videoformat uploader, such as jwplayer, that i can use on my website to allow users to upload video. I tried jwplayer but i got so many problems whit it, and i think its bad. Any suggestions?

  10. i made another session test file and it worked, but this doesnt seem to work, it doesnt store the session. can anyone tell me what wrong?
    <!DOCTYPE html><?php session_start();?>
    <html>
    <head>
    <meta charset="UTF-8" />
    <link href='style/style.css' rel='stylesheet' type="text/css" />
    <title>Login</title>
    <meta name='description' content='login to itsnature' />
    <meta name='keywords' content='login' />
    </head>
    <body>
    <h1>Login</h1>
    <?php
    require_once "connect.php";
    // login form
    $login = "<form action='login.php' method='POST' name='login1' class='forgotpass'>
    <input type='text' name='username' placeholder='Username' /> <br />
    <input type='password' name='password' placeholder='Password' />
    <input type='submit' name='submit' value='Login' /> |
    <a href='register.php'>Register</a>
    </form>";
    if(isset($_SESSION['username']))
    {
    $username = $_SESSION['username'];
    }
    // sets a navigator
    if(isset($username))
    {
    include "navigator/navigator_login.php";
    echo "hei";
    } else {
    include "navigator/navigator.php";
    echo "hei feil";
    }
    if(isset($username))
    {
    echo "<p>Welcome $username.</p> <br />";
    }
    else
    {
    if(isset($_POST['username']) && isset($_POST['password']))
    {
    $username = mysqli_real_escape_string($con, $_POST['username']);
    $password = mysqli_real_escape_string($con, $_POST['password']);
    }
    if(isset($username) && isset($password))
    {
    $password = md5($password);
    $query = mysqli_query($con ,"SELECT * FROM users WHERE username='$username' && password='$password'") or die(mysql_error());
    $numrows = mysqli_num_rows($query);
    if($numrows != 0)
    {
    $_SESSION['username']=$username;
    echo "<p>You have been logged in.</p> <br />";
    }
    else
    {
    echo "<p>Wrong password or username.</p>$login";
    }
    }
    else
    {
    echo "<p>You must register an account in order to login.</p>$login";
    }
    }
    mysqli_close($con);
    ?>
    </body>
    </html>
×
×
  • Create New...