Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP Submitting News (Query Error)

    The code below works on another website I use but when pasted and modded to fit this site it stopped working for no apparent reason (I've looked over and tripled checked my code) The database connection is correct but the script dies trying to insert the entries.

    The database looks like this:
    Table: News
    news_id : int(5) (auto increment)
    subject : varchar(200)
    body : longtext
    image : varchar(200)
    date : date


    Code:
     <?
     session_start();                                        # 7
      
      if (@$_SESSION['auth'] != "yes")                        # 9
      {
         header("Location: Login.php");
         exit();
      }
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    body,td,th {
    	color: #FFFFFF;
    }
    body {
    	background-color: #000000;
    	background-image: url(Images/bg_main.gif);
    	background-repeat: repeat-x;
    	margin-left: 0px;
    	margin-top: 0px;
    	margin-right: 0px;
    	margin-bottom: 0px;
    }
    a:link {
    	color: #FFFF00;
    	text-decoration: none;
    }
    a:visited {
    	color: #FFCC00;
    	text-decoration: none;
    }
    a:hover {
    	text-decoration: underline;
    }
    a:active {
    	text-decoration: none;
    }
    .style1 {
    	font-family: Verdana, Arial, Helvetica, sans-serif;
    	font-size: 10px;
    	font-weight: bold;
    }
    .style2 {font-size: 10px}
    -->
    </style></head>
    
    <body>
    <div align="center">
      <table width="1000" height="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td width="102" height="163"><img src="Images/1.gif" width="102" height="163" /></td>
          <td width="482" height="163"><img src="Images/2.gif" width="482" height="163" /></td>
          <td width="233" height="163"><img src="Images/3.gif" width="233" height="163" /></td>
          <td width="117" height="163"><img src="Images/4.gif" width="117" height="163" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td width="102" height="77"><img src="Images/5.gif" width="102" height="77" /></td>
          <td background="Images/6_bg.gif"><div align="center"><img src="Images/banner_top.jpg" width="468" height="60" /></div></td>
          <td width="233" height="77"><img src="Images/7.gif" width="233" height="77" /></td>
          <td width="117" height="77"><img src="Images/8.gif" width="117" height="77" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="32" height="40"><img src="Images/9.gif" width="32" height="40" /></td>
          <td width="102" height="40"><img src="Images/10.gif" width="102" height="40" /></td>
          <td width="482" height="40"><img src="Images/11.gif" width="482" height="40" /></td>
          <td width="233" height="40"><img src="Images/12.gif" width="233" height="40" /></td>
          <td width="117" height="40"><img src="Images/13.gif" width="117" height="40" /></td>
          <td width="34" height="40"><img src="Images/14.gif" width="34" height="40" /></td>
        </tr>
        <tr>
          <td width="32" height="80"><img src="Images/15.gif" width="32" height="80" /></td>
          <td width="102" height="80"><img src="Images/16.gif" width="102" height="80" /></td>
          <td height="80" colspan="2"><img src="Images/17.gif" width="715" height="80" /></td>
          <td width="117" height="80"><img src="Images/18.gif" width="117" height="80" /></td>
          <td width="34" height="80"><img src="Images/19.gif" width="34" height="80" /></td>
        </tr>
        <tr>
          <td height="100%" background="Images/20_runner_BG.gif">&nbsp;</td>
          <td height="100%" valign="top"><div align="right"><img src="Images/banner_left.jpg" width="100" height="487" /></div></td>
          <td height="100%" colspan="2" valign="top" background="Images/bg_inner.gif"><div align="center"><br />
               <?php
    if(isset($_POST['add']))
    {
    //************************************************
    // Customize this area to match your database information
    //************************************************
    
    include_once("Includes/news_conn.php");
    
    //************************************************
    // End of Database Connection & Selection
    //************************************************
    
    $insert_subject = $_POST['subject'];
    $insert_body = $_POST['body'];
    $insert_image = $_POST['image'];
    $date = date("Y-m-d");
    
    $query = "INSERT INTO News (subject, body, image, date) VALUES ('$insert_subject', '$insert_body', '$insert_image', '$date')";
    
    mysql_query($query) or die('Error, insert query failed');
    
    mysql_close();
    
    echo "New News Item has been added!<br> <a href='http://www.getliveevents.com'>Click Here to see your addition.</a>";
    }
    else
    {
    ?>
    <form method="post">
      <table width="502" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#999999">
        <tr>
          <td><div align="center">
            <table width="500" border="0" align="center" cellpadding="2" cellspacing="1">
              <tr>
                <td colspan="2" bgcolor="#363636"><div align="center"><img src="Images/add_news.jpg" width="495" height="82"></div></td>
                </tr>
              <tr>
                <td width="88" bgcolor="#363636" class="style12"><div align="right"><span class="style1">Subject</span></div></td>
                <td width="401" bgcolor="#363636"><div align="left">
                  <input name="subject" type="text" id="subject" size="62">
                </div></td>
              </tr>
              <tr>
                <td width="88" valign="top" bgcolor="#363636" class="style12"><div align="right"><span class="style1">Body</span></div></td>
                <td bgcolor="#363636">
                  <div align="left">
                    <textarea name="body" cols="45" rows="7" id="body"></textarea>
                    </div>
                </td>
              </tr>
              <tr>
                <td valign="top" bgcolor="#363636" class="style12"><div align="right"><span class="style1">Image Name </span></div></td>
                <td bgcolor="#363636"><div align="left">
                  <input name="image" type="text" id="image" size="62">
                </div></td>
              </tr>
              <tr>
                <td colspan="2" bgcolor="#363636"><span class="style1">(Please input the image name including extension you have uploaded to the Images Directory. If you have no image leave this field <strong>EMPTY</strong>  and no image will be used.) </span></td>
              </tr>
              <tr>
                <td width="88" bgcolor="#363636">&nbsp;</td>
                <td bgcolor="#363636">
                  <div align="center">
                    <input name="add" type="submit" id="add" value="Add News">
                    </div></td>
              </tr>
            </table>
          </div></td>
        </tr>
      </table>
    </form>
    <?php
    }
    ?> <br />
                
              <br />
          </div></td>
          <td height="100%" valign="top"><div align="right"><img src="Images/banner_right.jpg" width="100" height="487" /></div></td>
          <td height="100%" background="Images/21_runner_BG.gif">&nbsp;</td>
        </tr>
      </table>
    </div>
    </body>
    </html>

  • #2
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here is the code on it's own.. still not working:

    The database looks like this:
    Table: News
    news_id : int(5) (auto increment)
    subject : varchar(200)
    body : longtext
    image : varchar(200)
    date : date

    Code:
    <?
    				
    include_once("Includes/news_conn.php");
    
    $query = "SELECT * FROM News ORDER BY news_id DESC LIMIT 0, 4";
    $result = mysql_query($query);
    
    $num = mysql_numrows($result);
    
    mysql_close();
    
    
    
    $i = 0;
    
    while($i < $num)
    {
        $subject   = mysql_result($result,$i,"subject");
        $body      = mysql_result($result,$i,"body");
    	$image     = mysql_result($result,$i,"image");
    	$date      = mysql_result($result,$i,"date");
    
        echo "<table width='652' border='0' align='center' cellpadding='1' cellspacing='0' bgcolor='#E6E6E6'>
      <tr><tr>
            <td valign=top width='650' beight='20' bgcolor='#F4F4F4'><span class='style2'><div align='left'><strong>$subject</strong></div></span></td>
          </tr>
        <td>
    	<table width='650' border='0' align='center' cellpadding='0' cellspacing='0'>
          <tr>
            <td width='322' bgcolor='#FFFFFF'>
    		<div align='center'>
            	<a href='News_images/$image' target='blank'><img src='News_images/$image' height='240' width='320' alt='Click here to ENLARGE' border='0'></a> 
    		</div>        
    		</td>
        <td valign=top bgcolor='#FFFFFF'>				
    		<div align='right' class='style1'>
    				Article Added: $date
    		</div>
    	<hr>
    		<div align='left' class='style1'>	
    				$body	
    		</div>
    	<hr>
    		<div align='left'>	
    				
    				
    				
    		</div>
    	</td>
    </tr>   
        </table></td>
      </tr>
    </table><br>";
    
        $i++;
    }
    ?>
    Last edited by Andrius; 12-01-2006 at 02:41 AM.

  • #3
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know there are lots of ways to accomplish the same task...but, I prefer to do this another way:
    PHP Code:
    $query "SELECT * FROM News ORDER BY news_id DESC LIMIT 0, 4";
    $result mysql_query($query);

    while (
    $row mysql_fetch_assoc($result))
          {
              
    $newsentries[] = $row;
          }

    foreach (
    $newsentries AS $newsentry)
          {
    <
    display html information here with vars like$newsentry['subject']>
          } 
    This accomplishes the same task. I just think it's a bit cleaner and easier to control.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •