Page 1 of 1
Adding to my DB
Posted: Tue Jun 04, 2002 5:13 pm
by Aaron
Ok- I have a nice little table set up, a display page and such...
Now what I need is a script that will put the info into the rows.
The rows are as followed :
id, series, episode, title, info, date, author.
Obviously I'd need a form that would allow me to input the values for the next row, but i dont know how to make it and stuff.
Password protection wouldnt need building in because I've got a CGI script to lock the page.
To view the script in BETA action (looks shabby i know) go
here!
Posted: Tue Jun 04, 2002 5:20 pm
by gotDNS
here is a generous snippet of some of my code:
The signup page!:
Code: Select all
<?php
session_start();
$connect = mysql_connect("localhost:3306", "techy") && mysql_select_db("forum")
or $failed = "Could not connect to database.";
echo "<html><head>
<title>Techy Board</title>
<link rel="stylesheet" type="text/css" href="forum.css" />
</head>
<body marginheight="0" marginwith="0" topmargin="0" leftmargin="0">";
if(session_is_registered("loggedin"))
{
echo "<img src="forumtop.gif" /><br /> <b>You are logged in as $loggedin</b> : <a href="logout.php" class="NLINK">Logout</a><br /> ERROR: You already seem to be signed up.<img src="smile.gif" />";
}
else
{
echo "<img src="forumtop.gif" /><br /><br />
<table cellpadding="0" cellspacing="0" width="92%" border="0" align="center">
<tr>
<td align="left" width="80">
<b><u>Sign-Up</u></b><br /><br />
</td>
<td align="left"></td>
</tr>
<tr>
<td align="right" width="80">
<form action="signup2.php" method="post">
First Name:
</td>
<td align="left">
<input type="text" size="16" maxlength="24" name="fname" />
</td>
</tr>
<tr>
<td align="right" width="80">
Last Name:
</td>
<td align="left">
<input type="text" size="16" maxlength="24" name="lname" />
</td>
</tr>
<tr>
<td align="right" width="80">
Username:
</td>
<td align="left">
<input type="text" size="16" maxlength="16" name="usrname" />
</td>
</tr>
<tr>
<td align="right" width="80">
Password:
</td>
<td align="left">
<input type="password" size="16" maxlength="32" name="passwd" />
</td>
</tr>
<tr>
<td align="right" width="80">
Password2:
</td>
<td align="left">
<input type="password" size="16" maxlength="32" name="passwd2" /> (re-type)
</td>
</tr>
<tr>
<td align="right" width="80">
E-mail:
</td>
<td align="left">
<input type="text" size="16" maxlength="40" name="email" />
</td>
</tr>
<tr>
<td align="right" width="80" valign="top">Signature:</td>
<td align="left"><textarea name="sig" rows="10" cols="45"></textarea>
</td>
</tr>
<tr>
<td></td>
<td align="left"><input type="Submit" value="Sign-Up" class="BUTTON" /> <input type="reset" value="Reset" class="BUTTON" /></td>
</form>
</tr>
<tr>
<td></td>
<td><br /><a href="forum.php" class="NLINK">< Back to the forums</a></td>
</tr>
</table>";
}
?>
</body>
</html>
The submit-to-db page!:
Code: Select all
<?php
session_start();
$connect = mysql_connect("localhost:3306", "techy") && mysql_select_db("forum")
or $failed = "Could not connect to database.";
$loginform = "<form method="post" action="login.php">
<img src="forumtop.gif" /><br /> <b>Thank you for signing up!</b><br /><br /> <b><u>Login</u></b><br />
Username: <input type="text" size="16" maxlength="16" name="username" />
Password: <input type="password" size="16" maxlength="16" name="password" />
<input type="hidden" name="login" value="true" />
<input type="submit" value="Login" />
</form>";
if($fname != "" && $lname != "" && $usrname != "" && $passwd != "" && $passwd2 != "" && $email != "" && $passwd == $passwd2) {
$passwdon = md5($passwd);
mysql_query("insert into usrinfo set fname="$fname",lname="$lname",username="$usrname",password="$passwdon",email="$email",signature="$sig""); echo $loginform; }
else { $error = "ERROR:"; }
?>
<html>
<head>
<title>Techy Board</title>
<link rel="stylesheet" type="text/css" href="forum.css" />
</head>
<body marginheight="0" marginwith="0" topmargin="0" leftmargin="0">
<?php if($error) { echo "<img src="forumtop.gif" /><br /><br /> <b>$error</b>"; }
if($fname == "" || $lname == "" || $usrname == "" || $passwd == "" || $passwd2 == "" || $email == "") { echo " <code>You did not complete the form, please hit your back button and complete it.</code>"; }
if($passwd != $passwd2 || $passwd == "" || $passwd2 == "") { echo " <code>Your passwords did not match, please hit your back button and re-type them.</code>"; }
?>
</body>
</html>
Posted: Tue Jun 04, 2002 5:42 pm
by Aaron

