I’m looking for some help with my INSERT mysql query, I currently have the php loop
<?php
$sql="SELECT clientID,clientName FROM clients";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result))
{
?><option value="
<?php echo $data['clientID'] ?>" >
<?php echo $data['clientName'] ?></option>
<?php
} ?>
This outputs the list of Clients that I have, but I need to INSERT the chosen client. How do I insert the clientID chosen in a html form and insert it into ‘projects’ ?
projectID ('projects') and clientID ('clients') are related, so I need to insert to clientID into projects to associate them together.
Example:
$strSql="INSERT INTO projects
( projectID , projectName , projectBusiness , projectDescription) VALUES
(NULL , '$strprojectName', '$intclientID', '$strProjectDescription')";
The above doesn’t grab the clientID yet..
This is one of the more fundamental aspects of PHP (and HTML to an extent) and so you should get a good grasp of this before going much further.
Wrap the select in a form. You may, or may not have done this already; can’t tell.
Once you submit this form, you can access it from the super global $_POST (this is because the forms
methodis set topost. Again – fundamentals.You can now access the
valueof the submit data in the form of an associative array:$client_id = mysql_real_escape_string($_POST['client_id']);– where the key comes from the form.You can now use this variable within your queries and for further processing – after sanitising of course.
Again this is extremely basic; so you should probably do a bit of work looking for basic PHP tutorials.