Jump to content

Recommended Posts

Hoping someone can help me.  My attached code will not output anything to my tables.  I am not getting any errors or anything, when I submit the registration, it takes me to my newmember page fine and the email is sent, but nothing is sent to my database/tables.  If someone can help me out here, I'm at a loss.  Thanks so much!

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/
Share on other sites

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\inetpub\vhosts\pos-x.com\httpdocs\Login.php on line 125

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\inetpub\vhosts\pos-x.com\httpdocs\Login.php on line 125

 

Warning: Cannot modify header information - headers already sent by (output started at C:\inetpub\vhosts\pos-x.com\httpdocs\Login.php:125) in C:\inetpub\vhosts\pos-x.com\httpdocs\Login.php on line 136

 

All I did was add mysql_query($sql); after line 123 in the file

I understand where you would think that; but I have the username and password in my db connection file and I'm not actually connecting to my localhost, I'm connecting to a server elsewhere.  After I added that query is when I started receiving that error.  I am confused :(

You have no connection at the time the mysql_query() is being executed. Since I didn't see (your code has no indentation, so it is difficult to locate anything in it) any statement closing the connection, you either never create a valid connection or some of the included code is closing the connection.

Is there a better way I can attach the code for you to be able to see?

 

This is what I have for connecting to the db:

$connection = mysql_connect($host, $user,$password)

or die (“Couldn’t connect to server.”);

$db = mysql_select_db($database, $connection)

or die (“Couldn’t select database.”);

 

and my db information is in a separate file, and I have verified that the host, user and password are correct there. 

login.php

<?php
/* Program: Login.php
* Desc: Login program for the Members Only section of the
* pet store. It provides two options: (1) login* using an existing Login Name and (2) enter a new
* login name. Login Names and passwords are stored
* in a MySQL database.
*/
session_start(); # 9
include("dogs.inc"); #10
switch (@$_GET['do']) #11
{
case "login": #13
$connection = mysql_connect($host,$user,$password) #14
or die ("Couldn't connect to server.");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database."); #17
$sql = "SELECT loginName FROM Member
WHERE loginName='$_POST[fusername]'"; #20
$result = mysql_query($sql)
or die("Couldn't execute query."); #22
$num = mysql_num_rows($result); #23
if ($num == 1) // login name was found #24
{
$sql = "SELECT loginName FROM Member
WHERE loginName='$_POST[fusername]'
AND password=password('$_POST[fpassword]')";
$result2 = mysql_query($sql)
or die("Couldn't execute query 2."); #30
$num2 = mysql_num_rows($result2);
if ($num2 > 0) // password is correct #32
{
$_SESSION['auth']="yes"; #34
$logname=$_POST['fusername'];
$_SESSION['logname'] = $logname; #36
$today = date("Y-m-d h:m:s"); #37
$sql = "INSERT INTO Login (loginName,loginTime)
VALUES ('$logname','$today')";
mysql_query($sql) or die("Can't execute query.");
header("Location: Member_page.php"); #41
}
else // password is not correct #43
{
unset($do); #45
$message="The Login Name, '$_POST[fusername]'
exists, but you have not entered the
correct password! Please try
again.<br>";
include("login_form.inc"); #49
}
} #51
elseif ($num == 0) // login name not found #52
{
unset($do); #54
$message = "The Login Name you entered does not
exist! Please try again.<br>";
include("login_form.inc");
}
break; #59
case "new": #61
foreach($_POST as $field => $value) #62
{
if ($field != "fax") #64
{
if ($value == "") #66
{
unset($_GET['do']);
$message_new = "Required information is missing.
Please try again.";
include("login_form.inc");
exit();
}
}
if (ereg("(Name)",$field)) #75
{
/*if (!ereg("^[A-Za-z' -]{1,50}$",$value))
{
unset($_GET['do']);
$message_new = "$field is not a valid name.
Please try again.";
include("login_form.inc");
exit();
}*/
}
$$field = strip_tags(trim($value)); #86
} // end foreach
if (!ereg("^[0-9]{5,5}(\-[0-9]{4,4})?$",$zip)) #88
{
unset($_GET['do']);
$message_new = "$zip is not a valid zip code.
Please try again.";
include("login_form.inc");
exit();
}
if (!ereg("^[0-9)(xX -]{7,20}$",$phone)) #96
{
unset($_GET['do']);
$message_new = "$phone is not a valid phone number.
Please try again.";
include("login_form.inc");
exit();
}
if ($fax != "") #104
{
if (!ereg("^[0-9)(xX -]{7,20}$",$fax))
{
unset($_GET['do']);
$message_new = "$fax is not a valid phone number.
Please try again.";
include("login_form.inc");
exit();
}
}
if (!ereg("^.+@.+\\..+$",$email)) #115
{
unset($_GET['do']);
$message_new = "$email is not a valid email address.
Please try again.";
include("login_form.inc");
exit();
} #122
{
$today = date("Y-m-d"); #143
$sql = "INSERT INTO Member (firstname,lastname,createDate,street,city,state,zip,email,phone,fax,serial,model) 
VALUES ('$firstname','$lastname','$today','$street','$city','$state','$zip','$email','$phone','$fax','$serial','$model')";
mysql_query($sql);
$_SESSION['auth']="yes"; #151
$_SESSION['logname'] = $newname; #152
/* send email to new member */ #153
$emess = "Your POS-X Product has now been submitted for registration. ";
$emess.= "Your product information is: ";
$emess.= "\n\n\tSerial:$serial\n\tModel:$model\n\n";
$emess.= "\n\tYour name:$firstname $lastname\n\t$email\n\n";
$emess.= "If you have any questions or problems,";
$emess.= " email support@pos-x.com";
$ehead="From: info@pos-x.com\r\n"; #161
$subj = "Your new Product Registration Information";
$mailsend=mail("$email","$subj","$emess","$ehead");
header("Location: New_member.php");
}
break; 
default: 
include("login_form.inc");
}
?>

login_form.inc

<?php
/* File: login_form.inc
* Desc: Displays login page. Page displays two forms--one
* form for entering an existing login name and
* password and another form for the information
* needed to apply for a new account.
*/
include("functions12.inc"); # 8
?>
<html>
<head><title>Members Only Login</title></head>
<body topmargin="0" leftmargin="0" marginheight="0"
marginwidth="0">
<table border="0" cellpadding="5" cellspacing="0">
<tr><td colspan="3" bgcolor="gray" align="center">
<font color="white" size="+10">
<b>Register your product</b></font></td></tr>

<td width="67%">
<p><font size="+1"><b>Not registered yet?</b></font>
Get new product information, driver download updates, advance notice of
new products and much more. Fill in the information
below and join. It's easy and free! </b>
<!-- form for new member to fill in -->
<form action="Login.php?do=new" method="POST">
<p>
<table border="0" width="100%">
<?php
if (isset($message_new)) #55
echo "<tr><td colspan='2'><b>$message_new</b>
</td></tr>";
?>
<tr><td align="right"><b>Product Serial Number</b></td>
<td><input type="text" name="serial"
value="<?php echo @$serial ?>"
size="20" maxlength="20"></td></tr>
<tr><td align="right"><b>Model Number</b></td>
<td><input type="text" name="model"
value="<?php echo @$model ?>"
size="10" maxlength="8"></td></tr>
<tr><td align="right"><b>First Name</b></td>
<td><input type="text" name="firstname"
value="<?php echo @$firstname ?>"
size="40" maxlength="40"></td></tr>
<tr><td align="right"><b>Last Name</b></td>
<td><input type="text" name="lastname"
value="<?php echo @$lastname ?>"
size="40" maxlength="40"></td></tr>
<tr><td align="right"><b>Street</b></td>
<td><input type="text" name="street"
value="<?php echo @$street ?>"
size="55" maxlength="50"></td></tr>
<tr><td align="right"><b>City</b></td>
<td><input type="text" name="city"
value="<?php echo @$city ?>"
size="40" maxlength="40"></td></tr>
<tr><td align="right"><b>State</b></td>
<td><select name="state">
<?php
$stateName=getStateName(); #86
$stateCode=getStateCode(); #87
for ($n=1;$n<=50;$n++)
{
$state=$stateName[$n];
$scode=$stateCode[$n];
echo "<option value='$scode'";
if ($scode== "AL")
echo " selected";
echo ">$state\n";
}
?>
</select>
    <b>Zip</b>
<input type="text" name="zip"
value="<?php echo @$zip ?>"
size="10" maxsize="10">
</td></tr>
<tr><td align=right><b>Phone</b></td>
<td><input type="test" name="phone"
value="<?php echo @$phone ?>"
size="15" maxlength="20">
   <b>Fax</b>
<input type="test" name="fax"
value="<?php echo @$fax ?>"
size="15" maxlength="20"></td></tr>
<tr><td align=right><b>Email Address</b></td>
<td><input type="test" name="email"
value="<?php echo @$email ?>"
size="55" maxlength="67"></td></tr>
<tr><td> </td>
<td align="left">
<input type="submit"
value="Register Your Product"></td>
</tr>
</table>
</form>
</td>
</tr>
<tr><td colspan="3" bgcolor="gray"> </td></tr>
</table>
<div align="center"><font size="-1">
All comments and suggestions are appreciated. Please
send comments to <a href="mailto:info@pos-x.com">
POS-X</A> </font></div>
</body></html>

 

dogs.inc (for obvious reasons I have removed the password, but it is correct when there :)

<?php
$user="productregister";
$host="productregister.db.4113972.hostedresource.com";
$password="";
$database="productregister";
?>

Your form is setting ?do=new

 

In your form processing code, you are only creating a connection to the mysql server/selecte a database when ?do=login So, you don't have a connection in the select/case 'new': code.

 

You should connect to the mysql server/select a database at a common point in your code.

 

Also, please rename your include file to end in a .php extension so that someone cannot simply browse to it and see your connection details (as is the case when it does not end in a .php extension.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.