raymens Posted October 29, 2006 Share Posted October 29, 2006 Hello everyone, i got a aproblem with my form, if i fill/update in the form and press on the submit button. it doesnt update my form :( it just reload the page with the form.this is the page:[code]<?php require_once "maincore.php"; require_once "subheader.php"; require_once "side_left.php"; require_once ("config.php"); require_once ("maincore.php"); if (isset($_POST['Wijzig])) { $update_date = date("d-m-Y H:i"); $sql = "UPDATE projects (name, description, update_date, progress) VALUES('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['description']) . "', '" . mysql_real_escape_string($update_date) . "', '" . mysql_real_escape_string($_POST['progress']) . "'); $res = mysql_query($sql) or die(mysql_error()); echo $res; echo " Project succesvol gewijzigd"; } else{ $id = $_GET['id']; $username = $userdata['user_name']; $sql = "SELECT id,name,description,author,date FROM projects WHERE id = '$id'"; $res = mysql_query($sql); $num = mysql_num_rows($res); $d = mysql_fetch_array($res); if ($username == $d['author']) { echo "<h3>Wijzig uw Project:</h3>"; ?> <table border="0"><form method="post" action="addproject.php?id="<?php echo $d['id']; ?>" enctype="multipart/form-data"> <tr><td width="40%">Project Naam:</td><td><input type="text" size="20" maxlength="20" name="name" value="<? echo $d['name']; ?> ">(Max 20 chars)</td></tr> <tr><td width="40%">Project Beschrijving:</td><td><textarea name="description" rows="8" cols="31"><?php echo $d['description']; ?></textarea></td></tr> <tr><td width="40%">Percentage klaar:</td><td><select><option name="0">0</option> <option name="10">10</option> <option name="20">20</option> <option name="30">30</option><option name="40">40</option> <option name="50">50</option><option name="60">60</option> <option name="70">70</option><option name="80">80</option> <option name="90">90</option><option name="100">100</option></select> </td></tr> <tr><td width="40%"></td><td><input type="Submit" name="Wijzig" value="Wijzig"> </table></form> <? } else{ echo "U heeft niet het recht om dit project te wijzigen"; } } require_once "side_right.php"; require_once "footer.php";?>[/code] Quote Link to comment Share on other sites More sharing options...
alpine Posted October 29, 2006 Share Posted October 29, 2006 You have to set a WHERE clause in your UPDATE to define witch row to update,[code]<?phpUPDATE table set (field1,field2) values ($val1,$val2) WHERE id = '$id'?>[/code] Quote Link to comment Share on other sites More sharing options...
raymens Posted October 29, 2006 Author Share Posted October 29, 2006 ok, i changed that but my error now is: Parse error: parse error, unexpected T_STRING in C:\Program Files\xampp\htdocs\php-fusion\update_project.php on line 16This is my script now:[code]<?php require_once "maincore.php"; require_once "subheader.php"; require_once "side_left.php"; require_once ("config.php"); require_once ("maincore.php"); if ($_SERVER['REQUEST_METHOD'] == 'POST') { //$id = $_GET['id']; $update_date = date("d-m-Y H:i"); $sql = "UPDATE projects set (name, description, update_date, progress) WHERE id = '$id' VALUES('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['description']) . "', '" . mysql_real_escape_string($update_date) . "', '" . mysql_real_escape_string($_POST['progress']) . "'); $res = mysql_query($sql) or die(mysql_error()); echo $res; echo " Project succesvol gewijzigd"; } else{ $id = $_GET['id']; $username = $userdata['user_name']; $sql = "SELECT id,name,description,author,date FROM projects WHERE id = '$id'"; $res = mysql_query($sql); $num = mysql_num_rows($res); $d = mysql_fetch_array($res); if ($username == $d['author']) { echo "<h3>Wijzig uw Project:</h3>"; ?> <table border="0"><form method="post" action="addproject.php?id="<?php echo $d['id']; ?>" enctype="multipart/form-data"> <tr><td width="40%">Project Naam:</td><td><input type="text" size="20" maxlength="20" name="name" value="<? echo $d['name']; ?> ">(Max 20 chars)</td></tr> <tr><td width="40%">Project Beschrijving:</td><td><textarea name="description" rows="8" cols="31"><?php echo $d['description']; ?></textarea></td></tr> <tr><td width="40%">Percentage klaar:</td><td><select><option name="0">0</option> <option name="10">10</option> <option name="20">20</option> <option name="30">30</option><option name="40">40</option> <option name="50">50</option><option name="60">60</option> <option name="70">70</option><option name="80">80</option> <option name="90">90</option><option name="100">100</option></select> </td></tr> <tr><td width="40%"></td><td><input type="Submit" name="Wijzig" value="Wijzig"> </table></form> <? } else{ echo "U heeft niet het recht om dit project te wijzigen"; } } require_once "side_right.php"; require_once "footer.php";?>[/code] Quote Link to comment Share on other sites More sharing options...
Destruction Posted October 29, 2006 Share Posted October 29, 2006 gress']) . "');you're missing a " at the end of your statement Quote Link to comment Share on other sites More sharing options...
raymens Posted October 29, 2006 Author Share Posted October 29, 2006 thx m8, it works now i guess:Dedit: it doesnt works, it adds a new row :( Quote Link to comment Share on other sites More sharing options...
alpine Posted October 29, 2006 Share Posted October 29, 2006 You have misplaced the WHERE stuff[code]<?php$sql = "UPDATE projects set (name, description, update_date, progress) VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['description']) . "', '" . mysql_real_escape_string($update_date) . "', '" . mysql_real_escape_string($_POST['progress']) . "' WHERE id = '$id'");?>[/code] Quote Link to comment Share on other sites More sharing options...
raymens Posted October 30, 2006 Author Share Posted October 30, 2006 i get this error now:Parse error: parse error, unexpected T_STRING in C:\Program Files\xampp\htdocs\php-fusion\update_project.php on line 17[code]<?php require_once "maincore.php"; require_once "subheader.php"; require_once "side_left.php"; require_once ("config.php"); require_once ("maincore.php"); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $id = $_GET['id']; $update_date = date("d-m-Y H:i"); $sql = "UPDATE projects set (name, description, update_date, progress) VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['description']) . "', '" . mysql_real_escape_string($update_date) . "', '" . mysql_real_escape_string($_POST['progress']) . "' WHERE id = '$id'); $res = mysql_query($sql) or die(mysql_error()); echo $res; echo " Project succesvol gewijzigd"; } else{ $id = $_GET['id']; $username = $userdata['user_name']; $sql = "SELECT id,name,description,author,date FROM projects WHERE id = '$id'"; $res = mysql_query($sql); $num = mysql_num_rows($res); $d = mysql_fetch_array($res); if ($username == $d['author']) { echo "<h3>Wijzig uw Project:</h3>"; ?> <table border="0"><form method="post" action="addproject.php?id="<?php echo $d['id']; ?>" enctype="multipart/form-data"> <tr><td width="40%">Project Naam:</td><td><input type="text" size="20" maxlength="20" name="name" value="<? echo $d['name']; ?> ">(Max 20 chars)</td></tr> <tr><td width="40%">Project Beschrijving:</td><td><textarea name="description" rows="8" cols="31"><?php echo $d['description']; ?></textarea></td></tr> <tr><td width="40%">Percentage klaar:</td><td><select><option name="0">0</option> <option name="10">10</option> <option name="20">20</option> <option name="30">30</option><option name="40">40</option> <option name="50">50</option><option name="60">60</option> <option name="70">70</option><option name="80">80</option> <option name="90">90</option><option name="100">100</option></select> </td></tr> <tr><td width="40%"></td><td><input type="Submit" name="Wijzig" value="Wijzig"> </table></form> <? } else{ echo "U heeft niet het recht om dit project te wijzigen"; } } require_once "side_right.php"; require_once "footer.php";?>[/code] Quote Link to comment Share on other sites More sharing options...
alpine Posted October 30, 2006 Share Posted October 30, 2006 OK, i had a typo in my last code BUT you also left out a quote, now - try this out:[code]<?phprequire_once "maincore.php";require_once "subheader.php";require_once "side_left.php";require_once "config.php";require_once "maincore.php";if (isset($_POST["Wijzig"])){$id = $_POST['id'];settype($id,"integer");$update_date = date("d-m-Y H:i");$name = mysql_real_escape_string($_POST['name']);$descr = mysql_real_escape_string($_POST['description']);$progress = mysql_real_escape_string($_POST['progress']);$sql = "UPDATE projects set (name, description, update_date, progress) VALUES ('$name', '$descr', '$update_date', '$progress' WHERE id = '$id'";$res = mysql_query($sql) or die(mysql_error());echo $res;echo " Project succesvol gewijzigd";}else{$id = $_GET['id'];$username = $userdata['user_name'];$sql = "SELECT id,name,description,author,date FROM projects WHERE id = '$id'";$res = mysql_query($sql);$num = mysql_num_rows($res);$d = mysql_fetch_array($res);if ($username == $d['author']){echo <<<_HTML<h3>Wijzig uw Project:</h3><form method="post" action="addproject.php" enctype="multipart/form-data"><table border="0"><tr><td width="40%">Project Naam:</td><td><input type="hidden" name="id" value="{$d['id']}"><input type="text" size="20" maxlength="20" name="name" value="{$d['name']}">(Max 20 chars)</td></tr><tr><td width="40%">Project Beschrijving:</td><td><textarea name="description" rows="8" cols="31">{$d['description']}</textarea></td></tr><tr><td width="40%">Percentage klaar:</td><td><select name="progress"><option value="0">0</option><option value="10">10</option><option value="20">20</option><option value="30">30</option><option value="40">40</option><option value="50">50</option><option value="60">60</option><option value="70">70</option><option value="80">80</option><option value="90">90</option><option value="100">100</option></select></td></tr><tr><td width="40%"></td><td><input type="Submit" name="Wijzig" value="Wijzig"></td></tr></table></form>_HTML;}else{echo "U heeft niet het recht om dit project te wijzigen";}}require_once 'side_right.php';require_once 'footer.php';?>[/code] Quote Link to comment Share on other sites More sharing options...
raymens Posted October 31, 2006 Author Share Posted October 31, 2006 if i click on submit(wijzig) now, this error appears:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(name, description, update_date, progress) VALUES ('Infusion: Project', 'Een Inf' at line 1 Quote Link to comment Share on other sites More sharing options...
raymens Posted November 4, 2006 Author Share Posted November 4, 2006 anyone? plz help Quote Link to comment Share on other sites More sharing options...
joshi_v Posted November 4, 2006 Share Posted November 4, 2006 Change this update query[code]$sql = "UPDATE projects set (name, description, update_date, progress) VALUES ('$name', '$descr', '$update_date', '$progress' WHERE id = '$id'";[/code]Like this,[code]$sql= "UPDATE projects set name='$name',description='$descr',updte_date='$update_date',progress='$progress' where id= '$id' ";[/code]Cheers! Quote Link to comment Share on other sites More sharing options...
raymens Posted November 4, 2006 Author Share Posted November 4, 2006 i dont get a error but it doesnt update the database :( Quote Link to comment Share on other sites More sharing options...
joshi_v Posted November 4, 2006 Share Posted November 4, 2006 Make sure that all variables are passing to that query or not! pritn the query to the browser.[code]$sql= "UPDATE projects set name='$name',description='$descr',updte_date='$update_date',progress='$progress' where id= '$id' ";echo $sql;[/code]If all variables are passing correctly, then check the query directly in phpMyAdmin.Regards,Joshi. Quote Link to comment Share on other sites More sharing options...
raymens Posted November 5, 2006 Author Share Posted November 5, 2006 thx m8s it works :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.