What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP/MySQL help

Pages: (3): « First [ 1 ] 2 3 » Last »
PHP/MySQL help
Author: Message:
lordy
Senior Member
****


Posts: 853
Reputation: 24
35 / Male / Flag
Joined: Jul 2004
Status: Away
O.P. PHP/MySQL help
I'm creating a MySQL database for my dad so he can catalogue his huge collection of DVD's and CD's etc. I'm doing it cause i want to learn PHP and mySQL and stuff, so i figured I may as well do something useful with it while im going. It's being accessed using PHP via our webrowser over our home network. atm i have it so the page displays all entries in the database.

My questions are: How do you make a webpage in which you can easily add a new entry into the database (ie. add a new DVD/CD), using a form, so its easier for my dad to add new dvd's.

and how do i make a search form so my dad can search for a particular DVD within the database?

Im not sure if i've given enough information here... If you need something else then let me know. and dont be worried about talking n00bish to me cos im a n00b at this sort of stuff :P (hence why i am trying to learn)
11-10-2005 12:04 PM
Profile E-Mail PM Find Quote Report
Dempsey
Scripting Contest Winner
*****

Avatar
http://AdamDempsey.net

Posts: 2395
Reputation: 53
38 / Male / Flag
Joined: Jul 2003
RE: PHP/MySQL help
well to add stuff you need a form which will send the results to a php page which will then process the form data and add it into the DB.

I suggest following a tutorial like:

WebMonkey
SoundPacks   -   Scripts   -   Skins

that's not a bug, thats an unexpected feature
11-10-2005 12:09 PM
Profile E-Mail PM Web Find Quote Report
lordy
Senior Member
****


Posts: 853
Reputation: 24
35 / Male / Flag
Joined: Jul 2004
Status: Away
O.P. RE: PHP/MySQL help
aaah that is excellent for adding stuff :D thanks
11-10-2005 12:34 PM
Profile E-Mail PM Find Quote Report
Dempsey
Scripting Contest Winner
*****

Avatar
http://AdamDempsey.net

Posts: 2395
Reputation: 53
38 / Male / Flag
Joined: Jul 2003
RE: PHP/MySQL help
no problem :)

And about doing the search, you will be doing something similar, except instead of using INSERT, you will use SELECT, something like:
code:
SELECT dvdName, dvdYear (etc etc) FROM TableName WHERE dvdName LIKE `%searchTerms%` ORDER BY dvdName ASC

Where dvdName, dvdYear (etc, etc) is the field list you want to return, TableName is the name of the table you are searching in and searchTerms is from the textbox you search in.
SoundPacks   -   Scripts   -   Skins

that's not a bug, thats an unexpected feature
11-10-2005 12:37 PM
Profile E-Mail PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: PHP/MySQL help
also remember when using a unknown varible (from a form or something) in a sql query you should escape it with

code:
mysql_real_escape_string();

[Image: dt2.0v2.png]      Happy Birthday, WDZ
11-10-2005 01:00 PM
Profile PM Web Find Quote Report
lordy
Senior Member
****


Posts: 853
Reputation: 24
35 / Male / Flag
Joined: Jul 2004
Status: Away
O.P. RE: PHP/MySQL help
well, so far i have this:

code:
<html>

<body>

<?php
$db = mysql_connect("127.0.0.1", "root");
mysql_select_db("movie_library",$db);
$_POST = array_map("mysql_escape_string",$_POST);


if (isset($_POST['dvd_title']))
{
//Form has been submitted
$dvd_title = $_POST['dvd_title'];
$dvd_director = $_POST['dvd_director'];
$dvd_classification = $_POST['dvd_classification'];
$dvd_actors = $_POST['dvd_actors'];
$dvd_genre = $_POST['dvd_genre'];
$dvd_year = $_POST['dvd_year'];
$dvd_length = $_POST['dvd_length'];
//insert to db
$sql = "INSERT into movies (dvd_title,dvd_director,dvd_classification,dvd_actors,dvd_genre,dvd_year,dvd_length) VALUES ('$dvd_title','$dvd_director','$dvd_classification','$dvd_actors','$dvd_genre','$dvd_year','$dvd_length')";
$result = mysql_query($db,$sql);
}
else{

?>


<form method="post" action="?">
DVD Title:<input type="Text" name="dvd_title"><br />
DVD Director:<input type="Text" name="dvd_director"><br />
DVD Classification:<input type="Text" name="dvd_classification"><br />
DVD Actors:<input type="Text" name="dvd_actors"><br />
DVD Genre:<input type="Text" name="dvd_genre"><br />
DVD Year:<input type="Text" name="dvd_year"><br />
DVD Length:<input type="Text" name="dvd_length"><br />
<input type="Submit" name="submit" value="Sumbit">

<?php

}

mysql_close($db);
?>




</body>

</html>

when i enter the data, the page goes blank (which im pretty sure its meant to), but the data isnt entered into the MySQL database.
I've asked -dt- on MSN and he couldn't find an error, so its probably someone hugely obvious, or something frustratingly small.

This post was edited on 11-11-2005 at 12:30 PM by lordy.
11-11-2005 12:27 PM
Profile E-Mail PM Find Quote Report
Dempsey
Scripting Contest Winner
*****

Avatar
http://AdamDempsey.net

Posts: 2395
Reputation: 53
38 / Male / Flag
Joined: Jul 2003
RE: PHP/MySQL help
after
code:
$result = mysql_query etc
add
code:
if (!$result){die('Invalid query: ' . mysql_error() . "<br>SQL: " . $sql);}
SoundPacks   -   Scripts   -   Skins

that's not a bug, thats an unexpected feature
11-11-2005 12:45 PM
Profile E-Mail PM Web Find Quote Report
lordy
Senior Member
****


Posts: 853
Reputation: 24
35 / Male / Flag
Joined: Jul 2004
Status: Away
O.P. RE: PHP/MySQL help
i just chucked in random characters and it came up with this:

Invalid query:
SQL: INSERT into movies (dvd_title,dvd_director,dvd_classification,dvd_actors,dvd_genre,dvd_year,dvd_length) VALUES ('fjidjjfids','jfiodjfdos','kf','jifojodf jgf9idf','jdioas','1425','162')
11-11-2005 12:54 PM
Profile E-Mail PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: PHP/MySQL help
http://php.net/mysql_query

resource mysql_query ( string query [, resource link_identifier] )

You have your arguments in the wrong order...

mysql_query($db,$sql)
11-11-2005 02:05 PM
Profile PM Web Find Quote Report
lordy
Senior Member
****


Posts: 853
Reputation: 24
35 / Male / Flag
Joined: Jul 2004
Status: Away
O.P. RE: PHP/MySQL help
OMGZORS it works :D

THANK YOU WDZ :D :D

now the next thing is to make a search form but that doesnt matter right now

thank you so much :D
11-11-2005 10:03 PM
Profile E-Mail PM Find Quote Report
Pages: (3): « First [ 1 ] 2 3 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On