DSLWeb
06-10-2004, 09:40 PM
Ok Got A Quick Question
A customer asked for a script to create free email accounts
I have it working but heres the problem I need it to check a db entry to find if a name is available.
I have created a config file to refer for the db name/pw.
Also started making a SQL :
create table email_accounts (
user VARCHAR unsigned NOT NULL auto_increment,
PRIMARY KEY (user)
) TYPE=MyISAM COMMENT='Used Emails';
now how would I call for this information in my script?
Hope this makes sense :D
Any Ideas would be greatly appreciated
Regards,
Lee
Epagien
06-11-2004, 12:19 AM
Ok, here is one way...
// Connect and select a database
// Check for SQL Injection
$var = mysql_escape_string($_POST[request_email]);
// Run Query
$sql = mysql_query("SELECT * `email_accounts` WHERE(user=`$var`)");
// Num of Rows
$num = mysql_num_rows($sql);
if($num>0) {
print "Email address already exists";
}
Please try that; its untested. It will give you an idea of what to do.
foogee
06-11-2004, 09:29 AM
A possible imrovement to EPagien's suggestion is to use count(*) in the SQL like :
$rs = mysql_query("SELECT count(*) from `email_accounts` WHERE(user=`$var`)");
$row = mysql_fetch_row($rs);
$num = $row[0];
This way only one row with one field will be returned and that field will contain the number of times user=`$var` .
HTH,
Mike
WLHosting
06-11-2004, 09:32 PM
I think that instead of using:
$rs = mysql_query("SELECT count(*) from `email_accounts` WHERE(user=`$var`)");
Use:
$rs = mysql_query("SELECT count(user) from `email_accounts` WHERE(user=`$var`)");
This way you are not getting all of the values in the row in the database except for the user field.
That should work for you as well.
ilyash
06-11-2004, 11:19 PM
Originally posted by WLHosting
I think that instead of using:
$rs = mysql_query("SELECT count(*) from `email_accounts` WHERE(user=`$var`)");
Use:
$rs = mysql_query("SELECT count(user) from `email_accounts` WHERE(user=`$var`)");
This way you are not getting all of the values in the row in the database except for the user field.
That should work for you as well.
I dont think it'll make a difference..
In the table.. there is only one column anyway...
WLHosting
06-11-2004, 11:36 PM
Couldn't this start to be a thing then to look at when there is many columns?
DSLWeb
06-12-2004, 05:10 PM
Thanks Im Going To Try It Now :D
DSLWeb
06-12-2004, 07:44 PM
ok i must not be doing something right here is the form for the email maker
<?
include("../config.php");
include("header2.php");
if ($submit){
//****************************
// Setup the Auth String
$pass = base64_encode($authstr);
//Setup an array of all the POST data
$formdata = array ( "email" => $email, "domain" => $host, "password" => $password, "quota" => $quota);
//build the post string
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
// strip off trailing ampersand
$poststring = substr($poststring, 0, -1);
$fp = fsockopen($host, $port, $errno, $errstr, $timeout = 30);
if(!$fp){
//error tell us
echo "$errstr ($errno)\n";
}else{
//send the server request
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Authorization: Basic $pass \r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");
fclose($fp);
}
echo "<b>Your Email Account Was Created</b><br><br>
To Access Please Use Outlook<br><br>
<b>Incoming POP3:</b> mail.$domain<br><br>
<b>Outgoing SMTP:</b> mail.$domain<br><br>
<br><br>
<b>Your new email address is:</b> $email@$domain<br><br>
<b>Password:</b> $password";
}else{
?>
<strong> DSL WebHosting Solution Free E-Mail Account Sign-Up</strong>
<form method="post">
<b>
Username: <input type="text" name="email">
@<select name=domain>
<option value="dsl-webhosting-solutions.com" selected>dsl-webhosting-solutions.com</option>
<option value="joshua-inc.com">joshua-inc.com</option>
</select><br>
Password: <input type="text" name="password"><br>
<INPUT type="text" style="display:none" name="quota" value="10"><br><br>
<center><input type="submit" name="submit" value="Create"> <input type="reset" value="Clear"></center
</b>
<br><br><br><br>
<center>
<b>[</b> <a href = "index.html"><font class="med">Go Back</font></a> <b>]</b>
</center>
<? }
include("footer.php");
?>
The SQL is
CREATE TABLE `email_accounts` (
`ueid` bigint(22) unsigned NOT NULL auto_increment,
PRIMARY KEY (`ueid`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
The config file is stored under root
$dbhost = "localhost";
$dbuname = "dslweb_emails";
$dbpass = "*********";
$dbname = "dslweb_emails";
$prefix = "email";
$user_prefix = "email";
$dbtype = "MySQL";
Any Ideas How / Where to join them to call up that db tried suggested with no luck =/
Thanks For Your Help :D
TechSolution
06-12-2004, 09:51 PM
Originally posted by WLHosting
I think that instead of using:
$rs = mysql_query("SELECT count(*) from `email_accounts` WHERE(user=`$var`)");
Use:
$rs = mysql_query("SELECT count(user) from `email_accounts` WHERE(user=`$var`)");
This way you are not getting all of the values in the row in the database except for the user field.
That should work for you as well.
It doesn't matter. count(*) is a count of the rows, not the columns or columns * rows.