Forum Moderators: coopster

Message Too Old, No Replies

Cannot insert data into mysql database

         

calmchess

9:33 pm on Feb 2, 2006 (gmt 0)

10+ Year Member



Will somebody plz look at this page and tell me if it is valid code....if not plz give me the solution.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>eol</title>

<head><link href="../common_css/eol.css" rel="stylesheet" type="text/css" media ="screen">

</head>

<body>

<?php
$link = mysql_connect('localhost', 'EOL', 'RK1RK1')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('EOL') or die('Could not select database');
mysql_query($query);

$query = "INSERT INTO EOL VALUES ($_POST'assettag')";

?>

<div class="con">

<div class="banbox">new record</div>

<div class="navbox">

<a href="/eol/cser_home.php">home</a>&nbsp

<a href="/eol/cser_allrec.php">allrecords</a>&nbsp

<a href="/eol/cser_search.php">search</a>&nbsp

<a href="/eol/cser_inser.php">new record</a>&nbsp

</div>

<div class="footerbox"></div>

<div class="datcon">

<form name ="form1" method="post">

<div class="formbox1">asset tag #&nbsp<input type="text"
name="assettag" action=" "></div>

<div class="formbox1">serial # &nbsp<input type="text" name="assettag" action=" "></div>

<div class="formbox1">location &nbsp<input type="text" name="assettag" action=" "></div>

<div class="formbox1">department &nbsp<input type="text" name="assettag" action=" "></div>

<div class="formbox1">office &nbsp<input type="text" name="assettag" action=" "></div>


<div class="textformbox">issues &nbsp<textarea rows="1" cols="13"></textarea></div>

<div class="formbox1">collected? &nbsp yes <input type="checkbox" name="assettag"></div>

<div class="buttbox">

<INPUT TYPE="image" SRC="../common_images/insert.jpg" VALUE="Submit" name = "submit">

</form>

<a href="search.php"><img border="0" src="../common_images/bak.jpg"></a>

<a href="search.php"><img border="0" src="../common_images/can.jpg"></a>

</div>

</div>

</div>

</body>

</html>

StupidScript

9:39 pm on Feb 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Three things:

First, you need to define your

$query
variable BEFORE you try to use it.

Second, note the correct

$_POST
array syntax.

Third, it's a good idea to assign a

$_POST
array value to a variable before trying to use it in a query, as the apostrophes and such tend to cause problems.

<?php

$link = mysql_connect('localhost', 'EOL', 'RK1RK1') or die('Could not connect: ' . mysql_error());

echo 'Connected successfully';

mysql_select_db('EOL') or die('Could not select database');

$assettag=[b]$_POST['assettag'][/b];

$query = "INSERT INTO EOL VALUES ('$assettag')";

mysql_query($query);

?>