...

View Full Version : form post to php to sql database fields empty.



bubbbbbz
04-19-2011, 03:03 PM
hello i had it posting empty fields nbow its not posting at all

i have a form below on sign_up.tpl


<form name="register" method="post" action="tested.php">
Name:<br>
<input type="text" name="first_name">
<br>
Email: <br>
<input type="text" name="user_email">
<br>
Email2: <br>

<input type="text" name="user_email2">
<br>
Email3: <br>
<input type="text" name="user_email3">
<br><br>
<input type="Submit" name="Submit" value="Submit">
</form>

with action to tested.php

in my php it should insert to database but not


<?php
require_once 'includes/global.php';

if($smarty -> template_exists(basename(str_replace(DYNAMIC_EXTENSION,TEMPLATE_EXTENSION,$_SERVER['PHP_SELF']))))
{
####################################################################
################ DATABASE CONFIGURE ##############################
####################################################################
if (isset($_POST['register'])) {
//Create the databse link, ("localhost", "username", "password")
mysql_connect("", "", "")
OR die(mysql_error()); //for debugging
mysql_select_db("user_info")
OR die(mysql_error()); //for debugging
//ensure that items have been passed, and set them
if (!empty($_POST['user_name']))
$user_name = $_POST['user_name'];
else
$user_name = '';
if (!empty($_POST['user_email']))
$user_email = $_POST['user_email'];
else
$user_email = '';
if (!empty($_POST['user_email2']))
$user_email2 = $_POST['user_email2'];
else
$user_email2 = '';
if (!empty($_POST['user_email3']))
$user_email3 = $_POST['user_email3'];
else
$user_email3 = '';


$sql = "INSERT INTO `user_info`
(`user_name`, `user_email`, `user_email2`, `user_email3`)
VALUES ('$_POST[user_name]','$_POST[user_email]','$_POST[user_email2]','$_POST[user_email3]')";

if (mysql_query($sql))
echo 'Query executed';
else
die(mysql_error()); echo 'error';
mysql_close();
}




$smarty -> display(basename(str_replace(DYNAMIC_EXTENSION,TEMPLATE_EXTENSION,$_SERVER['PHP_SELF'])));
}



my_log_error('2000','APPLICATION','SMARTY template is missing',__FILE__,__LINE__);

exit;

?>

can any one help me please

Fumigator
04-19-2011, 04:30 PM
You have no variable $_POST['register'].

This is a PHP question and should be moved to the PHP forum.

Old Pedant
04-20-2011, 07:15 AM
???? Fumigator: WHY should he have $_POST['register']??? Where is there any field by that name in the <form>???

Old Pedant
04-20-2011, 07:23 AM
First, you create these variables:


if (!empty($_POST['user_name']))
$user_name = $_POST['user_name'];
else
$user_name = '';
if (!empty($_POST['user_email']))
$user_email = $_POST['user_email'];
else
$user_email = '';
if (!empty($_POST['user_email2']))
$user_email2 = $_POST['user_email2'];
else
$user_email2 = '';
if (!empty($_POST['user_email3']))
$user_email3 = $_POST['user_email3'];
else
$user_email3 = '';

And then you IGNORE those variables completely in this code:


$sql = "INSERT INTO `user_info`
(`user_name`, `user_email`, `user_email2`, `user_email3`)
VALUES ('$_POST[user_name]','$_POST[user_email]','$_POST[user_email2]','$_POST[user_email3]')";


I'm no PHP person, but it seems clear to me that you should have done


$sql = "INSERT INTO `user_info`
(`user_name`, `user_email`, `user_email2`, `user_email3`)
VALUES('$user_name','$user_email','$user_email2','$user_email3')";

But no matter WHAT you do, learn to DEBUG DEBUG DEBUG!!!

Right after setting $sql to that string, DEBUG it:


echo "<hr>DEBUG SQL: " . $sql . "<hr>";

And ensure that the SQL query you are actually using is the one you intended to use.

Fumigator
04-20-2011, 07:26 AM
???? Fumigator: WHY should he have $_POST['register']??? Where is there any field by that name in the <form>???

There isn't, that's why I pointed out it doesn't exist so he shouldn't be referring to it.

I suppose I should have said "No variable $_POST['register'] exists, you shouldn't be referring to it".

FYI One question mark does the job, no need to use three. :rolleyes:

bubbbbbz
04-20-2011, 10:54 AM
thanks i got it to work now. i have a page saying thank you is there a way to stop the user typing in the thank you url with out registering.

or dont you think its a prob as there is no log in feature yet? regards

bubbbbbz
04-20-2011, 11:18 AM
[QUOTE=bubbbbbz;1080709]thanks i got it to work now. ok now for the email lol.

i have the email sending fine but i have $_post[first_name] as my value and my email message says

$owner_message = <<<HTML


a new member $first_name is this correct? also i have '$email_address' but it just shows me the '$email_address' & $first_name.

all done now user '$_REQUEST[first_name]'

Old Pedant
04-20-2011, 06:18 PM
I'm not only blind as a bat, I'm anal retentive!!!!!!! <grin/>

Sorry, Fumigator. Dunno how I missed that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum