Jump to content

Can't insert


aspnetguy

Recommended Posts

Well, I am now learning php and I am having trouble inserting a recordhere is my code

<?phpinclude('db.php');include('authenticate.php');if($action == "add"){  $topic_name = $_POST['topicname'];  $topic_pass = $_POST['topicpass'];  $topic_pdf = $_POST['topicpdf'];  $topic_notes = $_POST['topicnotes'];  if($topic_name == "")    $msg = "Enter topic name";  elseif($topic_pass == "")    $msg = "Enter password";  elseif($topic_pdf == "0")    $msg = "Select PDF";  else  {    $db = mysql_connect($db_server,$db_usr,$db_passw);    @mysql_select_db($db_name) or die( "Unable to select database");    $sql =  "INSERT INTO Topics ";    $sql .= "('TopicName','KeyCode','Pdf','Notes') ";    $sql .= "VALUES('$topic_name','$topic_pass','$topic_pdf','$topic_notes')";    mysql_query($sql);    mysql_close($db);    $msg = "Topic added";  }}?><html><head>  <title>Admin Area - Add Topic</title>  <link type="text/css" rel="stylesheet" href="../scripts/admin.css"/></head><body><form action="?action=add" method="post"><table>  <tr>    <td>Topic Name:</td>    <td><input type="text" name="topicname" id="topicname" style="width:150px" value="<?php echo $topic_name?>"/></td>  <tr>  <tr>    <td>Topic Password:</td>    <td><input type="password" name="topicpass" id="topicpass" style="width:150px" value="<?php echo $topic_pass?>"/></td>  <tr>  <tr>    <td>Topic Pdf:</td>    <td>      <select name="topicpdf" id="topicpdf">        <option value="0">Select PDF</option>        <option value="testpdf.pdf">testpdf.pdf</option><?php//read pdf folder?>      </select>    </td>  <tr>  <tr>    <td>Notes:</td>    <td><textarea name="topicnotes" id="topicnotes" rows="4" columns="25"><?php echo $topic_notes?></textarea></td>  </tr>  <tr>    <td colspan="2">      <input type="submit" value="Add Topic"/>       <input type="button" value="Cancel" onclick="java script:history.back()"/>    </td>  </tr></table><div style="display:block"><?php echo $msg?></div></form></body></html>

Any ideas as to why it won't insert...it displays "topic added" but when I check the db it is not there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...