Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7850673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:56:16+00:00 2026-06-02T18:56:16+00:00

I am very new to PHP & MySQL. Just designing websites for friends as

  • 0

I am very new to PHP & MySQL. Just designing websites for friends as a hobby, so any help is greatly appreciated. When I have a simple contact form on my page I keep getting error messages when submitting the information. Here is the PHP:

<?php
$con = mysql_connect("localhost","user","password");
if (!$con))  {
die('Could not connect: ' . mysql_error());
 }

mysql_select_db("database_name", $con);

$sql="INSERT INTO contact (first_name, last_name, email, phone, message)
VALUES
('$_POST[first_name]','$_POST[last_name]','$_POST[email]','$_POST[phone]','$_POST[message])";

if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con);
?>

I put in my username & password where necessary, but I keep “localhost” there. Is this correct? I have hosting through webhostingpad. I also insert my database name above. Here is my HTML:

<!--Start of order form-->

<form id="contactform" method="POST" action="http://www.talephotography.com/insert.php">
<p><label>First Name:<br />
<input type="text" name="first_name" class="textfield" value="" />
</label></p>

<p><label>Last Name:<br />
<input type="text" name="last_name" class="textfield" value="" />
</label></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" value="" />
</label></p>

<p><label>Phone: <br />
<input type="text" name="phone" class="textfield" value="" />
</label></p>

<p><label>Message: <br />
<textarea name="message" class="textarea" cols="45" rows="5"></textarea>
</label></p>

<p><input type="submit" name="submit" class="button" value="Submit" /></p>
</form>
<!--End of order form-->

I can elaborate anywhere necessary.


Changed some of the code, it’s only posting the email address to the database however.

mysql_select_db("databasename", $con);

$first = mysql_real_escape_string($_POST['first']);
$last = mysql_real_escape_string($_POST['last']);
$email = strip_tags(mysql_real_escape_string($_POST['email']));
$number = preg_replace('/[^0-9]/', '', $_POST['number']);
$number =  (int) $number;


$sql="INSERT INTO contact (first, last, email, phone);
VALUES
('$first','$last','$email','$number')";

There’s my code, however when I check my database the only info listed is the email address.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:56:17+00:00Added an answer on June 2, 2026 at 6:56 pm

    localhost is correct if the database server is on the same machine as the web server. When you set up the database it should have told you somewhere what you need to connect to.

    That aside, escape your ———–ing inputs!!!!

    Seriously, take those variables and wash them thoroughly with mysql_real_escape_string and then concatenate them into the query. You’ll thank me later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new in MySQL & PHP. I have 2 tables like these
I am very new to PHP and MySql. Is there any method by which
I am very new to PHP and MySQL and I have some questions. First,
I'm very very new to PHP, but now I have to help my friend
I'm very new to PHP and I have a small task of displaying a
I'm very new to PHP; and am doing a few sample projects to help
I am new to PHP and find it very hard to explain. I have
I am going through some very basic AJAX programming in Learning PHP, MySQL &
I am very new to php and I have a table that displays cases
I am VERY new to PHP, I'm currently working on a service, part which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.