Jump to content

Error message I'm getting


j05hr

Recommended Posts

I'm copying a video tutorial and I keep getting this error message...

 

 

Notice: Undefined index: visible in C:\wamp\www\widget_corp\create_subject.php on line 7

 

Subject creation failed.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 5

 

It has example code and I've copied the example code so I don't think it's an error in the code?  I think it has something to do with my database but I've looked at everything in there and the spelling looks ok.

 

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>

<?php
$menu_name = $_POST['menu_name'];
$position = $_POST['position'];
$visible = $_POST['visible'];
?>
<?php
$query = "INSERT INTO subjects (
			menu_name, position, visible
		) VALUES (
			'{$menu_name}', {$position}, {$visible}
		)";
if (mysql_query($query, $connection)) {
	// Success!
	header("Location: content.php");
	exit;
} else {
	// Display error message.
	echo "<p>Subject creation failed.</p>";
	echo "<p>" . mysql_error() . "</p>";
}
?>

<?php mysql_close($connection); ?>

 

 

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
find_selected_page();
?>
<?php include("includes/header.php"); ?>
<table id="structure">
<tr>
	<td id="navigation">
		<?php echo navigation($sel_subject, $sel_page); ?>
	</td>
	<td id="page">
		<h2>Add Subject</h2>
		<form action="create_subject.php" method="post">
			<p>Subject name: 
				<input type="text" name="menu_name" value="" id="menu_name" />
			</p> 
			<p>postion:
				<select name="position">
					<?php
						$subject_set = get_all_subjects();
						$subject_count = mysql_num_rows($subject_set);
						//$subject_count + 1 because we are adding a subject
						for($count=1; $count <= $subject_count+1; $count++) {
							echo "<option value=\"{$count}\">{$count}</option>";
						}
					?>

				</select>
				</p>
				<p>Visible:
					<input type="radio" name="visible" value="0" /> No
					 
					<input type="radio" name="visbile" value="1" /> Yes
				</p>
				<input type="submit" value="Add subject" />
			</form>
		<br />
		<a href="content.php">Cancel</a>
	</td>
</tr>
</table>
<?php require("includes/footer.php"); ?>

Link to comment
https://forums.phpfreaks.com/topic/177531-error-message-im-getting/
Share on other sites

Well if you're setting visible to yes then you will get that error as you've spelt it wrong.... You've spelt it as visbile...

 

Change your code to:

 

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
   find_selected_page();
?>
<?php include("includes/header.php"); ?>
<table id="structure">
   <tr>
      <td id="navigation">
         <?php echo navigation($sel_subject, $sel_page); ?>
      </td>
      <td id="page">
         <h2>Add Subject</h2>
         <form action="create_subject.php" method="post">
            <p>Subject name:
               <input type="text" name="menu_name" value="" id="menu_name" />
            </p>
            <p>postion:
               <select name="position">
                  <?php
                     $subject_set = get_all_subjects();
                     $subject_count = mysql_num_rows($subject_set);
                     //$subject_count + 1 because we are adding a subject
                     for($count=1; $count <= $subject_count+1; $count++) {
                        echo "<option value=\"{$count}\">{$count}</option>";
                     }
                  ?>
                  
               </select>
               </p>
               <p>Visible:
                  <input type="radio" name="visible" value="0" /> No
                   
                  <input type="radio" name="visible" value="1" /> Yes
               </p>
               <input type="submit" value="Add subject" />
            </form>
         <br />
         <a href="content.php">Cancel</a>
      </td>
   </tr>
</table>
<?php require("includes/footer.php"); ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.