neuralsyntax Posted November 2, 2010 Share Posted November 2, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 There is no mysql_query() statement in it to executing the query. At line 123 in the file, you set $sql = "... ..."; but you never put that into a mysql_query() statement to execute it. Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129535 Share on other sites More sharing options...
neuralsyntax Posted November 2, 2010 Author Share Posted November 2, 2010 Thank you for the quick response. So when I add mysql_query($sql); after that line I get some crazy errors when it processes the form. Sorry I'm still a newb at this stuff Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129537 Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 I get some crazy errors when it processes the form Cannot help you with any of them unless you post them. Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129538 Share on other sites More sharing options...
neuralsyntax Posted November 2, 2010 Author Share Posted November 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129539 Share on other sites More sharing options...
awjudd Posted November 2, 2010 Share Posted November 2, 2010 Your connection to your database is wrong (probably your username / password). ~judda Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129557 Share on other sites More sharing options...
neuralsyntax Posted November 2, 2010 Author Share Posted November 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129560 Share on other sites More sharing options...
Pikachu2000 Posted November 2, 2010 Share Posted November 2, 2010 Then you don't have the hostname properly specified, because it's attempting to connect to the MySQL server located at localhost. Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129563 Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129568 Share on other sites More sharing options...
neuralsyntax Posted November 2, 2010 Author Share Posted November 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129577 Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 Paste it into the post and with it selected, hit the # menu button to surround it in bbcode tags. Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129578 Share on other sites More sharing options...
neuralsyntax Posted November 2, 2010 Author Share Posted November 2, 2010 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129580 Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 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.) Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129581 Share on other sites More sharing options...
neuralsyntax Posted November 2, 2010 Author Share Posted November 2, 2010 Thanks for all your help folks!! Quote Link to comment https://forums.phpfreaks.com/topic/217580-no-output-to-sql-database/#findComment-1129602 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.