Note that there are some explanatory texts on larger screens.

plurals
  1. POBeginner trouble with PHP & MySQL
    primarykey
    data
    text
    <p>I am very new to PHP &amp; 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:</p> <pre><code>&lt;?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); ?&gt; </code></pre> <p>I put in my username &amp; 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:</p> <pre><code>&lt;!--Start of order form--&gt; &lt;form id="contactform" method="POST" action="http://www.talephotography.com/insert.php"&gt; &lt;p&gt;&lt;label&gt;First Name:&lt;br /&gt; &lt;input type="text" name="first_name" class="textfield" value="" /&gt; &lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;label&gt;Last Name:&lt;br /&gt; &lt;input type="text" name="last_name" class="textfield" value="" /&gt; &lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;label&gt;Email: &lt;br /&gt; &lt;input type="text" name="email" class="textfield" value="" /&gt; &lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;label&gt;Phone: &lt;br /&gt; &lt;input type="text" name="phone" class="textfield" value="" /&gt; &lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;label&gt;Message: &lt;br /&gt; &lt;textarea name="message" class="textarea" cols="45" rows="5"&gt;&lt;/textarea&gt; &lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="submit" name="submit" class="button" value="Submit" /&gt;&lt;/p&gt; &lt;/form&gt; &lt;!--End of order form--&gt; </code></pre> <p>I can elaborate anywhere necessary.</p> <hr> <p>Changed some of the code, it's only posting the email address to the database however.</p> <pre><code>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')"; </code></pre> <p>There's my code, however when I check my database the only info listed is the email address. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload