I used mysql server side to create a database named Database1 and a table named MyTable. Here is the the code for the input form:
<head>
<TITLE>Insert Form</TITLE>
</head>
<body>
<FORM ACTION="insert.php" METHOD=POST>
<p>Add Text Name<br>
<input type=text name="last" size=30>
<p><input type=submit name="submit value" value="Insert Record"></p>
</FORM>
</body>
</html>
Here is the insert.php form
<?php
$conn = mysql_connect("localhost", "xxx_user", "somepass");
mysql_select_db ("xxxx_Database1",$conn);
$sql = "INSERT INTO MyTable values('','$_POST[last]')";
$result = mysql_query($sql, $conn) or die(mysql_error());
if (mysql_query($sql, $conn)) {
echo "record added!";
}else {
echo "Uh Uh!";
}
?>
Here is the retrieval form to show the data I inputted
<?php
$conn = mysql_connect("localhost", "xxxx_user", "somepass");
mysql_select_db ("xxxx_Database1",$conn);
$sql = "SELECT * FROM MyTable";
$result= mysql_query($sql_conn) or die(mysql_error());
$number_of_rows = mysql_num_of_rows($result);
while ($newArray = mysql_fetch_array($result)) {
$id = $newArray['id'];
$last = $newArray['last'];
echo "ID $id Name $last<br>";
}
?>
The problem is I am getting an error message saying
Query was empty. Clearly I have the query statement present. Any therories??
<head>
<TITLE>Insert Form</TITLE>
</head>
<body>
<FORM ACTION="insert.php" METHOD=POST>
<p>Add Text Name<br>
<input type=text name="last" size=30>
<p><input type=submit name="submit value" value="Insert Record"></p>
</FORM>
</body>
</html>
Here is the insert.php form
<?php
$conn = mysql_connect("localhost", "xxx_user", "somepass");
mysql_select_db ("xxxx_Database1",$conn);
$sql = "INSERT INTO MyTable values('','$_POST[last]')";
$result = mysql_query($sql, $conn) or die(mysql_error());
if (mysql_query($sql, $conn)) {
echo "record added!";
}else {
echo "Uh Uh!";
}
?>
Here is the retrieval form to show the data I inputted
<?php
$conn = mysql_connect("localhost", "xxxx_user", "somepass");
mysql_select_db ("xxxx_Database1",$conn);
$sql = "SELECT * FROM MyTable";
$result= mysql_query($sql_conn) or die(mysql_error());
$number_of_rows = mysql_num_of_rows($result);
while ($newArray = mysql_fetch_array($result)) {
$id = $newArray['id'];
$last = $newArray['last'];
echo "ID $id Name $last<br>";
}
?>
The problem is I am getting an error message saying
Query was empty. Clearly I have the query statement present. Any therories??