omg
Posted: Tue Jun 04, 2002 5:51 pm
by Aaron
ok its not as hard as it looks
Only problem im havin is figuring out what bits art choosing the table ids, is it the || $lname == "" || $usrname == "" || $passwd == "" || $passwd2 == "" || $email ==
bits? ie i should change lname to id for it to write in that row?
Posted: Tue Jun 04, 2002 6:19 pm
by Aaron
parse errors, deleted :S
Posted: Tue Jun 04, 2002 6:21 pm
by gotDNS
yes, change the variable name, etc.
parse errors in my code?....works for me
:S ?
Posted: Tue Jun 04, 2002 7:20 pm
by Aaron
I changed it and it <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> up :S i suck

Posted: Tue Jun 04, 2002 7:23 pm
by gotDNS
hmmm, what did u change?
Paste the code and i'll take a look.
Posted: Wed Jun 05, 2002 3:27 am
by Aaron
Posted: Wed Jun 05, 2002 8:24 am
by Aaron
OK proplem solved thx to Dave, from Evil Walrus.
Here it is for anyone interested!
Inputting!
Code: Select all
<?php
session_start();
mysql_connect("localhost","user","password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
echo "<html><head>
<title>Techy Board</title>
<link rel="stylesheet" type="text/css" href="forum.css" />
</head>
<body marginheight="0" marginwith="0" topmargin="0" leftmargin="0">";
if(session_is_registered("loggedin"))
{
echo "<img src="forumtop.gif" /><br /> <b>You are logged in as $loggedin</b> : <a href="logout.php" class="NLINK">Logout</a><br /> ERROR: You already seem to be signed up.<img src="smile.gif" />";
}
else
{
echo "<img src="forumtop.gif" /><br /><br />
<table cellpadding="0" cellspacing="0" width="92%" border="0" align="center">
<tr>
<td align="left" width="80"> <b><u>Sign-Up</u></b><br />
<br />
</td>
<td align="left"></td>
</tr>
<tr>
<td align="right" width="80"> <form action="submit.php" method="post">
author: </td>
<td align="left">
<input type="text" size="16" maxlength="24" name="author" />
</td>
</tr>
<tr>
<td align="right" width="80"> </td>
<td align="left"> </td>
</tr>
<tr>
<td align="right" width="80"> series</td>
<td align="left">
<input type="text" size="16" maxlength="16" name="series" />
</td>
</tr>
<tr>
<td align="right" width="80"> episode</td>
<td align="left">
<input type="text" size="16" maxlength="32" name="episode" />
</td>
</tr>
<tr>
<td align="right" width="80"> title</td>
<td align="left">
<input type="text" size="16" maxlength="32" name="title" />
</td>
</tr>
<tr>
<td align="right" width="80"> info</td>
<td align="left">
<textarea name="info" rows="10" cols="45"></textarea>
</td>
</tr>
<tr>
<td align="right" width="80" valign="top">date</td>
<td align="left">
<input type="text" size="16" maxlength="40" name="date" />
</td>
</tr>
<tr>
<td></td>
<td align="left">
<input type="Submit" value="Sign-Up" class="BUTTON" />
<input type="reset" value="Reset" class="BUTTON" />
</td></form>
</tr>
<tr>
<td></td>
<td><br />
</td>
</tr>
</table>
";
}
?>
</body>
</html>
Finalising
Code: Select all
<?php
session_start();
mysql_connect("localhost","user","password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
if($author != ""&& $series != "" && $episode != "" && $title != "" && $info != "") {
mysql_query("INSERT INTO unknownz.unz VALUES ('','$series','$episode','$title','$info','$date','$author')") or die(mysql_error()); echo $loginform; }
else { $error = "<b> - Error - </b>"; }
?>
<html>
<head>
<title>Series Submitter</title>
</head>
<body marginheight="0" marginwith="0" topmargin="0" leftmargin="0">
<?php if($error) { echo "<b> - Error - </b>"; }
if($author == "" || $series == "" || $episode == "" || $title == "" || $info == "") { echo " <code>You did not complete the form, please hit your back button and complete it.</code>"; }
?>
</body>
</html>
If anyone has any further ideas for it?
Anywho, next problem =/ I was reading a tutorial on Ascenvia about deleting certain ids, tried it and it didnt work, have a look :
Code: Select all
<form method="get" action="file.php"> //file is the name of this file
<?
mysql_pconnect("localhost","unknownz","Cm784Xhti"); //connect to the mySQL
mysql_select_db("unz"); //select the db
if(!$submit)//if submit has not already been pressed
{
$result = mysql_query("select * from news order by id"); //select all the news
while($r=mysql_fetch_array($result)) //run the while loop
{
$title=$rї"title"];//take out the title
$id=$rї"id"];//take out the id
?>
<INPUT TYPE="RADIO" NAME="id" VALUE="<?php echo $id;?>"><br> //the radio button with the value of each id
<?php echo $id;?><br> //output the id
<?php echo $title?><br> //output the title
<?
}?> //end of the while loop
<input type="submit" value="submit" name="Submit"></form> //submit
<?
}?>
[/u][/quote]