HELP NEED TO INSERT FORM DATA INTO MYSQL DATABASE

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

ammaflagathon
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Jan 12, 2013 12:23 am

HELP NEED TO INSERT FORM DATA INTO MYSQL DATABASE

Postby ammaflagathon » Mon Jan 14, 2013 12:40 pm

:help:
Guys I'm student trying to create a website using PHP & MySQL.
I'm having hard time accessing the database.
My website has been hosted for testing!

website: [url]ammatest.bugs.com[/url]
In the http://ammatest.bugs3.com/Register.html page when i enter all details & click submit, it will post the values to insert.php, but I'm getting this error!
Error: No database selected


The code of insert.php is:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
$con = mysql_connect("mysql.serversfree.com","u967246295_root","anandrao");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

$sql="INSERT INTO `reg` (t3, t4, t1, t6, t8, t9, t10, t11, t12) VALUES('$_POST[t3]','$_POST[t4]','$_POST[t1]','$_POST[t6]','$_POST[t8]','$_POST[t9]','$_POST[t10]','$_POST[t11]','$_POST[t12]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "YOU ARE REGISTERED SUCCESSFULLY!";
mysql_close($con);
?>
<body>
</body>
</html>


Please help!
I'm running out of time! :(

iamabhinav
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Feb 03, 2013 2:38 am

Re: HELP NEED TO INSERT FORM DATA INTO MYSQL DATABASE

Postby iamabhinav » Sun Feb 03, 2013 2:42 am

you have connected to the mysql..but you did not select the database.
To select a database you need to add the following line of code:

Code: Select all

mysql_select_db("Your_database_name");


Return to “Your Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron