473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Not able to insert to db from form in production

97 64KB
I'm trying to get a web page working so that visitors to the website can leave reviews of the business, or read reviews others have left. But I'm having trouble getting it working on the production server, even though it worked in development.

Here's the code I'm using to inert the reviews into the database;

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbc = mysql_connect('localhost', 'communi3_root', 'NotTheRealPassword');
  3. mysql_select_db('communi3_cfds',$dbc);
  4. $monicker = $_POST['monicker'];
  5. review = $_POST['review'];
  6.  
  7. $query = "INSERT INTO reviews 
  8. (monicker, review) 
  9. VALUES ('$monicker', '$review' );";
  10.  
  11. if (mysql_query($query, $dbc))
  12. {
  13. print '<p>The review has been submitted!</p>';
  14. } else 
  15. {
  16. print '<p style="color: red;">Could not add the review because:<br />' .mysql_error($dbc) . '</p>';
  17. }
  18. ?>
  19.  
I know that this is an old version of MySQL but the admin at the hosting company has already changed the version on the server and I don't mind using it as long as it works (even though it doesn't). I also know that I should be using an error log rather than printing error messages to the screen, but I'm not sure how to access the php.ini file to set that up.

Basically, I haven't got much experience in this kind of thing (should be only too obvious from the amateurish code) but I'd really like to get this working. I had it working in production but it just won't work in development. I got it to the point where it looked ok, but when I tested it, the reviews were not being stored in the database. I also have code to display the reviews when a user clicks a button, but that seems to be fine.
May 14 '15 #1
2 1651
Luuk
1,047 Expert 1GB
You should check if your connection is setup correctly.

You should to this by checking the value of $dbc, after line#2

see the stuff about return values in the docs: MySQL_connect
May 14 '15 #2
tdrsam
97 64KB
I think I've finally got it going. The connection was ok but I didn't have the id set in the INSERT statement, also I hadn't used an ISSET statement, so when I got the first problem fixed I had to add the ISSET so that a blank entry wouldn't be added to the database on page load. Anyway final code is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbc = mysql_connect('localhost', 'DB_NAME', 'NotRealPassWord');
  3. mysql_select_db('communi3_cfds',$dbc);
  4. if(isset($_POST['submit'])) {
  5. $monicker = mysql_real_escape_string ($_POST['monicker']);
  6. $review = mysql_real_escape_string ($_POST['review']);
  7.  
  8. $query = "INSERT INTO reviews 
  9. (id, monicker, review, date) 
  10. VALUES (DEFAULT,'$monicker', '$review', 'CURDATE()');";
  11. }
  12. ?>
  13.  
May 15 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: EricRobineau | last post by:
hello I have a DB with many inter-related tables (MySQL) My main table called "content" has almost only foreign keys (integers) some have a 3 level relation (ex: content->city->region->country) ...
6
by: Sean | last post by:
HI There, I am making the transition from asp to asp .net, I am currenty writing an application that requires a bulk insert from a webform into SQL server, normally I would just create rows of...
8
by: fjm | last post by:
Hello all, I know it wouldn't be long before I was back. I have a dilemma and really have no idea where to look for an answer. I have two issues going on and I appoligize in advance if I'm wrong...
1
by: billypit | last post by:
Hi, In my project i have one table production.Now i have to make application in which i have to insert new data in table by fields of form made in access.I don't know how to use form field's values...
0
by: leab | last post by:
i make a simple project in c# with access->database i make forms: one for start one for menu one for see the data from access i need one more for insert new...
8
mandrekar salim
by: mandrekar salim | last post by:
hi guys , i'm using visual studio 2005. now i've to create a insert form which shud be connected to database(mssql). can any one tell me how to do dat. as i'm new to visual studio i dnt knw it.
1
by: wizardry | last post by:
how do i get this insert form to display for the results record id 1 once and record id 2 once instead of looping though all of foreign keys for record 1. this is in refferance to the code for sub...
13
by: yateesh | last post by:
Hello , I have a form in post.php page . When i submit that , its inserting only the comments not the id of the post . This is my form in post.php page . //Details of post.php <form...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.