Hello all, I am a newbie to this PHP lark but I am finding it very interesting indeed. I am currently doing a project which involves creating and editing user CV details for online purposes. For some reason my test code is not working (how unusual!). I am trying to create a user in a pre-defined table in MySQL. My test connections are ok so I know that My configuration of MySQL and Apache are ok. (hopefully).
Here is the feeble snippet of code that does not work:
<html><head><title>NEW USER</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body>
<p><font size="4">Please enter username details:</font>
<?php
Ensuring that all fields have entries
if ($name and $pass)
{
#Connect to MySQL
$conn=@mysql_connect("localhost","root","")
or die("Sorry no connection");
#echo("MySQL connection test ok."."<br>");
#Select the specified database
$rs = @mysql_select_db("cvtest", $conn)
or die("Database not located");
#echo("Database located ok."."<br>");
#Create the query
$sql="insert into candidate (uname,password) values (\"$name\", \"$pass\" )";
#execute the query
$rs = @mysql_query($sql,$conn);
#confirm the added record details
if($rs) { echo("Record added: $name $pass");}
} #PROBLEMS WITH FORM NOT SUBMITTING VALUES TO SQL STATMENT SO NO DATA IS ENTERED!!
?>
</p>
<form action="<?php echo($PHP_SELF); ?>" method="post">
User Name: <input type="text" name="name" size="8">
Password: <input type="text" name="pass" size="8">
<br>
<br>
<input name="submit" type="submit" value="Create User">
</form></body></html>
If I comment out the "if"statement, then ther are two null entries in MySQL - Wierd! (but at least connection is ok). Something about the form is not passing on the variables "name" and "pass" so while I am checking to ensure that the fields are complete, no data gets passed to MySQL. I have a feeling in my water about the sql string but can't put my finger on it. If you are still awake after all this and can help, I would be very grateful indeed, as the rest of the project can follow this same format for all editing purposes. Thanx in advance.