Jump to content

Posting to database


Redneckheaven

Recommended Posts

Not sure what the problem is here.  :confused:  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());
?>

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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());
?>

Link to comment
Share on other sites

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 = "";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 = "";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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());
?>

Link to comment
Share on other sites

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.