Jump to content

[SOLVED] Help with database project


anon

Recommended Posts

Hi, this is quite long so bear with me.

I want to create my own search engine. The engine will have an 'add website' form. This form will have the following fields,

 

Name - name of website e.g PHP Freaks Forums

URL - URL of website e.g http://www.phpfreaks.com/forums

Description - How you want your website to be described in the directory listing.

 

Each of these values will be posted to my database. I want Name to be tied to Description, to be tied to URL. e.g If they search for something in the search box (coming later), the keyword provided will be compared to each value in the DB. If it finds a value which matches, it will display the name URL and Description, because the value it found, was tied to two other values.

 

My first question is, what would the Table look like, and can it work?

Link to comment
Share on other sites

Should work just fine. One table would do what you need.

 

table structure

 

u_id - int(11)

u_name  - varchar(100)

u_link - varchar(255)

u_desc - text or varchar(255) depending how long your descriptions will be

 

all fields are in the same row so all will be tied together.

 

Ray

Link to comment
Share on other sites

:) just something to tell apart the tables for future use u_ is for url. Just a personal preference and to try and stay away from reserved words in your script. You want to try and stay away from using field names like "date" and "name" and other words mysql or php may use as functions. so adding a prefixes help keep that from happening
Link to comment
Share on other sites

Well this is basic mysql scripting but here is a some help

 

i assume you know how to create your form

 

<?php
// Make mysql connection below
$mysql_conn = @mysql_connect("host", "username", "password") or die("Could not connect to Mysql, Please check host/username/password settings and try again");
@mysql_select_db("dbname", $mysql_conn) or die("DataBase does not exist");

// prepare form values for insert
$urlname = mysql_real_escape_string($_POST['urlname']);
$URL = mysql_real_escape_string($_POST['url']);
$urldesc = mysql_real_escape_string($_POST['desc']);
// Make mysql connection below

$sql = "INSERT INTO `tablename` (`u_name`, `u_link`, `u_desc`) VALUES ('$urlname, '$URL', '$urldesc')";
$res = mysql_query($sql) or die(mysql_error());
  if(!$res){
  echo "Could not enter data";
  } else {
  echo "data entered into database";
  }

It's a start. Also did I mention that the u_id field should be an autonumber field to give each row a unique identifier??

Ray

Link to comment
Share on other sites

there is an error

 

Parse error: syntax error, unexpected '=' in /home/redzero/public_html/direx/addurl.php on line 3

 

and when i went to edit the code, it had parsed it i think

<?php
// Make mysql connection below
$mysql_conn = @mysql_connect("localhost", "***", "***") or die("Could not connect to Mysql, Please check host/username/password settings and try again");
@mysql_select_db("direx", $mysql_conn) or die("DataBase does not exist");

// prepare form values for insert
$urlname = mysql_real_escape_string($_POST['urlname']);
$URL = mysql_real_escape_string($_POST['url']);
$urldesc = mysql_real_escape_string($_POST['desc']);
// Make mysql connection below

$sql = "INSERT INTO `addurl` (`u_name`, `u_link`, `u_descrip`) VALUES ('$urlname, '$URL', '$urldesc')";
$res = mysql_query($sql) or die(mysql_error());
  if(!$res){
  echo "Could not enter data";
  } else {
  echo "data entered into database";
  }

?>

Link to comment
Share on other sites

<?php
// Make mysql connection below
$mysql_conn=@mysql_connect("localhost","***","***")or die("Could not connect to Mysql, Please check host/username/password settings and try again");
@mysql_select_db("direx",$mysql_conn) or die("Database does not exists");

// prepare form values for insert
$urlname=mysql_real_escape_string($_POST['urlname']);
$URL=mysql_real_escape_string($_POST['url']);
$urldesc=mysql_real_escape_string($_POST['desc']);
// Make mysql connection below

$sql="INSERT INTO `addurl` (`u_name`,`u_link`,`u_descrip`) VALUES('$urlname,'$URL','$urldesc')";
$res=mysql_query($sql)or die(mysql_error());
if(!$res){
echo"Could not enter data";
}
else{
echo"data entered into database";
}

?>

Link to comment
Share on other sites

There was 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 'http://www.google.com', 'The best search engine in the world')' at line 1

 

I tested it. I entered Google. That's the error that occured. Here's the code as of now

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
// Make mysql connection below
$mysql_conn = @mysql_connect("localhost", "redzero", "polojock101!^") or die("Could not connect to Mysql, Please check host/username/password settings and try again");
@mysql_select_db("redzero_Direx", $mysql_conn) or die("DataBase does not exist");

// prepare form values for insert
$urlname = mysql_real_escape_string($_POST['urlname']);
$URL = mysql_real_escape_string($_POST['url']);
$urldesc = mysql_real_escape_string($_POST['desc']);
// Make mysql connection below

$sql = "INSERT INTO `addurl` (`u_name`, `u_link`, `u_desc`) VALUES ('$urlname, '$URL', '$urldesc')";
$res = mysql_query($sql) or die(mysql_error());
  if(!$res){
  echo "Could not enter data";
  } else {
  echo "data entered into database";
  }
  ?>
</html>

Link to comment
Share on other sites

try

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
// Make mysql connection below
$mysql_conn = @mysql_connect("localhost", "redzero", "polojock101!^") or die("Could not connect to Mysql, Please check host/username/password settings and try again");
@mysql_select_db("redzero_Direx", $mysql_conn) or die("DataBase does not exist");

// prepare form values for insert
$urlname = mysql_real_escape_string($_POST['urlname']);
$URL = mysql_real_escape_string($_POST['url']);
$urldesc = mysql_real_escape_string($_POST['desc']);
// Make mysql connection below

$sql = "INSERT INTO `addurl` (`u_name`, `u_link`, `u_desc`) VALUES ('$urlname', '$URL', '$urldesc')";
$res = mysql_query($sql) or die(mysql_error());
  if(!$res){
  echo "Could not enter data";
  } else {
  echo "data entered into database";
  }
  ?>
</html>

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.