Jump to content


Photo

[resolved] my form doesnt work :(


  • Please log in to reply
13 replies to this topic

#1 raymens

raymens
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 29 October 2006 - 05:13 PM

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:
<?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";
?>


#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 29 October 2006 - 05:21 PM

You have to set a WHERE clause in your UPDATE to define witch row to update,
<?php

UPDATE table set (field1,field2) values ($val1,$val2) WHERE id = '$id'

?>


#3 raymens

raymens
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 29 October 2006 - 07:07 PM

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 16

This is my script now:
<?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";
?>


#4 Destruction

Destruction
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 29 October 2006 - 07:20 PM

gress']) . "');
you're missing a " at the end of your statement

#5 raymens

raymens
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 29 October 2006 - 07:27 PM

thx m8, it works now i guess:D

edit: it doesnt works, it adds a new row :(

#6 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 29 October 2006 - 08:36 PM

You have misplaced the WHERE stuff
<?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'");

?>


#7 raymens

raymens
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 30 October 2006 - 05:26 AM

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

<?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";
?>


#8 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 30 October 2006 - 03:53 PM

OK, i had a typo in my last code BUT you also left out a quote, now - try this out:

<?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"]))
{
$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';

?>



#9 raymens

raymens
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 31 October 2006 - 06:55 AM

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

#10 raymens

raymens
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 04 November 2006 - 07:13 AM

anyone? plz help

#11 joshi_v

joshi_v
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 04 November 2006 - 07:25 AM


Change this update query
$sql = "UPDATE projects set (name, description, update_date, progress) VALUES ('$name', '$descr', '$update_date', '$progress' WHERE id = '$id'";


Like this,

$sql= "UPDATE projects set name='$name',description='$descr',updte_date='$update_date',progress='$progress' where id= '$id' ";

Cheers!


#12 raymens

raymens
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 04 November 2006 - 09:00 AM

i dont get a error but it doesnt update the database :(

#13 joshi_v

joshi_v
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 04 November 2006 - 09:37 AM


Make sure that all variables are passing to that query or not! pritn the query to the browser.

$sql= "UPDATE projects set name='$name',description='$descr',updte_date='$update_date',progress='$progress' where id= '$id' ";
echo $sql;

If all variables are passing correctly, then check the query directly in phpMyAdmin.

Regards,
Joshi.

#14 raymens

raymens
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 November 2006 - 11:49 AM

thx m8s it works :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users