Jump to content

Not pulling information from one page to another <form>


Collegeboox

Recommended Posts

Below are two pages...Post.php. and Posted.php the posted page checks and makes sure everything is filled out and makes sure that the link has not been already added. The problem I am having is that it is not pulling over the link information. Every time you hit submit it drops down and goes to saying that you forgot to fill something in and I have it showing everything right now so when that happens I can see what is not going through and the $link never comes through. Any ideas? if anyone needs a better explanation please post and I will try to explain better....basically I am trying to post and everything posts but the link.

 

POST.PHP

				<h1>Post</h1>
			<div class="descr"></div><form method="post" action="posted.php">
          <table align="center">
			<tr>
            		<td>
                   		Youtube Embed Link
                    </td>
                    <td>
                    	<input name="link" type="text" id="link"/>
                    </td>
                </tr>    
                <tr>
                	<td>
                  	 	Title Of Song
                    </td>
                    <td>
                    	<input name="title" type="text" id="title" />
                    </td>
                </tr>
                <tr>
                	<td>
                   		Author
                    </td>
                    <td>
                    	<input name="author" type="text" id="author" />
                    </td>
                </tr> 
                <tr>
            		<td>
                    	Text:
                    </td>
                    <td>
                    	<input name="information" type="text" id="information" />
                        <br />
                    </td>
                </tr>
                <tr>
                	<td colspan="2" align="center">
                    <br>
                    	<input name="submit" type="submit" value="Post" />
                    </td>
                </tr>               
            </table>
            </form>

 

POSTED.PHP

<?php
//msut be logged in page
session_start();

if  ($_SESSION['username'])
{
echo"";
}
else
die("You must log in first!");

//form information
$submit = $_POST['submit'];
$row4 = $_SESSION['username'];

// form data
$link = strip_tags($_POST['link']);
$information = strip_tags($_POST['information']);
$title = strip_tags($_POST['title']);
$author = strip_tags($_POST['author']);
$date = date('Y-m-d');


			 //Connect To Database
			$hostname='';
			$username2='';
			$password2='';
			$dbname='';

				mysql_connect($hostname,$username2, $password2) OR DIE ('Unable to connect to database! Please try again later.');
			mysql_select_db($dbname);
			$querycheck = "SELECT * FROM videos WHERE username='$row4'";
			$result = mysql_query($querycheck);
			while($rowz = mysql_fetch_array($result))

$linkcheck = $rowz['link'];


if ($submit)
{
if ($link&&$information&&$title&&$author)
	{
		if ($link == $linkcheck)
		{
			die ("This link has already been posted.");
		}
		else

			{


			 //Connect To Database
			$hostname='';
			$username2='';
			$password2='';
			$dbname='';

			 mysql_connect($hostname,$username2, $password2) OR DIE ('Unable to connect to database! Please try again later.');
			mysql_select_db($dbname);
			$queryreg = mysql_query("INSERT INTO videos Values ('','$row4','$link','$title','$author','$information','$date')");




			}
	}	

else
	{
		die ("You forgot to put something in the link/title/author/text box.  $information $title $link $author");
   		 }

}


		   


?>

 

Link to comment
Share on other sites

You don't need to connect to a database twice.  Once you're connected, the connection stays open until the script ends, you manually close it, or you attempt to open another connection and you don't specify to keep the current one open.

 

Similarly, you don't need a while-loop if you're only retrieving a single row of data.  The entire point of loops is to iterate over multiple items.  You also neglect to put brackets in the loop anyway.

 

Ultimately, you need to do some bare bones basic debugging.  That means turning on error reporting by putting the following at the top of your files:

 

ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);

 

which will display all errors, warnings, and notices when things break.  That will help you narrow down your problems.

 

You also need to escape your incoming string (read: text) data.  Stripping tags does nothing to protect your database from injection attacks.  mysql_real_escape_string - learn it, use it, love it.

Link to comment
Share on other sites

This is what is being inputted in link line...

 

<object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/watch?v=NhO-tTsxVso?version=3&feature=player_embedded"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/watch?v=NhO-tTsxVso?version=3&feature=player_embedded" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></object>

Link to comment
Share on other sites

It's one giant tag, so strip_tags() removes it entirely. There is no reason to use strip_tags() on data simply to insert it in a database. If you're thinking it's protecting you from SQL injection, it isn't. That code is wide open to injection. You should be validating and escaping or casting data before using it in a query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.