Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's wrong with my SQL query?
    text
    copied!<p>I need a quick look at my SQL query. It's already given me a headache. Comparing some advice I have gotten, I could not figure out the proper format for my SQL.</p> <p>This is my code:</p> <pre><code>$query = "INSERT INTO `[my_db_name]`.`members` (`id` ,`first` ,`last` ,`add1` ,`add2` ,`phone_home` ,`phone_cell` ,`phone_dad` ,`phone_mom` ,`email1` ,`email2`) VALUES ('NULL' , '".$first."', '".$last."', '".$add1."', '".$add2."', '".$phone_home."', '".$phone_cell."', '".$phone_dad."', '".$phone_mom."', '".$email1."', '".$email2."')"; `mysql_query($query) or die ('Error updating database, Error:' . mysql_error()); </code></pre> <p>Thanks in advance!</p> <p><strong>EDIT:</strong></p> <p>Currently I have this as the form:</p> <pre><code>&lt;table border="0" cellpadding="0" cellspacing="0"&gt; &lt;form enctype="multipart/form-data" method="POST" action="add-member.php"&gt; &lt;tr class="labels"&gt; &lt;td class="f"&gt;Add a Member&lt;/td&gt; &lt;td class="l"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="first"&gt;First Name:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="first" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="last"&gt;Last Name:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="last" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="add1"&gt;Address 1:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="add1" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="add2"&gt;Address 2:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="add2" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="phone_home"&gt;Home Phone:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="phone_home" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="phone_cell"&gt;Cell Phone:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="phone_cell" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="phone_dad"&gt;Dad Cell:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="phone_dad" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="phone_mom"&gt;Mom Cell:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="phone_mom" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="email1"&gt;Email 1:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="email1" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="f"&gt;&lt;label for="email2"&gt;Email 2:&lt;/label&gt;&lt;/td&gt; &lt;td class="l"&gt;&lt;input id="email2" type="text"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>This is the insert query:</p> <pre><code>&lt;?php $first = $_POST['first']; $last = $_POST['last']; $add1 = $_POST['add1']; $add2 = $_POST['add2']; $phone_home = $_POST['phone_home']; $phone_cell = $_POST['phone_cell']; $phone_dad = $_POST['phone_dad']; $phone_mom = $_POST['phone_mom']; $email1 = $_POST['email1']; $email2 = $_POST['email2']; include ("../lib/login.php"); mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); mysql_select_db ([dbname]); $query = "INSERT INTO `[dbname]`.`mem_dir` (`id` ,`first` ,`last` ,`add1` ,`add2` ,`phone_home` ,`phone_cell` ,`phone_dad` ,`phone_mom` ,`email1` ,`email2`) VALUES (NULL , '$first', '$last', '$add1', '$add2', '$phone_home', '$phone_cell', '$phone_dad', '$phone_mom', '$email1', '$email2')"; mysql_query($query) or die ('Error updating database, Error:' . mysql_error()); echo "Database successfully uploaded with:&lt;br/&gt;&lt;ul&gt; &lt;li&gt;" . $first . "&lt;/li&gt; ... &lt;/ul&gt;"; ?&gt; </code></pre> <p>Seems to submit the entry, but not the values... I'm tired of looking at it and not seeing it. I appreciate all the help. Thanks!</p> <p><strong>EDIT (AGAIN):</strong></p> <p>As was pointed out by <a href="https://stackoverflow.com/users/87015/salman-a">Salman A</a>, the problem was in fact the form, and the fact that each input was identified with an "id", instead of a "name".</p> <p>Thanks everyone, I really appreciate all the help! I guess my incorrect SQL formatting is another topic, eh?</p>
 

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