Lamez Posted October 13, 2007 Share Posted October 13, 2007 I am having tons of problems with this please help me out thanks <?php include ("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // insert the data $insert = mysql_query("insert into $table values ($_POST['email']')"); or die("Could not insert data because ".mysql_error()); // print a success message echo "E-Mail Added To Database, starting to e-mail."; echo "<meta http-equiv=Refresh content=2; URL=mailing.php>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73086-what-is-wrong-with-this/ Share on other sites More sharing options...
ThYGrEaTCoDeR201 Posted October 13, 2007 Share Posted October 13, 2007 Well I can't really see anything wrong with it, except for your queries. For good practice always use INSERT INTO instead of insert into. This will help you in the future, and it also helps you fix scripts easily. Quote Link to comment https://forums.phpfreaks.com/topic/73086-what-is-wrong-with-this/#findComment-368607 Share on other sites More sharing options...
AndyB Posted October 13, 2007 Share Posted October 13, 2007 I am having tons of problems with this please help me out care to identify one or two of the problems for us? Quote Link to comment https://forums.phpfreaks.com/topic/73086-what-is-wrong-with-this/#findComment-368609 Share on other sites More sharing options...
Lamez Posted October 13, 2007 Author Share Posted October 13, 2007 I here is one error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /mounted-storage/home48c/sub007/sc33591-LWQU/uploads/vote/insert.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/73086-what-is-wrong-with-this/#findComment-368627 Share on other sites More sharing options...
Rithiur Posted October 13, 2007 Share Posted October 13, 2007 There are three parse errors in that code. 1. In the code you posted, in line 13 you have $_POST['email'] inside string. This should be $_POST because you are not using curly syntax. 2. Line 13 has extra ; in the end, which should not be there because of the OR in the next line 3. There is extra } at the end in line 20 In addition, there is problem in your SQL syntax. You don't have quotes around the email, so MySQL doesn't understand it as string. Also, user input values should always be escaped, when entered into query in order to avoid SQL injections. Here is code that might actually work (plus, I added the mysql_real_escape_string there for escaping user input data) <?php include ("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // insert the data $insert = mysql_query("insert into $table values ('" . mysql_real_escape_string($_POST["email"]) . "')") or die("Could not insert data because ".mysql_error()); // print a success message echo "E-Mail Added To Database, starting to e-mail."; echo "<meta http-equiv=Refresh content=2; URL=mailing.php>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73086-what-is-wrong-with-this/#findComment-368630 Share on other sites More sharing options...
redarrow Posted October 13, 2007 Share Posted October 13, 2007 my little say....... <?php include ("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // insert the data // always set a form condiction..... if(isset($_POST['submit'])){ //<<<<dont post within database statements...... $email=$_POST["email"]; $insert = mysql_query("insert into $table values ('$email')"); or die("Could not insert data because ".mysql_error()); // print a success message echo "E-Mail Added To Database, starting to e-mail."; echo "<meta http-equiv=Refresh content=2; URL=mailing.php>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73086-what-is-wrong-with-this/#findComment-368638 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.