updating sql with php with out using a form

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rcurrie82
Forum Newbie
Posts: 2
Joined: Tue Jan 27, 2004 10:37 am

updating sql with php with out using a form

Post 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]
rcurrie82
Forum Newbie
Posts: 2
Joined: Tue Jan 27, 2004 10:37 am

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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".
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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."')";
Arulraj
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:41 pm
Location: India

Post 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?
Post Reply