Jump to content

SPOT the NOT


user4fun
 Share

Recommended Posts

I can't see why this is nor working but ooh well, take a crack at it if you well<html><head> </head><body><?php$host="http://mydomain.com/directory where mysql is installed/"; // Host name $username="my user name"; // Mysql username $password="mypassword"; // Mysql password $db_name="Customer"; // Database name $tbl_name="subscribe"; // Table name $status = "OK"; // setting the flag to check the status$msg=""; // setting the variable for messageif (!stristr($em,"@") OR !stristr($em,".")) {$msg="Your email address is not correct<BR>";$status= "NOTOK";} echo "<br><br>";if($status=="OK"){// Now the email is valid and we can add to our database$query=("INSERT INTO subscribe (em,status) VALUES ('$em','subscribe')");$result=mysql_query($query);echo "<center>THANK YOU <br>Thanks for subscribing to our newsletter and any time you can unsubscribe by clicking a link in your newsletter. </center>"; }else {echo "<center>$msg </center>";} // this will display the error message if email address is not valid one.?> </body></html>

Link to comment
Share on other sites

ok I see where you went wrong, you forgot 2 very important lines. the connection to mysql and the slection of a database

$host="http://mydomain.com/directory where mysql is installed/"; // Host name $username="my user name"; // Mysql username $password="mypassword"; // Mysql password $db_name="Customer"; // Database name $tbl_name="subscribe"; // Table name $db = mysql_connect($host,$username,$password)if(!$db)  die("Unable to connect to MySql");@mysql_select_db($db_name) or die("Unable to select database");...

give that a try

Link to comment
Share on other sites

thank you for trying to help so far my php file that is suppost to conenct or say die could not connect shows up as an empty file.and the record does not get addedhere is all i have maybe the problem is from the root.FILE 1 enter.php<html><head> <title>Untitled</title></head><body><?phpecho " <table border='0' width='100%' cellspacing='0' cellpadding='0' bgcolor='$mail_bgcolor'><tr><td><font face='Verdana' size='2'>Sign up for newsletter</font></td></tr><tr><td align=center><form method=post action=newsletter.php><input type='text' name='em' value = 'Your Email' size=15><br><input type='submit' value = 'Signup'></form></td></tr></table>"; ?> </body></html>FILE 2 newsletter.php<html><head> <title>Untitled</title></head><body><?phpforeach ($_POST as $field => $em){ echo "your submitted email address is $em<br>";}echo " <table border='0' width='100%' cellspacing='0' cellpadding='0' bgcolor='$mail_bgcolor'><tr><td><font face='Verdana' size='2'>Thank you for signing up, click submit so we would add you to the mailing list</font></td></tr><tr><td align=center><form method=post action=AddInfo.php><input type='submit' value = 'Add Me'></form></td></tr></table>"; ?></body></html>FILE 3 AddInfo.php<html><head> <title>Untitled</title></head><body><?php$host="http://aaa.aa/aaa_aaa/"; // Host name, it is not really aaaa lol $username="cccccc"; // Mysql username , cc is reaplaced with my username$password="*******"; // Mysql password , the stars are replaced by my actuall password$db_name="Customer"; // Database name $tbl_name="subscribe"; // Table name $db = mysql_connect($host,$username,$password)if(!$db) die("Unable to connect to MySql");@mysql_select_db($db_name) or die("Unable to select database");$query="INSERT INTO subscribe (em,status) VALUES ('$em', 'subscribe')";?></body></html>and that is it folks, i am just not seeing it lolthankx for reading this far.

Link to comment
Share on other sites

Try this:

$dblocation = ""; $dbusername = ""; $dbpassword = ""; $dbdatabase = ""; $dbconn = mysql_connect("$dblocation","$dbusername","$dbpassword") or die ("Could not connect to MySQL");$selectdb = mysql_select_db($dbdatabase,$dbconn) or die ("Could not open database");//Make sure that $em has a value$sql="INSERT INTO subscribe (em,status) VALUES ('$em', 'subscribe')";$query=mysql_query($sql);if($query){     echo "Subscription has been completed successfully";}else{     echo "Subscription has NOT been completed successfully";}

I'll be bold enough to say that that will work.

Link to comment
Share on other sites

woho, we are getting somewhere,one last issuethe result was "Could not connect to MySQL"under the url AddInfo.phpwe are almost there, i am going to say that you are the king and the bold statment was right on the money.I will keep playing with for a while to find out why i got that message.If you have any ideas, please feel fre to share.THANK YOU VERY MUCH FOR HELPING THIS FAR.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...