Hi guys. As you can probably see this is my first post on PHPBuilder. Loving the site already. Great sense of community.
So, down to the work. I have recently started learning PHP so I grant you permission to call me a noob. 🙂
I am having issues adding variables filled with text (in this case customer information) into a localhost (wampserver) MySQL Database. Ill show you what I have so far.
Config.php: Connects to my MySQL Database:
<?php
// Initiate MYSql Details
$MYSQL_Host = "localhost"; // Where the MySQL Database is located.
$MYSQL_Username = "root"; // MySQL Username.
$MYSQL_Password = ""; // MySQL Password.
$MYSQL_DbName = "iprint"; // Database name to connect to.
// Connect to MySQL Database (with OR DIE statement).
$MYSQL_Connection = mysql_connect($MYSQL_Host, $MYSQL_Username, $MYSQL_Password) or die ('MySQL Error: Failed to Connect to Database. Please see Cconfig.php. mysqli_connec() reported this error.');
// Select Database.
mysql_select_db($MYSQL_DbName, $MYSQL_Connection);
?>
addcustomer.php: Shows the form to fill in customer details.
<html>
<head>
</head>
<body>
<h2>Add Customer</h2>
<form action="doinsertcustomer.php" method="post">
Business Name: <input type="text" name="bname" size="16" maxlength="32" /><br />
Email: <input type="text" name="email" size="16" maxlength="32" /><br />
Phone: <input type="text" name="phone" size="16" maxlength="32" /><br />
Contact Name: <input type="text" name="cname" size="16" maxlength="32" /><br />
Melway Ref: <input type="text" name="melway" size="16" maxlength="32" /><br />
<input type="submit" value="Submit Customer" /><br />
</form>
</body>
</html>
doinsertcustomer.php: Gets variables via $_POST[] from addcustomer.php and tries to insert them into the MySQL database:
<?php
include_once "config.php"; // Connects to MySQL Database. See Config.php for details.
$name = $_POST['bname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$cname = $_POST['cname'];
$melway = $_POST['melway'];
$sql = "INSERT INTO `iprint`.`customers` (`Name`, `Email`, `Phone`, `Contact Name`, `SORCDD`, `Melway`, `Comments`, `CID`) VALUES (\'$name\', \'$email\', \'$phone\', \'$cname\', \'\', \'$melway\', \'\', NULL);";
mysql_query($sql); // Insert information from form to MySQL Database.
?>
When I insert information into the form and then press submit it runs 'doinsertcustomer.php' but when I check my PHPMyAdmin it is not there. I really need help on this as this is a very important task. Thanks for all your help guys. I really appreciate it.