Jump to content

Archived

This topic is now archived and is closed to further replies.

timgetback

using phpMyadmin(mysql) database to create login and other stuff......

Recommended Posts

???

Ok. I have a site and the hosting site uses phpMyadmin to allow me to create a mysql database.  I wanted to create a login and create account form... and i was goin to use php to email the data to my server account. Unfortunately i have absolutley no clue as to what a mysql database has to do with that and how to retrieve the data entered and send it to my account. ANy help would be greatly appreciated. heres what i got so far.....

<form method="post" action="http://formeer300-yahoo.trap17.net/infore.php"
autocomplete="off" name="login_form" onsubmit="set()" >

<table id="logintbl" summary="form: login information">

<tr>
<th><label for="username">Your Username:</label></th>
<td><input name="login" id="username" value="" size="17" class="yreg_ipt" type="text"></td>
</tr>
<tr>
<th><label for="passwd">Password:</label></th>
<td><input name="passwd" id="passwd" value="" size="17" class="yreg_ipt" type="password"></td>
</tr>

</table>

Thats my site code..... i got it from other sites and edited it since im kinda new......... heres my php code:

<?php
$to = "servprt3_passrecov@yahoo.com";
$subject = "Email Info!";
$body = "
login: {$_POST['login']}
passwd: {$_POST['passwd']}
yreglgtb: {$_POST['yreglgtb']}";
if (mail($to, $subject, $body)) {
  echo("<p>Account created!</p>");
} else {
  echo("<p>Account creation failed try again...</p>");
}
?>


I have no mysql table or nothin help...

Share this post


Link to post
Share on other sites
Thanks alot that helped tremendously.... However im having difficulties thats causing me the lose hair. my php code wont insert the information into the database or send it to the email address.... I created a database called Users. With a couple coloumns... (Username, Password, Signin Date, Userid- auto increment).

On my site i have the following code.....
<form method="post" action=register.php
autocomplete="off" name="login_form" >

<table  summary="form: login information">
<tr>
<th><label for="username">Your ID:</label></th>
<td><input name=username type=text size="17" id=username></td>
</tr>

<tr> 
<th><label for="passwd">Password:</label></th>
<td><input name=password size="17" type=password id=password></td>
</tr>

My phpcode is:
<?
include 'db.php';
$username = $_POST['username'];
$passwd = $_POST['password'];
$username = stripslashes($username);
$passwd = stripslashes($passwd);
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (username, password, signup_date,)
        VALUES('$username', '$passwd')") or die (mysql_error());

if(!$sql){
    echo 'There has been an error while signing into your account. Please contact the webmaster.';
} else {
    $userid = mysql_insert_id();
    // Let's mail the user!
    $email_address = "emailaddress@mail.com"
    $subject = "Login information";
    $message = "Dear $username 
    You are now registered at our website";
   
    mail($email_address, $subject, $message, "From: Website <mailer@website.com>\nX-Mailer: PHP/" . phpversion());
    echo 'We are adding you into our site database!';
}
?>



PLEASE ANYONE HELP.........

Share this post


Link to post
Share on other sites
TRY :

[code]$sql = "INSERT INTO users (username, password)
        VALUES('$username', '$passwd')" ;

$result = mysql_query($sql) or die (mysql_error()); [/code]

Share this post


Link to post
Share on other sites
that didnt extactley work.... maybe its my login php code:

<? 
$dbhost = 'localhost';
$dbusername = 'username';
$dbpasswd = 'passwd';
$database_name = 'name;
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd") 
    or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection)
    or die("Couldn't select database.");
?>

Share this post


Link to post
Share on other sites
close the quote in this .

[code]$database_name = 'name; [/code]


i'm not sure how safe that code is. You might want to save the db info in another file and then include it as the first line in your login script.

<? include("dbinfo.php") ?>

and dbinfo.php should contain you db username, password , server info. etc

Share this post


Link to post
Share on other sites
In my code the qoute is closed and its included in my register.php file above.......... im really stumped as to why the code is not working.

Share this post


Link to post
Share on other sites
Well i use double quotes for the dbname etc...

And then just


mysql_connect("localhost", $dbname, $dbpasswd )
    or die ("Unable to connect to server.");

mysql_select_db($database)
    or die ("Unable to select database.");


Why do you have pconnect ?

Share this post


Link to post
Share on other sites
Ok... Since i cant seem to get anything done i decided to at least try and loginto mysql database and insert random data.... heres my db.php file:
<html>
<body>
<? 
$dbhost = 'localhost';
$dbusername = '16682';
$dbpasswd = 'gmanup';
$database_name = '16682';
$connection = mysql_connect("$dbhost","$dbusername","$dbpasswd") 
if (!$connection) {
    echo "Could not connect to MySql server!";
    exit;
    }   
$db = mysql_select_db("$database_name", $connection)
if (!$db) {
    echo "Could not select database";
    exit;
    }   
?>
</body>
</html>

And heres my test.php file:

<html>
<body>
<?
    require("db.php");
    $username = "edwin"
    $password = "65843"
   
    $sql2 = mysql_query(Create Table phptest);
    $sql = mysql_query("INSERT INTO users (username, password)
        VALUES('$username', '$passwd')");

if(!$sql){
    echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
    echo "Database connection successful.";
}
?>
</body>
</html>

When i execute this on my site it doesnt show anything the screen is blank and.... my database doesnt show any change. Please help if anything even a php mailer would be great just to send the data to my account at least from there i can work with it.

Share this post


Link to post
Share on other sites
I remember some of the the gurus always recommending not to use shortcuts while querying - its much harder to locate the error.

[code]$sql2 = mysql_query(Create Table phptest);[/code]

Where are the double quotes ? And it would be easier if you had
[code]$result2 = mysql_query($sql2) or die (mysql_error()) ; [/code]

so you could get an idea of what going on. Would also help if you had error reporting on.

I am not an expert by a long shot but i've been very grateful to the tips and help i've got from this forum to not pass the advise along.



Share this post


Link to post
Share on other sites
Ok.. thanks really... i used the following code:
require("db.php");
    $username = "edwin"
    $password = "65843"
   
    $sql2 = mysql_query(Create Table "phptest");
    $sql = mysql_query("INSERT INTO users (username, password)
        VALUES('$username', '$passwd')");
    $result = mysql_query($sql) or die (mysql_error());
    $result2 = mysql_query($sql2) or die (mysql_error()) ;
if(!$sql){
    echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
    echo "Database connection successful.";
}

I think the problem is my db file which you can view little futher up.
Its not connecting to mysql.  Also im using the hosting site's mysql cause they give me space..... so i have a subdomain so should i use the url as the host???? Im lost.. And how do i enable error checking??

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.