View Full Version : Adding data to a database
shwaza
12-09-2004, 12:18 AM
How on earth do i add data to a database??? lol i am such a newbie!!!!
688206002
12-09-2004, 12:47 AM
Originally posted by shwaza@Dec 8 2004, 07:18 PM
How on earth do i add data to a database??? lol i am such a newbie!!!!
16407
Do you mean from your code or manually from phpmyadmin?
(btw, have you created tables yet in your DB?)
shwaza
12-09-2004, 09:55 AM
i dont really care, ill do it anyway lol
EDIT: nevermind i think i added a row, but im still not sure how to show it
<html>
<head>
<title>yup</title>
</head>
<body bgcolor="#FFFFFF">
</body>
<?php
mysql_connect("localhost", "shwaza_shwaza", "password") or die("We are having troubles with the site at the moment.");
mysql_select_db("shwaza_p") or die("We are having troubles with the site at the moment.");
$p = $_GET['p']; // This is the dynamic URL part.
$result = mysql_query("SELECT * FROM `pages` WHERE `name` = '$p'");
if (mysql_num_rows($result) != 1)
{
echo "There was an error processing your request. *Most likely, the page is missing. *If you have received this from a link on this site, contact the administator.";
}
else
{
while($cPage = mysql_fetch_object($result))
{
* *echo $cPage->content;
}
}
?>
</html>
Thats the code, the only thing i changed was my password, my database is called shwaza_p the table is called pages, it has 2 fields, name and content, i filled in one row of name and content, i think all they say is like hello or test or something like that. Also, when i view the page (http://shwaza.hostmatrix.org/yup.php), i get the second error message "there was an error processing your request. Mostlikley on this site, contact the administrator." so i am asuming the only problem with the code is the actual querey itself. I hope ive given enough information for someone to help :)
mahangee
12-09-2004, 04:07 PM
The reason your getting the home made error and its not displaying the row is because you are getting $p from the URL right? However the link you gave us does not declare p as anything. If you want to get it to work you should put http://shwaza.hostmatrix.org/yup.php?p=<whatever the rows name is> then it should work.
Hope this helps.
shwaza
12-10-2004, 06:35 PM
ok i think i've done that, but i'll try again
reid315
12-11-2004, 12:44 AM
make sure that your form is labeled "p" because you can let the user type his/her own entry into it... then just set the action of the form to the processing page. I'ts an alternative
shwaza
12-11-2004, 01:37 AM
hmmm i hadnt really thought about letting others add to it, does anyone have a code with a form that would do that?
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.