Jump to content

Why Dosent This Work?


ColdEdge
 Share

Recommended Posts

Okay I am trying to make a script to add video details to the database by the site staff only, I coded a basic script that should do the work but the only thing that I dont know how to do is how to make it validate input as well as to make the the "vid" something like G6HJZ7 something like MegaVideo with its /v?=G65HFZ link style.Here is the code that I madevAdd.php Code

<?php$con = mysql_connect("localhost", "******_root", "**********");if(!$con)   {   die('Could not connect: ' . mysql_error());   }mysql_slect_db("******_yoko", $con);$sql="INSERT INTO doVideos (title, plot, tags, rating, video) VALUES ('$_POST['title']','$_POST['plot']','$_POST['tags']','$_POST['rating']','$_POST['video']')";if (!mysql_query($sql,$con))	{	die('Error: ' . mysql_error());	}echo "Information has been added";mysql_close($con)?>

Index.php Code

<html><body><form action="vAdd.php"  medthod="POST">Title: <input type="text" name="title" />Description: <input type="text" name="plot" />Tags: <input type="text" name="tags" />Rating: <input type="text" name="rating" />Video: <input type="text" name="video" /><input type="submit" value="Add" /></form></body></html>

This is the error I get with the vAdd.php[07-Aug-2009 22:24:39] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/******/public_html/otaku/vAdd.php on line 10An ones again how to make a it generate random vid? like ones again megavideo uses or megaupload for its files so my videos can run under /v directory under index.php file with ?=GH6J5Y-Thanks

Link to comment
Share on other sites

If you do want to reference an array index directly within a string literal, use braces:

"string with {$array['index']}";

Link to comment
Share on other sites

I fixed the first part vAdd.php with this code

$sql="INSERT INTO doVideos (title, plot, tags, rating, video) VALUES ('".$_POST['title']."','".$_POST['plot']."','".$_POST['tags']."','".$_POST['rating']."','".$_POST['video']."')";

Now the only part that I do not know how to do is generate a random key for the video like GH5HJ6 which can be called by the index.php later on

Edited by ColdEdge
Link to comment
Share on other sites

Is this any help

function generaterandomkey(){$chars = "0123456789abcdefghijklm0123456789nopqrstuvwxyz0123456789";srand((double)microtime()*1000000);$i = 0;$pass = '';while ($i <= 60) {   $num = rand() % 33;   $tmp = substr($chars, $num, 1);   $pass = $pass . $tmp;   $i++;  }return $pass;}

Link to comment
Share on other sites

You can either rename the video or add another field to your database that contains the key and then call that field to obtain the correct video. You would then be able to use a GET link like ?=GH6J5Y where the variable GH6J5Y was used in a mysql SELECT to select the relevant video

Link to comment
Share on other sites

So is this how the code has to look like?

<?php$title=$_POST['title'];$plot=$_POST['plot'];$tags=$_POST['tags'];$rating=$_POST['rating'];$video=$_POST['video'];$con = mysql_connect("localhost", "*******_root", "*******");if(!$con)   {   die('Could not connect: ' . mysql_error());   }mysql_slect_db("******_yoko", $con);$sql="INSERT INTO doVideos (title, plot, tags, rating, video) VALUES ('".$_POST['title']."','".$_POST['plot']."','".$_POST['tags']."','".$_POST['rating']."','".$_POST['video']."')";function generaterandomkey()$chars = "0123456789abcdefghijklm0123456789nopqrstuvwxyz0123456789";srand((double)microtime()*1000000);$i = 0;$pass = '';while ($i <= 60){   $num = rand() % 33;   $tmp = substr($chars, $num, 1);   $pass = $pass . $tmp;   $i++;  }return $pass;if (!mysql_query($sql,$con))	{	die('Error: ' . mysql_error());	}echo "Information has been added";mysql_close($con)?><html><body><form action="vAdd.php"  medthod="POST">Title: <input type="text" name="title" />Description: <input type="text" name="plot" />Tags: <input type="text" name="tags" />Rating: <input type="text" name="rating" />Video: <input type="text" name="video" /><input type="submit" value="Add" /></form></body></html>

I am still getting an error[09-Aug-2009 12:51:47] PHP Fatal error: Call to undefined function mysql_slect_db() in /home/*******/public_html/otaku/vAdd.php on line 13

Link to comment
Share on other sites

The key code is a function so you need to call the function.

function generaterandomkey(){$chars = "0123456789abcdefghijklm0123456789nopqrstuvwxyz0123456789";srand((double)microtime()*1000000);$i = 0;$pass = '';while ($i <= 60){   $num = rand() % 33;   $tmp = substr($chars, $num, 1);   $pass = $pass . $tmp;   $i++;  }return $pass;}$generatedkey = generaterandomkey();

Link to comment
Share on other sites

  • 3 weeks later...

I still dont get it what I have to do, I tryed many simple insert scripts but for some od reason nothing is ever added into MySQL table doVideos all I want to add isVideo Title: Video Ep: Video URL: The videos are stored on 3rd party sites like megavideo, myspace and ect when inserting value the value is direct access to the .flv fileVideo Tags: this is used by the search scriptVideo Description: just a simple 250 charecter description.and the ability to make the videos be avaible truth /-task/series/?=GH78HJKwhen member is pointed to that location the rest of the info will be called likeTitle, Ep # so ex; Shakugan no Sahan Episode 1 will show up, and under it the video will be avaible with <object> coding. And under thouse you will see Views: 124256Please help me with this two things. please i tryed everything and i can get anything to work.... please very please help me put this together....

Link to comment
Share on other sites

This is basic PHP stuff, if you don't understand go through the tutorial about using functions with PHP. All you need to do is define the function, and then run it. That's something you should understand how to do, so instead of people posting code for you to try just go read the function tutorial and then come back and look at the code again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...