Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing data inputted

Status
Not open for further replies.

omega1983

Programmer
Dec 21, 2004
32
US
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??
 

Could it just be a simple typo?
Code:
$result= mysql_query($sql_conn) or die(mysql_error());

Should it perhaps be:
Code:
$result= mysql_query($sql[COLOR=red], $[/color]conn) or die(mysql_error());

Cheers,
Jeff
 
BabyJeffy has it right.
The mysql_query() statment requires the SQL statement to be present. There are 2 arguments of which the second one is optional, the first isn't.
Have a closer look at the documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top