Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm still learning php database.
I want to save the url in the database and 20 url limite show display page. Example:
<a href="http://pcboxsearch.com/link/">http://pcboxsearch.com/link/</a>

My code was not able to save it to database, how to create a database url? :(( :((

$link = mysql_connect('localhost', 'root', '');
mysql_select_db('dy',$link);
mysql_query("update messages set $url=$image where id='$id'");

$result=mysql_query("select up,down from url where id='$id'");
$row=mysql_fetch_array($result);

$url = $_REQUEST['url'];
$url = checkValues($url);

function checkValues($value)
{
	$value = trim($value);
	if (get_magic_quotes_gpc()) 
	{
		$value = stripslashes($value);
	}
	$value = strtr($value, array_flip(get_html_translation_table(HTML_ENTITIES)));
	$value = strip_tags($value);
	$value = htmlspecialchars($value);
	return $value;
}	

function fetch_record($path)
{
	$file = fopen($path, "r"); 
	if (!$file)
	{
		exit("Problem occured");
	} 
	$data = '';
	while (!feof($file))
	{
		$data .= fgets($file, 1024);
	}
	return $data;
}

$string = fetch_record($url);


/// fecth title
$title_regex = "/<title>(.+)<\/title>/i";
preg_match_all($title_regex, $string, $title, PREG_PATTERN_ORDER);
$url_title = $title[1];

/// fecth decription
$tags = get_meta_tags($url);

// fetch images
$image_regex = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
preg_match_all($image_regex, $string, $img, PREG_PATTERN_ORDER);
$images_array = $img[1];
?>
</title>

<div class="images">
	<?php
	$k=1;
	for ($i=0;$i<=sizeof($images_array);$i++)
	{
		if(@$images_array[$i])
		{
			if(@getimagesize(@$images_array[$i]))
			{
				list($width, $height, $type, $attr) = getimagesize(@$images_array[$i]);
				if($width >= 50 && $height >= 50 ){
				
				echo "<img src='".@$images_array[$i]."' width='100' id='".$k."' >";
				
				$k++;
				
				}
			}
		}
	}
	?>
	<!--<img src="ajax.jpg"  alt="" />-->
	<input type="hidden" name="total_images" id="total_images" value="<?php echo --$k?>" />
	</div>
	<div class="info">
		
		<label class="title">
			<?php  echo @$url_title[0]; ?>
		</label>
		<br clear="all" />
		<label class="url">
			<?php  echo substr($url ,0,350); ?>
		</label>
		<br clear="all" /><br clear="all" />
		<label class="desc">
			<?php  echo @$tags['description']; ?>
		</label>
		<br clear="all" /><br clear="all" />
		
		<label style="float:left"><img src="prev.png" id="prev" alt="" /><img src="next.png" id="next" alt="" /></label>
		
		<label class="totalimg">
			Total <?php echo $k?> images
		</label>
		<br clear="all" />
            <br>
              <input type="submit" name="button" value="Kirim" class="submit" id="btsend" /></p>
	</div>


Source detail download:
http://pcboxsearch.com/link/mau.zip[^]
Posted
Updated 28-Aug-10 21:31pm
v8
Comments
Christian Graus 28-Aug-10 20:06pm    
Your question makes little sense. Do you want to create a DB, or insert a string into it ?
ariodoni 28-Aug-10 20:22pm    
I'm still learning php database
please help..
i need how creative database me link
detail me source
http://pcboxsearch.com/link/mau.zip
Christian Graus 28-Aug-10 20:41pm    
I don't do PHP, because it's rubbish, so I can't really help you. But, I thought you should know your question made no sense, for people who can help. What you posted as a comment, makes no sense, have you edited your question to be clearer ? What does 'i need how creative database me link' mean ? you want to create a new database when people click a link ? That's almost certainly a terrible idea.
ariodoni 28-Aug-10 20:45pm    
thanks your idea
Sandeep Mewara 29-Aug-10 3:32am    
Formatted code part using PRE tags so that your question is atleast readable.
Might be you would need to update it and be a little more clear as CG suggested.

I don't understand what you want:D
but perhaps this part has a problem:
<pre lang="sql">mysql_query("update messages set $url=$image where id='$id'");



Try it out:
mysql_query("update messages set url=$image where id='$id'");
 
Share this answer
 
Comments
ariodoni 2-Sep-10 11:50am    
can you detail because I'm still learning php database

Source detail download:
http://pcboxsearch.com/link/mau.zip[^]
ariodoni 2-Sep-10 11:53am    
I want it functions like a guestbook posts
when you want to update a record in your table, the code must be like:

update messages set url='$image' where id='$id'

But your ode is:
update messages set $url=$image where id='$id'


It means that a column that the name is $url should update! and because it's php varible that you defined($url = $_REQUEST['url'];), it will replace with content of variable(Te URL that your user entered:D)
In fact, your exact code is :
(if user enter $url:http://yahoo.com, $image=img.jpg,$id=Something)

update messages set http://yahoo.com=img.jpg where id='Something'


but you have no column in your table that its name is:http://yahoo.com

Note: Excuse me for my poor english:D
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900