Jump to content

Recommended Posts

hi im new with php some people can help me please i have this error from database som like

 

1:update form

html>
<head>
<title>change database</title>
</head>
<body bgcolor="white">
<form method="POST" action="sysdocupdate.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="blue">ID to Update:</font></td>
<td><input type="text" name="id" size=100></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>

 

2:sysdocupdate.php

<?php

foreach($_POST as $varname => $value) 
$_POST[$varname]=$value; 



$db1 = mysql_connect ("localhost", "root","", "") or die ("cannot connect");
mysql_select_db("polish") or die ("cannot select DB");

$result = mysql_query("SELECT * FROM `polish`.`update` where id = \"".$_POST["id"]. "\"");


$row=mysql_fetch_array($result);
$_POST = array();
$_POST["raekke"]=$row["raekke"];
$_POST["modelnr"]=$row["modelnr"];
$_POST["navn"]=$row["navn"];
$_POST["priser"]=$row["priser"];
$_POST["display"]=$row["display"];
$_POST["bruger"]=$row["bruger"];
$_POST["salg"]=$row["salg"];
$_POST["usedup"]=$row["usedup"];
$_POST["instock"]=$row["instock"];
$_POST["totaltstock"]=$row["totaltstock"];
$_POST["id"]=$row["id"];
mysql_close($db1);
?>
<html>
<head>
<title>SystemsDoc Update</title>
</head>
<body bgcolor="white">
<form method="post" action="postupdate.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="blue">Row:</font></td>
<td><input type="text" name="raekke" 
value="<? echo $_POST["raekke"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Model_Nr:</font></td>
<td><input type="text" name="modelnr" 
value="<? echo $_POST["modelnr"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Name:</font></td>
<td><input type="text" name="navn" 
value="<? echo $_POST["navn"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">price:</font></td>
<td><input type="text" name="priser" 
value="<? echo $_POST["priser"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">display</font></td>
<td><input type="text" name="display" 
value="<? echo $_POST["display"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Using:</font></td>
<td><input type="text" name="bruger" 
value="<? echo $_POST["bruger"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Sall:</font></td>
<td><input type="text" name="salg" 
value="<? echo $_POST["salg"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Used Up:</font></td>
<td><input type="text" name="usedup" 
value="<? echo $_POST["usedup"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">In Stock:</font></td>
<td><input type="text" name="instock" 
value="<? echo $_POST["instock"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Totalt Stock:</font></td>
<td><input type="text" name="totaltstock" 
value="<? echo $_POST["totaltstock"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">ID:</font></td>
<td><input type="text" name="id" 
value="<? echo $_POST["id"]; ?>" size=100></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>

 

3:Postupdated

 

<?php 

// Save form values to $formVars array 
foreach($_POST as $varname => $value) 
$_POST[$varname]=$value; 

					$id = $_POST['id'];
					$raekke = $_POST['raekke'];
					$modelnr = $_POST['modelnr'];
					$navn = $_POST['navn'];
					$priser = $_POST['priser'];
					$display = $_POST['display'];
					$bruger = $_POST['bruger'];
					$salg = $_POST['salg'];
					$usedup = $_POST['usedup'];
					$instock = $_POST['instock'];
					$totaltstock = $_POST['totaltstock'];

// Include database config file 

// Connect to mysql and select database 
$db1 = mysql_connect("localhost", "host", ""); 
mysql_select_db("polish"); 
// Run query, check for errors 
$query = "UPDATE update SET raekke = '".$_POST['raekke']."', modelnr = '".$_POST['modelnr']."', navn = '".$_POST['navn']."', priser = '".$_POST['priser']."', display= '".$_POST['display']."', bruger='".$_POST['bruger']."', salg= '".$_POST['salg']."', usedup='".$_POST['usedup']."', instock = '".$_POST['instock']."', totaltstock='".$_POST['totaltstock']."' WHERE id = '".$_POST['id']."'";
if (mysql_query($query) == FALSE) 
{ 
echo "Database Error: " . mysql_error(); 
} 
// Check for affected records 
if (mysql_affected_rows() > 0) 
{ 
echo "Record updated<br><a href=\"sysdocupdate.php\">click here</a> to update another record<br>"; 
} 
else 
{ 
echo "No records updated"; 
} 
// Close database connection 
mysql_close($db1); 
?> 
</body> 
</html> 

 

i get this error from NR:3 Postupdated

 

Database Error: 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 'update SET raekke = '3', modelnr = '0', navn = 'hello', priser = '0', display= '' at line 1No records updated

 

some people can help me thanks very much

 

 

Link to comment
https://forums.phpfreaks.com/topic/242990-update-database-php-not-work/
Share on other sites

// Run query, check for errors 
$query = "UPDATE update SET raekke = '".$_POST['raekke']."', modelnr = '".$_POST['modelnr']."', navn = '".$_POST['navn']."', priser = '".$_POST['priser']."', display= '".$_POST['display']."', bruger='".$_POST['bruger']."', salg= '".$_POST['salg']."', usedup='".$_POST['usedup']."', instock = '".$_POST['instock']."', totaltstock='".$_POST['totaltstock']."' WHERE id = '".$_POST['id']."'";

 

update (used there as a table name) is a mysql reserved word  you must enclose it in backtiks ...  UPDATE `update` or change the table name (recommended)

i have try to change

$query = "UPDATE `polish`.`update` SET

Database Error: UPDATE command denied to user ''@'localhost' for table 'update'No records updated

 

$query = "UPDATE `update` SET

Database Error: No database selectedNo records updated

 

update is my database table name, so is best i change them.but my code is not problem?

 

thanks

most likely you are not connected to the DB, hence the error

 

in your file  sysdocupdate.php you have this line for connection

 

$db1 = mysql_connect ("localhost", "root","", "") or die ("cannot connect");
mysql_select_db("polish") or die ("cannot select DB");

 

and then in your file  postupdated.php  you have this lines that are different to the previous ones

// Connect to mysql and select database 
$db1 = mysql_connect("localhost", "host", ""); 
mysql_select_db("polish"); 

 

so.. are you sure that you are using the right login credentials in both cases?

 

you should enable error reporting and display errors during develop (look for the 2 lines in my signature)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.