473,396 Members | 1,655 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,396 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 1652
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.