PDA

View Full Version : Can anyone say if this is right?


Fronix
01-06-2008, 06:01 PM
<?php
require_once("../../../Documents and Settings/oskar/My Documents/Local root/Test/Connections/connection.php"); // database connection script
////////////////////////////////////////////
$data2 = $_POST['data2'];
$data3 = $_POST['data3'];
$data4 = $_POST['data4'];
$submit = $_POST['submit'];
////////////////////////////////////////////
if ($data2 && $data3 && $data4){
//////////////////////////////////////////
$query = sprintf("INSTERT info realtech ($field2, $field3, $field4) values ('$data2, $data3, $data4')");
mysql_query[$query]or die(mysql_error()};
//////////////////////////////////////////
)elseif($submit)(
echo "One of your fields is empty";
}
/////////////////////////////////////////////////
$query = sprintf("SELECT * FROM realtech");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
/////////////////////////////////////////////////

/*do (
echo $row['field3']."<br>";
)while ($row = mysql_fetch_array($result))*/


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Connection</title>
<style type="text/css">
<!--
.style1 (font-size: 10px)
-->
</style>
</head>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post" action=""<?php $_SERVER['PHP_SELF']; ?>">
<table width="452" border="1">
<tr>
<td width="144">data2</td>
<td width="292">data3</td>
<td width="144">data4</td>
</tr>
<tr>
<td height="23"><label for="textfield"></label>
<input type="text" name="data2" id="data2" /></td>
<td><label for="label"></label>
<input type="text" name="data3" id="label" /></td>
<td><label for="label2"></label>
<input type="text" name="data3" id="label2" /></td>
</tr>
<tr>
<td height="39" colspan="3"><label for="textfield"></label>
<label for="Submit"> </label>
<label for="Submit"></label>
<h1>
<label for="Submit"></label>
<input type="submit" name="Submit" value="Submit" id="Submit" />
<input name="submit" type="hidden" id="submit" />
</h1></td>
</tr>
</table>
<p>&nbsp;</p>
</form>
<table width="424" height="57" border="1">
<tr>
<td height="24">ID1</td>
<td>data2</td>
<td>data3</td>
<td>data4</td>
</tr>

<?php do ( ?>
<tr>
<td height="25"><?php echo $row['field1_id'];?></td>
<td><?php echo $row['field2']?></td>
<td><?php echo $row['field3']?></td>
<td><?php echo $row['field4']?></td>
</tr>
<?php )while ($row = mysql_fetch_array($result)); ?>


</table>
</body>
</html>


Plz tell me if its right or wrong and if its wrong plz say the solution to me and what was wrong so i learn something :P

davidj
01-06-2008, 07:37 PM
this is right


if ($data2 && $data3 && $data4){ //<<



this is wrong


//////////////////////////////////////////
$query = sprintf("INSTERT info realtech ($field2, $field3, $field4) values ('$data2, $data3, $data4')");
mysql_query[$query]or die(mysql_error()};
//////////////////////////////////////////




you have defined your fields as variables here...

($field2, $field3, $field4) values ('$data2, $data3, $data4')

the vars are correct but the fields are not. They should be the name of your fields without the $