Page 1 of 1

updating sql with php with out using a form

Posted: Tue Jan 27, 2004 10:37 am
by rcurrie82
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]

Posted: Tue Jan 27, 2004 10:39 am
by rcurrie82
Just read through that and it didnt make any sense, basically I want to apply the [MM_update] action to this sorting the data by the [CaseNumber]

Thank you again

Posted: Tue Jan 27, 2004 3:56 pm
by d3ad1ysp0rk
uhh.. I haven't used dreamweaver forever, so can you explain exactly what you want to do?

ie. "I want to insert the date, then when a new user comes, update the date to when they visited".

Posted: Tue Jan 27, 2004 4:17 pm
by infolock
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."')";

Posted: Wed Jan 28, 2004 1:41 am
by Arulraj
Before executing the Query statement, please echo it and see the SQL construct and the value assigining is coming correctly.

When you are inserting all fields in the table then there is no need of mentioning column names.

Please tell what error you are getting?