/    Sign up×
Community /Pin to ProfileBookmark

inserting data into mysql database

this is my code so far…

// Connecting, selecting database
include (“db_connect.inc”)

// add the new information into the database
$query=”INSERT INTO Users_Registered(fname,lname,pw,company,phone,email,addr1,addr2,city,state,zip) VALUES(‘$_POST[fname]’,’$_POST[lname]’,’$_POST[pw]’,’$_POST[company]’,’$_POST[phone]’,’$_POST[email]’,’$_POST[addr1]’,’$_POST[addr2]’,’$_POST[city]’,’$_POST[state]’,’$_POST[zip]’)”;
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
echo “success in database entry.”;

echo “<br />”;
echo “<a href=”login.php”>Click here to return to the form page.</a>”;

//header (“Location: http://www.decisus.net/partnerlogin.html“);
?>

but i get this error

Parse error: parse error, unexpected T_VARIABLE in /home/decisusn/public_html/Web2/processregistration.php on line 7 😑

line 7 is the $query line

to post a comment
PHP

7 Comments(s) ↴

Copy linkTweet thisAlerts:
@lightningstrikeJun 13.2006 β€”Β // add the new information into the database

$query="INSERT INTO Users_Registered(fname,lname,pw,company,phone,email,addr1,addr2,city,state,zip) VALUES('" . $_POST['fname'] . "','" . $_POST['lname'] . "','" . $_POST['pw'] . "','" . $_POST['company'] . "','" . $_POST['phone'] . "','" . $_POST['email'] . "','" . $_POST['addr1'] . "','" . $_POST['addr2'] . "','" . $_POST['city'] . "','" . $_POST['state'] . "','" . $_POST['zip'] . "')";

Just remember the post superglobal variable requires quotations around the variable.

Hoepfully the code above should work for you.
Copy linkTweet thisAlerts:
@The_Little_GuyJun 13.2006 β€”Β Maybe this (untested):
[code=php]<?
// Connecting, selecting database
include ("db_connect.inc")

// add the new information into the database
$query="INSERT INTO Users_Registered(fname,lname,pw,company,phone,email,addr1,addr2,city,state,zip) VALUES('$_POST[fname]','$_POST[lname]','$_POST[pw]','$_POST[company]','$_POST[phone]','$_POST[email]','$_POST[addr1]','$_POST[addr2]','$_POST[city]','$_POST[state]','$_POST[zip]')";
if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error()){
echo "success in database entry.";
}
echo "<br />";
echo "<a href="login.php">Click here to return to the form page.</a>";


//header ("Location: http://www.decisus.net/partnerlogin.html");
?>[/code]
Copy linkTweet thisAlerts:
@riddimauthorJun 13.2006 β€”Β $query="INSERT INTO Users_Registered(fname,lname,pw,company,phone,email,addr1,addr2,city,state,zip) VALUES($_POST['fname'],$_POST['lname'],$_POST['pw'],$_POST['company'],$_POST['phone'],$_POST['email'],$_POST['addr1'],$_POST['addr2'],$_POST['city'],$_POST['state'],$_POST['zip'])";

i tried both ways you guys showed me and got the same error..now i did this way..same thing..i have one more thing i'm gonna try

i move the quotes moved around and use single quotes..i'll try with double quotes now with where i have them positioned....see what happens..
Copy linkTweet thisAlerts:
@riddimauthorJun 13.2006 β€”Β this way i tried too doesnt work...this is pretty strange...

$query="INSERT INTO Users_Registered(fname,lname,pw,company,phone,email,addr1,addr2,city,state,zip) VALUES($_POST["fname"],$_POST["lname"],$_POST["pw"],$_POST["company"],$_POST["phone"],$_POST["email"],$_POST["addr1"],$_POST["addr2"],$_POST["city"],$_POST["state"],$_POST["zip"])";
Copy linkTweet thisAlerts:
@lightningstrikeJun 13.2006 β€”Β The easiest way is to simply do the following by not saving the query into a variable but directly executing it.

if(!mysql_db_query($dbname,"INSERT INTO Users_Registered(fname,lname,pw,company,phone,email,addr1,addr2,city,state,zip) VALUES($_POST['fname'],$_POST['lname'],$_POST['pw'],$_POST['company'],$_POST['phone'],$_POST["email"],$_POST['addr1'],$_POST['addr2'],$_POST['city'],$_POST['state'],$_POST['zip']",$link_id)) die(mysql_error());

give it a try
Copy linkTweet thisAlerts:
@chazzyJun 13.2006 β€”Β you guys keep giving him invalid sql...

[code=php]$sql = "INSERT INTO table(column list...) VALUES('".$_POST['val1'].'","'.....";[/code]
Copy linkTweet thisAlerts:
@riddimauthorJun 14.2006 β€”Β <?php

// Connecting, selecting database

include ("db_connect.inc")

// add the new information into the database

$query="INSERT INTO Users_Registered(fname,lname,pw,company,phone,email,addr1,addr2,city,state,zip)

Values('$fname', '$lname', '$password','$company','$phone','$email','$address1','$address2','$city','$state','$zip')";

//"INSERT INTO table(column list...) VALUES('".$_POST['val1'].'","'.....";

// I created some local variables

$fname = $_POST['fname'];

$lname = $_
POST['lname'];

$password = $_POST['pw'];

$company = $_
POST['company'];

$phone= $_POST['phone'];

$email = $_
POST['email'];

$address1 = $_POST['addr1'];

$address2 = $_
POST['addr2'];

$city = $_POST['city'];

$state = $_
POST['state'];

$zip= $_POST['zip'];


if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error()){

echo "success in database entry.";

echo "<br />";

echo "<a href="login.php">Click here to return to the form page.</a>";


//header ("Location: http://www.decisus.net/partnerlogin.html");

?>

i tried this way too..by creating local variables..but i still got this monkey on my back..same error...i've tried all you guys examples..but no progress...


i
Γ—

Success!

Help @riddim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 β€” BETA 5.1,
whats_new: community page,
up_next: more Davinciβ€’003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciβ€’003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...