Jump to content


Photo

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


  • Please log in to reply
11 replies to this topic

#1 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 30 July 2006 - 11:52 PM

???

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-ya...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...


#2 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 31 July 2006 - 12:20 AM

you can read up here to help you get started

http://www.phpfreaks...orials/65/0.php

#3 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 31 July 2006 - 04:22 AM

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.........

#4 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 31 July 2006 - 05:07 AM

TRY :

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

$result = mysql_query($sql) or die (mysql_error());



Shishya

#5 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 31 July 2006 - 05:30 AM

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.");
?>


#6 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 31 July 2006 - 05:34 AM

close the quote in this .

$database_name = 'name;



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


Shishya

#7 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 31 July 2006 - 05:40 AM

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.

#8 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 31 July 2006 - 06:24 AM

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 ?


Shishya

#9 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 31 July 2006 - 04:38 PM

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.

#10 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 01 August 2006 - 02:31 PM

I remember some of the the gurus always recommending not to use shortcuts while querying - its much harder to locate the error.

$sql2 = mysql_query(Create Table phptest);

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


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.




Shishya

#11 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 02 August 2006 - 04:28 AM

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??

#12 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 02 August 2006 - 05:30 PM

swatisonee  u been alot of help but it just dont work i cant seem to figure it out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users