/    Sign up×
Community /Pin to ProfileBookmark

insert doesn’t work

I have this little insert program, almost identical to other working programs, which doesn’t work and I don’t know why. Below is the code ?

[CODE]<html><BODY>
<b>Misc. Charges insert form<p>
<form action=”mschginsert.php” method=”post”>
<INPUT TYPE=”text” name=dep>Dep#<BR>
<INPUT TYPE=”text” name=name>Name<BR>
<INPUT TYPE=”text” name=apt>Apt#<BR>
<INPUT TYPE=”text” name=amtpaid>Amount Paid<BR>
<INPUT TYPE=”text” name=damage>Damage Chg<BR>
<INPUT TYPE=”text” name=month>Month Incurred<BR>
<INPUT TYPE=”text” name=courtcost>Court Costs<BR>
<INPUT TYPE=”text” name=nsf>NSF<BR>
<INPUT TYPE=”text” name=latechg>Late Charges<BR>
<INPUT TYPE=”text” name=comments>Comments<BR>
<p>
<INPUT type=submit value=”submit data”><BR>
</form></body></html>[/CODE]

the below PHP file is mschginsert.php

[code=php]<?php
$dep=$_POST[‘dep’];
$name=$_POST[‘name’];
$apt=$_POST[‘apt’];
$amtpaid=$_POST[‘amtpaid’];
$damage=$_POST[‘damage’];
$month=$_POST[‘month’];
$courtcost=$_POST[‘courtcost’];
$nsf=$_POST[‘nsf’];
$latechg=$_POST[‘latechg’];
$comments=$_POST[‘comments’];
mysql_connect(localhost,root,””);
mysql_select_db(mschgdb) or die (“Unable to select database”);

$query = “INSERT INTO miscdata VALUES (”,’$dep’,’$name’,’$apt’,’$amtpaid’,’$damage’,’$month’,’$courtcost’,’$nsf’,’$latechg’,’$comments’)”;
mysql_query($query);

mysql_close();
?>[/code]

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ChipzzzSep 11.2010 — You might try:
<i>
</i>mysql_connect('localhost','root',"");
mysql_select_db('mschgdb') or die ("Unable to select database");


Good luck ?
Copy linkTweet thisAlerts:
@ckdoublenecksauthorSep 11.2010 — no, as I posted, I have several programs using that syntax
Copy linkTweet thisAlerts:
@ChipzzzSep 11.2010 — Without quotes around localhost, root, and mschgdb?
Copy linkTweet thisAlerts:
@ckdoublenecksauthorSep 11.2010 — Sorry chipzzz, this PHP is new to me and very frustrating. Below is coding from a different program that I use at least daily:
[code=php]<?php
$apt=$_POST['apt'];
$name=$_POST['name'];
$datereceived=$_POST['datereceived'];
$time=$_POST['time'];
$symptom=$_POST['symptom'];
$action=$_POST['action'];
$datecomplete=$_POST['datecomplete'];
mysql_connect(localhost,root,"");
mysql_select_db(maintdb) or die ("Unable to select database");

$query = "INSERT INTO maintdata VALUES ('','$apt','$name','$datereceived','$time','$symptom','$action','$datecomplete')";
mysql_query($query);

mysql_close();
?>[/code]
Copy linkTweet thisAlerts:
@ChipzzzSep 11.2010 — That's curious... but in any case, you might try the following and let mysql tell you what it doesn't like about the code:

<i>
</i>$stat = mysql_connect(localhost,root,"") or die('Unable to connect to database: ' . mysql_error());
$stat = mysql_select_db(mschgdb) or die('Unable to select database: ' . mysql_error());

$query = "INSERT INTO miscdata VALUES ('','$dep','$name','$apt','$amtpaid','$damage','$month','$courtcost','$nsf','$latechg','$comments')";
$stat = mysql_query($query) or die('Query failed: ' . mysql_error());

mysql_close();
Copy linkTweet thisAlerts:
@ckdoublenecksauthorSep 11.2010 — thanks friend, it showed me that there was a problem with the database and it's now running fine. I'd love to put checks for problems in all my programs but haven't learned how.
Copy linkTweet thisAlerts:
@ChipzzzSep 11.2010 — Glad to hear it worked out for you and don't be discouraged by the occasional bump in the learning curve. We've all been there.

Best of luck ?
×

Success!

Help @ckdoublenecks 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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