anon Posted December 19, 2007 Share Posted December 19, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/ Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418471 Share on other sites More sharing options...
anon Posted December 19, 2007 Author Share Posted December 19, 2007 Sorry, but what is the u_ for? Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418485 Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 Sorry, but what is the u_ for? u_ is just a pattern he uses.. u_name1 u_name2 ..etc Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418487 Share on other sites More sharing options...
anon Posted December 19, 2007 Author Share Posted December 19, 2007 So it can be left out Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418488 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418493 Share on other sites More sharing options...
anon Posted December 19, 2007 Author Share Posted December 19, 2007 Thanks. Next question. What would my PHP processing script look like. In other words, the script to add values given in the form to their respective columns in my DB? Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418499 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418510 Share on other sites More sharing options...
anon Posted December 19, 2007 Author Share Posted December 19, 2007 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418539 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 What does line 3 have in it. Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418543 Share on other sites More sharing options...
anon Posted December 19, 2007 Author Share Posted December 19, 2007 The comment above yours is edited. it shows the problems Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418574 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 what is all the Have to remove all of those. unless my browser is doing something strange Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418600 Share on other sites More sharing options...
anon Posted December 19, 2007 Author Share Posted December 19, 2007 it does that automatically for some reason. I think its parsing or something. will try. Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418605 Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 <?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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418608 Share on other sites More sharing options...
anon Posted December 19, 2007 Author Share Posted December 19, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418625 Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418629 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 yes you missed the single ' after $urlname Also you may want to remove usernames and passwords from your scripts Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418630 Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 Ya, sorry about that, I re-coded it wrong. Quote Link to comment https://forums.phpfreaks.com/topic/82333-solved-help-with-database-project/#findComment-418632 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.