Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-16-2012, 12:32 AM   PM User | #1
b721991
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
b721991 is an unknown quantity at this point
PHP/form insert statement to mysql

I'm trying to insert this form data into mysql database but I keep getting a server error what am I doing wrong?



Code:
<html> 
<head> 
  <title>Incidence Reporting</title> 
</head> 
<body> 
  <h2>Incidence Reporting</h2> 
<?php 
  
$db_s = "localhost";
$db_u = "bs_72";
$db_p = "tmmd2f";
$db_n = "bs_72";
$co = mysqli_connect($db_s,$db_u,$db_p)
or die('Error connecting to MySQL server.');

mysqli_select_db($co, $db_n);

  
  $first_name = $_POST['firstname'];
  $last_name = $_POST['lastname'];
  $e_mail = $_POST['email'];
  $when_it_happened = $_POST['whenithappened']; 
  $phone_number = $_POST['phonenumber']; 
  $i_description = $_POST['idescription']; 

  
  
  $query = “INSERT INTO las_cruces (first_name, last_name, e_mail, when_it_happened, “ .
  “phone_number, i_description) “ .
  “VALUES (‘$first_name’, ‘$last_name’,‘$e_mail’, ‘$when_it_happened’ , ‘$phone_number’, “ .
  “’$i_description’)”;
  

  
 $result = mysqli_query($co, $query);
  or die('Error querying database.');
   mysqli_close($co);
  
  
  echo 'Hello, ' . $first_name . ' ' . $last_name . '<br />';
  echo 'Thanks for submitting the form.<br />'; 
  echo 'Your email is ' . $e_mail . '<br />'; 
  echo 'Your phone number? ' . $phone_number . '<br />';
  echo 'The date of the incidence was ' . $when_it_happened . '<br />'; 
  echo 'What Happened: ' . $i_description . '<br />';

?> 
</body> 
</html>

<form method="post" action="report.php">
b721991 is offline   Reply With Quote
Old 11-16-2012, 04:48 AM   PM User | #2
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 848
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
I think it might be your query, I've never seen any query written like that in php only in mysql but I might be wrong. Maybe someone could clarify??

Also I noticed you got your <form> after the closing </html>

Also, what error message are you getting?

Kind regards,

LC.
LearningCoder is offline   Reply With Quote
Reply

Bookmarks

Tags
insert, mysql, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:28 AM.


Advertisement
Log in to turn off these ads.