Title only showing first word once sent to database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

Title only showing first word once sent to database

Post by Smudly »

Users can type in a url in my form, along with a title for that url (anything they want). For the title however, once it is stored into the database, all that is shown is the first word. How can I fix this?

This is what my code looks like:


$title = str_replace(' ','%20',$title);
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Title only showing first word once sent to database

Post by requinix »

I'd hardly think we could diagnose the problem given one line of code.

What is the code used to print out the title?
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

Re: Title only showing first word once sent to database

Post by Smudly »

Here are the two pages of code. Hopefully this gives a better idea of what is going on.

// sites.php //

Code: Select all

<?php
session_start();



$submit = $_POST['submit'];

$title = $_POST['title'];
$title = str_replace(' ','%20',$title);
$url = strip_tags($_POST['url']);
$credits = strip_tags($_POST['credits']);



//////////////////////////////

if ($submit)
{

	include('inc/connect.php');

	$userid = $_SESSION[userid];
	

  
	
	// Check if URL is Valid
	if (preg_match("/^(http(s?):\/\/|ftp:\/\/{1})((\w+\.){1,})\w{2,}$/i", $url)) {
            
              //Check if URL is a Duplicate for current user			
			$results = mysql_query("SELECT * FROM `websites` WHERE `userid`='$userid' AND `url`='$url'");
                        $rows = mysql_num_rows($results);


			if ($rows<=0)
			{
				
				//mysql_query("INSERT INTO websites VALUES ('','$userid','$url','$credits','','','','$title')") or die("Error submitting url, try again");
                                //echo "Your Site Has Been Submitted";
                                header("Location: confirmsite.php?url=$url&credits=$credits&title=$title");
                                exit();
				 
			}
			else{
				echo "You have already submitted that site";
			}
		}
	else {
		echo "Invalid URL";
		}
}

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/sites.css" />
</head>
<body>

<form action="sites.php" method="POST">
      <div id="sites">
           URL: <input type="text" name="url" value="http://"><br />
           Title: <input type="text" name="title" maxlength="60" value="<?php echo $title ?>"><br />
           Max Views Daily: <input type="text" maxlength="11" name="credits" value="<?php echo $credits ?>"><br />

           <input type="submit" name="submit" value="Submit Site">
           
      </div>
</form>

</body>
</html>

// confirmsite.php //

Code: Select all

<?php
session_start();
$url = $_GET['url'];
$confirm = $_GET['confirm'];
$credits = $_REQUEST['credits'];
$title = $_REQUEST['title'];


if (isset($confirm)){
include('inc/connect.php');

$queryconfirm = mysql_query("INSERT INTO websites VALUES ('','$_SESSION[userid]','$url','$credits','','y','','$title')") or die("Error submitting url, try again");
echo "<meta http-equiv=\"refresh\" content=\"0;url=sites.php\">";
exit;

}


?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/surfbar.css" />
<title>Confirm Website</title>
<script type="text/javascript">

var time = 10;

function startCountdown(){
    var t = setTimeout("countdown()", 1000);
}

function countdown(){
var uRl = "<?php echo $url;?>";
var cRedits = "<?php echo $credits;?>";
var tItle = "<?php echo $title;?>";

    --time;
    if(time == 0){
        document.getElementById("countdown").innerHTML = "<a href=?confirm&url=<?php echo $url;?>&credits=<?php echo $credits;?>&title=<?php echo $title;?> name=confirm>Confirm</a>";

    }else{
        document.getElementById("countdown").innerHTML = time;
        var t = setTimeout('countdown()', 1000);
    }
}
</script>

</head>
<body onload="startCountdown();">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<?php

echo "<tr><td style=\"background:#333333;height:80px;border-bottom:#aaaaaa solid 2px;\">";
include('confirmbar.php');
echo "</td></tr>";
?>

<tr><td>
<iframe src="<?php echo $url;?>" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0">
  <p>Your browser does not support iframes.</p>
</iframe>
</td></tr>

</table>
</body>

</html>
My Database is as follows:

Database name: websites

Field Type Null Default Comments
id int(11) No
userid int(11) No
url varchar(2083) No
credits int(11) No 0
stats int(11) No 0
active tinytext No
status text No
title varchar(50) No


Thanks
Post Reply