edit.php
[php]
<?php
// Connects to your Database
mysql_connect("mysql.mydomain.com", "username", "password") or die(mysql_error());
mysql_select_db("my_database") or die(mysql_error());
$sql = "select * from record where ID = 1";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)){
$ID = $row['ID'];
$nameTitlePrefix = $row['nameTitlePrefix'];
$nameGiven = $row['nameGiven'];
$nameFamily = $row['nameFamily'];
$nameTitleSuffix = $row['nameTitleSuffix'];
}
mysql_free_result($query);
?>[/php]
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<form action="update.php" method="post">
userid:<br/>
<input type="text" value="<?php echo $ID;?>" name="ID" disabled/>
<br/>
Title Prefix:<br/>
<input type="text" value="<?php echo $nameTitlePrefix;?>" name="nameTitlePrefix"/>
<br/>
Given Name:<br/>
<input type="text" value="<?php echo $nameGiven;?>" name="nameGiven"/>
<br/>
Family Name:<br/>
<input type="text" value="<?php echo $nameFamily;?>" name="nameFamily"/>
<br/>
Title Suffix:<br/>
<input type="text" value="<?php echo $nameTitleSuffix;?>" name="nameTitleSuffix"/>
<br/>
<input type="submit" value="save"/>
</form>
</body>
</html>
update.php
[code][php]
<?php // Connects to your Database mysql_connect("mysql.mydomain.com", "username", "password") or die(mysql_error()); mysql_select_db("my_database") or die(mysql_error()); $ID = $_POST['ID']; $nameTitlePrefix = $_POST['nameTitlePrefix']; $nameGiven = $_POST['nameGiven']; $nameFamily = $_POST['nameFamily']; $nameTitleSuffix = $_POST['nameTitleSuffix']; $sql = "UPDATE record SET nameTitlePrefix = '$nameTitlePrefix', nameGiven = '$nameGiven', nameFamily = '$nameFamily', nameTitleSuffix = '$nameTitleSuffix' WHERE record.ID = '$ID' LIMIT 1"; mysql_query($sql) or die ("Error: ".mysql_error()); echo "Database updated. Edit record"; ?>[/php][/code]I am new to PHP/SQL & have come over from FMPro, really really loving this new found freedom!
Above is some code i have adapted from a tutorial i have read about submitting data to SQL via a PHP form.
Only problem is i can’t get it to work the way they have suggested.
if i replace the ‘$ID’ variable with ID in this part of update.php it works perfectly…
fails:
$sql = "UPDATE record SET nameTitlePrefix = '$nameTitlePrefix', nameGiven = '$nameGiven', nameFamily = '$nameFamily', nameTitleSuffix = '$nameTitleSuffix' WHERE record.ID = '$ID' LIMIT 1";
works:
$sql = "UPDATE record SET nameTitlePrefix = '$nameTitlePrefix', nameGiven = '$nameGiven', nameFamily = '$nameFamily', nameTitleSuffix = '$nameTitleSuffix' WHERE record.ID = ID LIMIT 1";
but i really need to know how to do this with the variable. (the tutorial did say this was a simplified version & did not allow for proper security & should really have a dynamic ID at the start of edit.php)
Any help in allowing me to understand the issue would be great
best
Stuart