Need PHP Help

Hi, guys. I need help. I’m doing a homework assignment and whenever I try to submit a joke, it won’t show up in the database. What should I do? Here’s my code:

<?xml version = "1.0" encoding = "utf-8"?> Jokes body { font-family: arial, sans-serif; background-color: #99CCFF } form { font-size: 10pt } .submit { background-color: #F0E86C; color: navy; font-weight: bold }

Click submit to enter your joke into the database.

Joke Text:

        <strong>Joke Punch:</strong><br />
        <input type = "text" name = "jokepunch" /><br />

        <strong>Joke Author:</strong><br />
        <input type = "text" name = "jokeauthor" /><br />
        
        <strong>Joke Date:</strong><br />
        <input type="text" name = "jokedate" /><br />

        <input type = "submit" value = "Submit" 
           class = "submit" />
     </div>
  </form>
<?php extract( $_POST ); { // build INSERT query $query = "INSERT INTO joke " . "( joketext, jokepunch, jokeauthor, jokedate) " . "VALUES ( '$joketext', '$jokepunch', '$jokeauthor', '$jokedate')"; // Connect to MySQL if ( !( $database = mysqli_connect('infolnx1.mccinfo.net', 'INFO2340', 'password') ) ) die( "Could not connect to database" ); } ?> <?php print( '<?xml version = "1.0" encoding = "utf-8"?>' )

?>

<! DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Joke Saved body { font-family: arial, sans-serif } span { color: blue }

The joke has been set with the following data:

  <!-- print each form field's value -->
  <br /><span>Joke Text:</span><?php print( $joketext ) ?><br />          
  <span>Joke Punch:</span><?php print( $jokepunch ) ?><br />         
  <span>Joke Author:</span><?php print( $jokeauthor ) ?><br />    
  <span>Joke Date:</span><?php print( $jokedate ) ?><br />    
  <p>Click <a href = "jokes.php">here</a>
     to read the saved joke.</p>
<?php include 'connect.php'; ?>

<! DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<link rel="stylesheet" type="text/css" href="css/styles.css" />

<title>Jokes</title>
<body>

	<table cellpadding="0" cellspacing="0">

	<tr>

		<td>Joke ID</td>

		<td>Joke Text</td>

		<td>Joke Punch</td>

		<td>Joke Author</td>

		<td>Joke Date</td>

	</tr>

	<?php

		$jokeresult = mysqli_query($link, 'SELECT id, joketext, jokepunch, jokeauthor, jokedate FROM joke;');

		if (!$jokeresult)

		{

			$error = 'Error fetching jokes: ' . mysqli_error($link);

			exit();

		}

	

		for ($counter = 0; $row = mysqli_fetch_row($jokeresult); $counter++)

		{

			print("<tr>");

			foreach ($row as $key => $value)

			{

				print("<td>$value</td>");

			}

			print("</tr>");

		}

	?>
    

	</table>

</body>
<?php $link = mysqli_connect('infolnx1.mccinfo.net', 'INFO2340', 'password'); if (!$link) { $output = 'Unable to connect to the database server.'; include 'output.html.php'; exit(); } if (!mysqli_set_charset($link, 'utf8')) { $output = 'Unable to set database connection encoding.'; include 'output.html.php'; exit(); } if (!mysqli_select_db($link, 'mmbierman')) { $output = 'Unable to locate the database.'; include 'output.html.php'; exit(); } ?>

Hi,

After a quick look, my first assumption would be that you are missing “mysqli_query($query);” inside the extract($_POST) section.

Sponsor our Newsletter | Privacy Policy | Terms of Service