I have been uing the following code to retrieve url variables and add the data to a database but ive spent for every trying to get it to update and just cant. I have seen how dw Mx does it with forms but cant apply this to my own code, if any one could help that would be fantatic!
[syntax=php]<?
//---------- Connects to the server and selects the database
$dbh=mysql_connect ("localhost", "example", "example")
or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("example");
//---------- Inserts Create Case Details into Project table
$CaseNumber = addslashes($CaseNumber);
$NHS_Number = addslashes($NHS_Number);
$AssessDate = addslashes($AssessDate);
$ReviewDate = addslashes($ReviewDate);
$NameOfProf = addslashes($NameOfProf);
$SummaryDate = addslashes($SummaryDate);
$User_ID = addslashes($User_ID);
$NameOfProf = addslashes($NameOfProf);
$query = "insert into CaseDetails values ('".$CaseNumber."','".$NHS_Number."','".$User_ID."',,'".$NameOfProf."''".$AssessDate."','".$ReviewDate."','".$NameOfProf."','".$SummaryDate."')";
$result = mysql_query($query);
if($result)
{
echo "<br>";
echo mysql_affected_rows()." Case has successfully been added to the database.";
}
?>[/syntax]
updating sql with php with out using a form
Moderator: General Moderators
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
You forgot to tell mysql what values are to be updated into what fields.. so, find out what the field names are for the table, and then put them in the query. the following is what it should look like ( assuming that the field names are the same as the value names.. change to reflect your table )
Code: Select all
$query = "insert into CaseDetails (CaseNumber, NHS_Number, User_ID, NameOfProf, AssessDate, ReviewDate, NameofProf, SummaryDate) values ('".$CaseNumber."','".$NHS_Number."','".$User_ID."',,'".$NameOfProf."''".$AssessDate."','".$ReviewDate."','".$NameOfProf."','".$SummaryDate."')";