...

View Full Version : mysql php help!



coming2soon
05-25-2011, 05:20 PM
Hi,
I'm new on mySQL. I want to validate user input from html form with mySQL row.

----------------------
html>
<head></head>
<body>
<form name="login" method="post" action="if.php">
Lucky Number <input type="text" name="guess" />
<input type="submit" value="Submit" />
</form>
</body>
</html>



and if.php is here

--------------------------------
<?php
$dbhost = "localhost";
$dbname = "gm";
$dbuser = "root";
$dbpass = "";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

//table rows
$guess = $_POST['guess'];
$result = mysql_query("SELECT guessnum FROM secnum");
$row = mysql_fetch_array( $result);

if($_POST['guess']==$row) {
echo "<p>Good Job!</p>";
} else {
echo "<p>Sorry!</p>";
}
?>


---------------------------
and my mysql database is like this
Datebase name = gm
table=secnum
column=guessnum
row(or column value)=1

Fumigator
05-25-2011, 05:32 PM
if($_POST['guess']==$row) {

That won't work because $row is an array. But more to the point, you should be able to use a WHERE clause on your query to determine if your row exists, rather than selecting _every row_ in your table and then using PHP to look for the row you're after.

Look in the PHP manual at php.net for examples of how to use mysql_fetch_array(). Also look for some basic SQL tutorials on the internet.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum