PDA

View Full Version : Can anyone give a hand (do this) simple request.



Darknight
June 25th, 2008, 05:39
What I need is a PHP Script where people can go too itexweb.com/emailsubmit/index.php submit there email, it would then be stored in a MySQL database under a generated random number like 62345436
After they submit it the script displays the random number and a few lines of text.,
And simple admin page that needs one login only (Admin)
That can view all submitted emails with there random number from newist to oldist or something.

I need this because it would be good to have a simple email submitter so when clients request hosting where we ask for email: ndhjkh@jhdjkh.info
It can become emailID: 8907487

And we just get it from the ID, this is only to save spam for people requesting

So if anyone has anytime, even if you just write the basic, I would be very thankful :devious2:

I usaly pay for all scripts but Im broke. :cry2:

Of course Im only guessing its simple, I have no idea. not a coder.

Also open to just "Ideas" wouldnt mind learning a bit myself so if someone can even give me some php to work with I will give it a try lol

JonnyH
June 25th, 2008, 06:45
I'm bored...


<?php

//Start session
session_start();

//mySQL Details
$mysql['user'] = "user"; # mySQL username
$mysql['pass'] = "pass"; # mySQL password
$mysql['host'] = "localhost"; # mySQL hostname
$mysql['db'] = "database"; # mySQL database

//Admin Password
$apass = "password";

//Check connection
$mysql['con'] = @mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']);
if(!$mysql['con']) {
echo "Your mySQL details are incorrect!";
}
else {
$mysql['sdb'] = @mysql_select_db($mysql['db'], $mysql['con']);
if(!$mysql['sdb']) {
echo "Your mySQL Database is incorrect!";
}
else {
pages();
}
}

//Shows content.. if mySQL passes
function pages() {
//If button aint pressed and admin isn't asked for
if(!$_POST && !$_GET['admin']) {
//Enter email
?>
<form name="form1" method="post" action="">
<table width="100&#37;" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="25%">Email:</td>
<td>
<input type="text" name="email" id="email"> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="Submit Email"></td>
</tr>
</table>
</form>
<?php
}
//If button is pressed
elseif($_POST['submit']) {
global $mysql;
$email = mysql_real_escape_string($_POST['email']); #Asign email to variable and make it safe..
$num = rand(0,99999999999999); # Generates num
mysql_query("INSERT INTO `emails` (email, id) VALUES('{$email}', '{$num}')", $mysql['con']) || "The email wasn't inserted into the database properly. Here's the error:<br />". mysql_error();
echo "Your email code: ". $num;
}
//Show admin login
elseif($_GET['admin'] == "1") {
global $mysql;
global $apass;
//Login code
if(!$_SESSION['logged']) {
if($_POST['login']) {
if($apass == $_POST['pass']) { #If submitted password and admin pass are equal
$_SESSION['logged'] = 1; # Sets session so ACP is show
header("Location: ?admin=1"); # Redirects user
}
else {
echo "Password was incorrect!";
}
}
?>
<form name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="25%">Admin Password:</td>
<td>
<input type="password" name="pass" id="pass"> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="login" id="login" value="Login"></td>
</tr>
</table>
</form>
<?php
}
else {
echo "<h1>Emails</h1>";
$select = mysql_query("SELECT * FROM `emails`", $mysql['con']);
if(mysql_num_rows($select) == 0) {
echo "No emails in the Database!";
}
else {
echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">';
while($data = mysql_fetch_array($select)) {
echo "<tr><td>";
echo $data['email'];
echo "</td><td>";
echo $data['id'];
echo "</td></tr>";
}
echo '</table>';
}
}
}
//If admin aint logged in
if(!$_SESSION['logged']) {
echo "<a href=\"?admin=1\">Admin Area</a>";
}
}
?>

Fully tested and it's working.

SQL Code:


CREATE TABLE `emails` (
`email` TEXT NOT NULL ,
`id` TEXT NOT NULL
) ENGINE = MYISAM

Darknight
June 26th, 2008, 05:41
Thank you very much!!! works like a charm