Jump to content

Trouble inserting into a table [MySQL]


Gyohdon
 Share

Recommended Posts

This is the code I'm using to try and submit something into a table. However, it doesn't seem to work.Can anyone help me?Note: When echo-ing the variables without mysql_real_escape_string, it returns. However, echo-ing those variables WITH mysqlrealescapestring don't work.

<?php$realname_insert = mysql_real_escape_string($_POST['realname'],$con);$email_insert = mysql_real_escape_string($_POST['email'],$con);$title_insert = mysql_real_escape_string($_POST['title'],$con);$idea_insert = mysql_real_escape_string($_POST['idea'],$con);$realname = $_POST['realname'];$email = $_POST['email'];$category = $_POST['category'];$title = $_POST['title'];$idea = $_POST['idea'];include('include/Include_mysql.php');$tablecreate = mysql_query("CREATE TABLE IF NOT EXISTS  `$database`.`$category` (								`ID` INT NOT NULL AUTO_INCREMENT ,								`Title` VARCHAR( 100 ) NOT NULL ,								`Name` VARCHAR( 50 ) NOT NULL ,								`Email` VARCHAR( 50 ) NOT NULL ,								`Idea` TEXT NOT NULL ,								`Responses` INT NULL ,								`Views` INT NULL ,								`Rates` INT NULL ,								PRIMARY KEY (  `ID` )								) ENGINE = MYISAM ;");if (!$tablecreate)	{	die('Error: ' . mysql_error());	}$sql = "INSERT INTO `$category` (Name, Email, Title, Idea)VALUES ('$realname_insert', '$email_insert', '$title_insert', '$idea_insert')";if (!mysql_query($sql))  {  die('Error: ' . mysql_error());  }mysql_close($con);?>

Edited by Gyohdon
Link to comment
Share on other sites

mysql_real_escape_string() needs a active mysql connection as its parameter. otherwise it shows empty.mysql_real_escape_string($something,$mysql_con);

Link to comment
Share on other sites

mysql_real_escape_string() needs a active mysql connection as its parameter. otherwise it shows empty.mysql_real_escape_string($something,$mysql_con);
I tried it but it still returns empty.
Link to comment
Share on other sites

The problem is you don't have a connection to begin with.You're only creating it when you include the file.Move the include file at the top, like:

<?phpinclude 'include/Include_mysql.php';$realname_insert = mysql_real_escape_string($_POST['realname'],$con);//etc.

Link to comment
Share on other sites

The problem is you don't have a connection to begin with.You're only creating it when you include the file.Move the include file at the top, like:
<?phpinclude 'include/Include_mysql.php';$realname_insert = mysql_real_escape_string($_POST['realname'],$con);//etc.

Herpderp, that was a stupid mistake.Thanks.And yes, it works.Thanks a lot guys :) Edited by Gyohdon
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...