Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

My form submits, but database only shows $ in each field..

Links for php scripts

Moderators: macek, egami, gesf

Re: My form submits, but database only shows $ in each field

Postby swirlee » Sat Nov 29, 2003 1:55 pm

Code: Select all
//Assign contents of form to variables
//$loginip = $_POST['loginip'];   
//$inputdate = $_POST['inputdate'];
$tscourtesy = $_POST['tscourtesy'];
/* ... */
$username = $_POST['username'];
$phone = $_POST['phone'];
$email = $_POST['email'];


The above is a huge waste of 2 dozen lines of code. If you're gong to name each value below anyway, why do it twice??

Code: Select all
//Insert data from survey to the table
$sql = 'INSERT INTO OS2003 SET
tscourtesy = "$tscourtesy",   
tsneeds = "$tsneeds",
...
phone = "$phone",
email ="$email"';


Here's your problem, though. When you put a string between single-quotes, variables aren't parsed. If you want your variables to resolve to their values (rather than be taken as literals), you need to put them in double quotes or use string-concatenation. You should probably read the section of the documentation called Strings. A better chunk of code would just look like this:

Code: Select all
<?php
//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");

//Select the database we want to use
MySQL_select_db("xyz") or die("Could not select database");

//Insert data from survey to the table
$sql = "INSERT INTO OS2003 SET
tscourtesy = '$_POST[tscourtesy]',   
tsneeds = '$_POST[tsneeds]',
tscommunicates = '$_POST[tscommunicates]',
...
username = "$_POST[username]",
phone = "$_POST[phone]",
email ="$_POST[email]"';

$result = mysql_query($sql);

/* ... */
?>
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron