Redneckheaven Posted November 29, 2009 Share Posted November 29, 2009 Not sure what the problem is here. This is the php code I made to post to database table but when I submit the info it doesnt appear in the table. Here is the code. Maybe someone here can help me out. Pretty new to php. Just testing to see if info gets submitted to table then will work on retrieving data and putting it in the guestbook entries. <?php // Database Connectivity $DBhost = "localhost"; // Database Server $DBuser = "user name"; // Database User $DBpass = "*****"; // Database Pass $DBName = "name of database"; // Database Name $table = "guestbook"; // Database Table // Recieve Variables From Flash $submit = $_POST['submit']; $name = $_POST['name']; $email = $_POST['email']; $website = $_POST['website']; $location = $_POST['location']; $comments = $_POST['comments']; $name = ereg_replace("[^A-Za-z0-9 ]", "", $name); $email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $email); $website = eregi_replace("http://", "", $website); $website = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $website); $location = ereg_replace("[^A-Za-z0-9 ]", "", $location); $comments = eregi_replace('&', ' and ',$comments); $comments = eregi_replace('<', '*',$comments); $comments = eregi_replace('>', '*',$comments); $comments = eregi_replace('f', '****',$comments); $comments = eregi_replace('s', '****',$comments); $comments = eregi_replace('b', '****',$comments); $comments = eregi_replace('b', '****',$comments); $comments = eregi_replace('ct', '****',$comments); $comments = eregi_replace('s', '****',$comments); $comments = eregi_replace('c', '****',$comments); $comments = eregi_replace('w', '****',$comments); $comments = eregi_replace('n', '****',$comments); $comments = eregi_replace('gl', '@#*!#%',$comments); $comments = eregi_replace('s', '****',$comments); $comments = eregi_replace('s', '$@*%!#',$comments); $comments = eregi_replace('d', '****',$comments); $comments = eregi_replace('p', '****',$comments); $comments = eregi_replace('d', '$@*%!#',$comments); $comments = eregi_replace('p', '****',$comments); $comments = eregi_replace('w', '****',$comments); $comments = eregi_replace('n', '#@%!$',$comments); $name = stripslashes($name); $email = stripslashes($email); $website = stripslashes($website); $location = stripslashes($location); $comments = stripslashes($comments); $submitted_on = date ("l F dS Y ( g:i:s a )",time()); $ip = $_SERVER['REMOTE_ADDR']; //Check if its submitted from Flash if($submit == "YES"){ //Insert the data into the mysql table $sql = "INSERT INTO $table (ID, name, email, website, location, comments, date, ip) VALUES ('$name', '$email', '$website', '$location', '$comments', '$submitted_on', '$ip')", $result = mysql_query($sql, $DBConn) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/ Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 I suggest you put error_reporting(E_ALL); at the top of your file. You should be getting a mysql error like 'column count doesn't match value count', because you're specifying 8 columns to insert into, but only providing 7 values. If `ID` is an auto_increment field it's not even necessary to include it in your query, so just remove it. [ot]You shouldn't be using ereg functions anymore as they're depreciated, instead use the PCRE functions. In your case preg_replace.[/ot] Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967631 Share on other sites More sharing options...
adrek Posted November 29, 2009 Share Posted November 29, 2009 you never connect to the database or choose your database. add this before your mysql query. //connect to the database $DBConn = mysql_connect($DBhost, $DBuser, $DBpass); //Check the connection but is not necessary if(!DBConn) die("Could not connect"); //choose the database $db_selected = mysql_select_db($DBName, $DBConn); this should work Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967633 Share on other sites More sharing options...
MisterWebz Posted November 29, 2009 Share Posted November 29, 2009 You didn't define $DBConn . Try using something like this: <?php $con = mysql_connect("localhost","username","****"); $result = mysql_query($sql, $con) or die(mysql_error()); ?> edit: oops adrek beat me to it. Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967634 Share on other sites More sharing options...
Redneckheaven Posted November 29, 2009 Author Share Posted November 29, 2009 Ok here is what I have now, still doesnt show in the guestbook table; <?php // Database Connectivity $DBhost = "localhost"; // Database Server $DBuser = "user"; // Database User $DBpass = "*****"; // Database Pass $DBName = "database name"; // Database Name $table = "guestbook"; // Database Table // Connection $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error()); // Select Database mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error()); // Recieve Variables From Flash $submit = $_POST['submit']; $name = $_POST['name']; $email = $_POST['email']; $website = $_POST['website']; $location = $_POST['location']; $comments = $_POST['comments']; $name = preg_replace("[^A-Za-z0-9 ]", "", $name); $email = preg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $email); $website = preg_replace("http://", "", $website); $website = preg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $website); $location = preg_replace("[^A-Za-z0-9 ]", "", $location); $comments = preg_replace('&', ' and ',$comments); $comments = preg_replace('<', '*',$comments); $comments = preg_replace('>', '*',$comments); $comments = preg_replace('f', '****',$comments); $comments = preg_replace('s', '****',$comments); $comments = preg_replace('b', '****',$comments); $comments = preg_replace('b', '****',$comments); $comments = preg_replace('c', '****',$comments); $comments = preg_replace('s', '****',$comments); $comments = preg_replace('c', '****',$comments); $comments = preg_replace('w', '****',$comments); $comments = preg_replace('n', '****',$comments); $comments = preg_replace('g', '@#*!#%',$comments); $comments = preg_replace('s', '****',$comments); $comments = preg_replace('s', '$@*%!#',$comments); $comments = preg_replace('d', '****',$comments); $comments = preg_replace('p', '****',$comments); $comments = preg_replace('d', '$@*%!#',$comments); $comments = preg_replace('p', '****',$comments); $comments = preg_replace('w', '****',$comments); $comments = preg_replace('n', '#@%!$',$comments); $name = stripslashes($name); $email = stripslashes($email); $website = stripslashes($website); $location = stripslashes($location); $comments = stripslashes($comments); $submitted_on = date ("l F dS Y ( g:i:s a )",time()); $ip = $_SERVER['REMOTE_ADDR']; //Check if its submitted from Flash if($submit == "YES"){ //Insert the data into the mysql table $sql = "INSERT INTO $table (name, email, website, location, comments, date, ip) VALUES ('$name', '$email', '$website', '$location', '$comments', '$submitted_on', '$ip')", $result = mysql_query($sql, $DBConn) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967649 Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 I suggest you put error_reporting(E_ALL); at the top of your file. Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967651 Share on other sites More sharing options...
adrek Posted November 29, 2009 Share Posted November 29, 2009 is it creating a row in the guestbook table with all blank values or is it just not doing anything? Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967655 Share on other sites More sharing options...
Redneckheaven Posted November 29, 2009 Author Share Posted November 29, 2009 Ok I tried putting error_reporting(E_ALL); . Like I said just learning this pp stuff. Then I put that at the top right above (see below) When it hit send it cleared the form like I wanted to so seems it connected but why not posting. NO ERROR showed up. Could it be on my send button that the problem is. On Send button i have (see below) Its not doing anything. I created a database in MyAdmin with the rows as Name, Email, Website, Location, Comments, Date, IP. After submitting i go to myAdmin check database and no posting. <?php error_reporting(E_ALL); // Database Connectivity $DBhost = "localhost"; // Database Server $DBuser = "user name"; // Database User $DBpass = "*****"; // Database Pass $DBName = "name of database"; // Database Name $table = "guestbook"; // Database Table Send Button: on(press){ if (name eq "") { status = "Required: Name"; } else if (email eq "") { status = "Required: Email Address"; } else if (!email.length || email.indexOf("@") == -1 || email.indexOf(".") == -1) { status = "Required: Valid Email Address"; } else if (location eq "") { status = "Please Enter Your State/Location"; } else if (comments eq "") { status = "Required: Comments"; } else { Submit = "Yes"; loadVariables("Registery.php",'POST'); // Clear fields name = ""; email = ""; website = ""; location = ""; comments = ""; status = ""; Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967656 Share on other sites More sharing options...
Redneckheaven Posted November 30, 2009 Author Share Posted November 30, 2009 Have tried all kinds of things and still no info is posted to database. I get NO errors when I hit send. Have checked and database name is right, password is right, user is right, and table is right. Not sure why nothing happens, sent to database. Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967815 Share on other sites More sharing options...
Alex Posted November 30, 2009 Share Posted November 30, 2009 It seems this has evolved into more of an ActionScript problem, unless you can confirm that the values are being sent to the PHP file. It appears that you're using AS2.0, the majority of my ActionScript knowledge lies with AS3.0, but if you post your entire ActionScript source I can try to help you. Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967826 Share on other sites More sharing options...
Redneckheaven Posted November 30, 2009 Author Share Posted November 30, 2009 Im not doing this in Flash Pro, using Swishmax. I know that using this on submit button works using a different php writing to a TEXT file. Want to use database instead. Hopefully this will help you out. This is what I have on my send button: on(press){ if (name eq "") { status = "Required: Name"; } else if (email eq "") { status = "Required: Email Address"; } else if (!email.length || email.indexOf("@") == -1 || email.indexOf(".") == -1) { status = "Required: Valid Email Address"; } else if (location eq "") { status = "Please Enter Your State/Location"; } else if (comments eq "") { status = "Required: Comments"; } else { submit = "Yes"; loadVariablesNum("Registery.php",0,'POST'); // Clear fields name = ""; email = ""; website = ""; location = ""; comments = ""; status = ""; Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967869 Share on other sites More sharing options...
Redneckheaven Posted November 30, 2009 Author Share Posted November 30, 2009 Heck with it cant seem to figure it out. Would rather use a database instead of txt file but looks like Im going to have to continue to use txt file. Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967925 Share on other sites More sharing options...
Alex Posted November 30, 2009 Share Posted November 30, 2009 Are you completely positive the request is getting to the file? If you really do have error_reporting(E_ALL); at the top of your file you should be receiving errors right now because unlike the ereg functions the PCRE functions require delimiters. Ex: preg_replace("[^A-Za-z0-9 ]", "", $name); should be: preg_replace("~[^A-Za-z0-9 ]~", "", $name);. You should change all of the other patterns accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967928 Share on other sites More sharing options...
Redneckheaven Posted November 30, 2009 Author Share Posted November 30, 2009 I do have error_reporting(E_ALL); at the top. Thats why Im confused on why if there are errors i get nothing showing errors. Here is the top of my php code and yo will see its there. Here is a link to check it out. This is just a test form to see if sends to database. www.redneckheaven.net <?php error_reporting(E_ALL); // Database Connectivity Variables and other Variables $DBhost = "localhost"; // Database Server $DBuser = "user"; // Database User $DBpass = "******"; // Database Pass $DBName = "database name"; // Database Name $table = "guestbook"; // Database Table // Connect to mySQL Server $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error()); // Select mySQL Database mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-967936 Share on other sites More sharing options...
Redneckheaven Posted November 30, 2009 Author Share Posted November 30, 2009 Ok my fault I checked my error log and this is what I got; PHP Parse error: syntax error, unexpected T_VARIABLE in /home/redneck6/public_html/Registery.php on line 71 PHP Parse error: syntax error, unexpected ',' in /home/redneck6/public_html/Registery.php on line 71 I must be blind I dont see what the problem is. Here is the full code <?php error_reporting(E_ALL); // Database Connectivity Variables and other Variables $DBhost = "localhost"; // Database Server $DBuser = "redneck6_redneck"; // Database User $DBpass = "(harley2007)"; // Database Pass $DBName = "redneck6_Guestbook"; // Database Name $table = "guestbook"; // Database Table // Connect to mySQL Server $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error()); // Select mySQL Database mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error()); // Recieve Variables From Flash $submit = $_POST['submit']; $name = $_POST['name']; $email = $_POST['email']; $website = $_POST['website']; $location = $_POST['location']; $comments = $_POST['comments']; $name = preg_replace("[^A-Za-z0-9 ]", "", $name); $email = preg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $email); $website = preg_replace("http://", "", $website); $website = preg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $website); $location = preg_replace("[^A-Za-z0-9 ]", "", $location); $comments = preg_replace('&', ' and ',$comments); $comments = preg_replace('<', '*',$comments); $comments = preg_replace('>', '*',$comments); $comments = preg_replace('fuck', '****',$comments); $comments = preg_replace('shit', '****',$comments); $comments = preg_replace('bitch', '****',$comments); $comments = preg_replace('bastard', '****',$comments); $comments = preg_replace('cunt', '****',$comments); $comments = preg_replace('slut', '****',$comments); $comments = preg_replace('cum', '****',$comments); $comments = preg_replace('whore', '****',$comments); $comments = preg_replace('nigger', '****',$comments); $comments = preg_replace('go to hell', '@#*!#%',$comments); $comments = preg_replace('suck', '****',$comments); $comments = preg_replace('suck me', '$@*%!#',$comments); $comments = preg_replace('dick', '****',$comments); $comments = preg_replace('pussy', '****',$comments); $comments = preg_replace('dick head', '$@*%!#',$comments); $comments = preg_replace('penis', '****',$comments); $comments = preg_replace('whore', '****',$comments); $comments = preg_replace('niger', '#@%!$',$comments); $name = stripslashes($name); $email = stripslashes($email); $website = stripslashes($website); $location = stripslashes($location); $comments = stripslashes($comments); $submitted_on = date ("l F dS Y ( g:i:s a )",time()); $ip = $_SERVER['REMOTE_ADDR']; //Check if its submitted from Flash if($submit == 'YES'){ //Insert the data into the mysql table $sql = "INSERT INTO $table (name, email, website, location, comments, date, ip) VALUES ('$name', '$email', '$website', '$location', '$comments', '$submitted_on', '$ip')", $result = mysql_query($sql, $DBConn) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183317-posting-to-database/#findComment-968243 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.