MySQL query won't insert no error message

hi I’m new here with a real simple newbie problem I just can’t solve. I’ve a connection to my database but can’t the query to insert, or get an error message back. I have other ‘select’ scripts that work so the connection works. What am I doing wrong??? and why don’t I get any errors returned?
TIA



<html>
<head>
<title>Input Links</title>
</head>
<body>
<H1 align=center><FONT color=blue>Web Content Control Panel</FONT></H1><br>

<TABLE align=center>
<TR>
    <TD>
<?php
//ini_set('display_errors',1); 
//error_reporting(E_ALL);
 
 

//connect to database
$db = mysql_connect("localhost", "user", "*******") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("my_db",$db); 


if ($submit) {

        $sql = "INSERT INTO links (link_desc, link_url) VALUES ('$link_desc','$link_url')";

    // run SQL against the DB
    $result = mysql_query($sql,$db);
    if (!$result) {
    die('Invalid query: ' . mysql_error());
}

   echo "<h3 align=center>Link Entered!</h3><br>";
   // Close the database connection
    mysql_close();
    } 
?>

 </td></tr>
<tr><td>

  
<!-- display form for links entry  -->
    <form method="post"  name="myForm" action="<?php echo $_SERVER['PHP_SELF'] ?> " >
 <TABLE align=center border=1>

  <TR><TD align=right>Link Description :</TD><TD><input type="Text" name="link_desc" size="100" ></TD></TR>

 <TR><TD align=right> URL:</TD><TD><input type="Text" name="link_url" size="50" ></Textarea></TD></TR>

   <TR><TD><input type="Submit" name="submit" value="Add Link"></TD><TD></TD></TR>
</TABLE>
       
  </form>
</body>
</html>

Try changing “if($submit)” to this:


if (isset($_POST["submit"])) {
    print("OK!");
    $sql = ... etc, etc.

Thankyou very much transio!! The SQl query now runs against the database but entering null values. This must be a PHP problem. At least now I’ve got something to work with. I’ll get a chance to work on this later after work. Thanks again for the quick response.

Sorted! The PHP post needed to be changed to $_POST[link_desc] to enter a value to the db.

Good deal. :slight_smile:

Look in the PHP manual on how to use MYSQL_REAL_ESCAPE_STRING to make sure you are only sending clean data to your database.

Thanks for the heads-up on that guelphdad, I’m still just trying to get the thing to work, then I need to clean things up with untainting user input and cleaning input data. Cheers