/    Sign up×
Community /Pin to ProfileBookmark

Writing data from a form to a table

hi,
i am having a form with some fields
and i had another php file which gets the posted data of that form
now i want to write this data (of that form) into one of my tables in one row
how can i do that???
i had used this code
==============CODE=======================================

<?
include (“connection.php”);
//printf(“Connection has been establisted….<br><br><br>”);

$cid=$_POST[‘cid’];
$code=$_POST[‘code’];
$name=$_POST[‘name’];

$query =”insert into vitamin VALUES (‘<? echo $cid?>’,'<?echo $code?>’,'<?echo $name?>’)”;

$result = mysql_query($query);

if($result)
echo “ROW INSERTED”;

?>

<h3>Insert Another Row</h3><br><a href =”insert.php”>Click Here</a>

=========================================================
what i am getting in the table is some junk values with some echo like values..
plz see this
thanks…
-ashish

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ZiplineMar 31.2006 — I see your main problem.... your insert statement is incorrectly formatted.

Your values don't need to be echoed because you're not displaying them you're using them within your script. I grabbed a working example of a query that you can use to help you create yours:

[code=php]
$sql = "insert into packages (display,page_title,package_title,content,price,type)
values ('".$_POST['display']."','".$_POST['page_title']."','".$_POST['package_title']."','".$_POST['content']."','".$_POST['price']."','".$_POST['type']."')";
[/code]


You can easily change $_POST['variable'] to $variable. Usually it is a good idea to set your vairables for your script like you're doing, in this case... I didn't.

Enjoy
Copy linkTweet thisAlerts:
@Heavy_MetalApr 01.2006 — plus you realized that in the [code=php]$query ="insert into vitamin VALUES ('<? echo $cid?>','<?echo $code?>','<?echo $name?>')";[/code] you put <? ?>'s inside of php <? ?>'s already
×

Success!

Help @ashishrathore 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.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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