Note that there are some explanatory texts on larger screens.

plurals
  1. POAllow user to add information to their profile using insert query
    text
    copied!<p>Im using the following function:</p> <pre><code>function Add_Oddjob ($Add_Oddjob){ global $MemberID; $update = array(); array_walk($Add_Oddjob, 'array_sanitize'); foreach($Add_Oddjob as $field=&gt;$data){ //loop through update data in Add_Oddjob.php $update[] = '`' . $field . '` = \'' . $data . '\''; } mysql_query("INSERT INTO `oddjob`($field) VALUES ($data)"); </code></pre> <p>Add_Oddjob.php</p> <pre><code>if (isset($_POST['OddJobName']) &amp;&amp; isset($_POST['Description']) &amp;&amp; isset($_POST['DaysAvailable']) &amp;&amp; empty($errors) === true){//if (empty($_POST) === false &amp;&amp; empty($errors) === true) { //if (isset(empty($_POST['OddJobName'])) &amp;&amp; isset(empty($_POST['Description'])) &amp;&amp; isset(empty($_POST['DaysAvailable'])) === false &amp;&amp; empty($errors) === true) $daysavailable=''; foreach ($_POST['DaysAvailable'] as $value) { $daysavailable .=$value." "; } $Add_Oddjob = array ( 'MemberID' =&gt; $MemberID, 'OddJobName' =&gt; $_POST['OddJobName'], 'Description' =&gt; $_POST['Description'], 'DaysAvailable' =&gt; $daysavailable, ); Add_Oddjob ($Add_Oddjob); if(success){ header('Location: member.php?username='.$username); exit (); } } else if (empty($errors) === false){ //otherwise output errors echo output_errors($errors); } </code></pre> <p>But when I log in as a user and enter data i get the following error:</p> <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE <code>MemberID</code> =' at line 1</p> <p>The <code>MemberID</code> in the <code>Oddjob</code> table is a primary key in the Member Table. The idea is that each member can have more than one odd job in the odd job table. Do I need to do some sort of join maybe?</p> <p>Also If i try the insert query in phpmyadmin:</p> <pre><code> INSERT INTO `oddjob`(`OddJobName`, `Description`, `DaysAvailable`) VALUES (painter,test,Friday) WHERE `MemberID` = 35 </code></pre> <p>I get this error:</p> <pre><code>#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `MemberID` = 35' at line 1 </code></pre> <p>Any help would be great!</p> <p>EDIT</p> <p>So I removed the WHERE clause from my query because I didnt realise I couldnt have that in an insert query. Now if i echo the query i see: <code>INSERT INTO</code>oddjob<code>(DaysAvailable) VALUES (Wednesday )</code> for some reason its not picking up any of the other fields. Any ideas why?</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