Sammy West Sammy West - 1 year ago 98
PHP Question

Trouble Linking forms to a php controller

i think im missing some post variables in this code. I'm not exactly sure how to place the post variables and link them to the controller in order to get submission forms going. I've read hours and hours and my minds still fuzzy on the concept. Now with this php controller, i can manually enter in data, but automatically uploading it via form is confusing me. I think im making it overly complicated and i know its just 1 or 2 steps from being completed. My mysql server is behind my lan, so the only thing that is publically accessable is my port 80 website. I hope i can get this resolved, its been murder on my brain lately lol

If i can't figure it out, ill just migrate it over to web2py. its more confusing but easier on the database front from what i've seen in organization of syntax. One last problem. The database isn't automatically creating new ID rows. I have it set to primary in the database and should automatically create new records, but for some reason it doesn't.

<form action="SubmissionForm.php" method="post">
<label>Name:</label><input type='text' name='user'/>
<label>Message:</label><input type='text' name='message'>
<input type='submit' value='Submit'>


$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if(! $conn ) {
die('Could not connect: ' . mysql_error());

$sql = "INSERT INTO testmessage2 ". "(user, message) ". "VALUES(user, message);

$retval = mysql_query( $sql, $conn );

if(! $retval ) {
die('Could not enter data: ' . mysql_error());

echo "Entered data successfully\n";


Answer Source
//captured the form data in variable 

$user= mysql_real_escape_string($_POST['user']);

$message= mysql_real_escape_string($_POST['message']);

$sql = "INSERT INTO testmessage2 (user, message) VALUES('$user','$message')";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download