inserting record help

2 posts Page 1 of 1
Contributors
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

inserting record help
Mark
Hello,

I was wondering if any of you can help me please.

My problem is im trying to get this code to insert the record in to my table it says its been added to the database but when i check its not can anyone see whats wrong please?.
Code: Select all
<?php $title = "MBAPPZ.com - Create A New Message"; ?>

<?php require("styles/top.php"); ?>

	<div id='left'>
			<?php
      
      if($username){
      
      echo "Create New Message<br /><br />";
      
      $form = "<form action='create_message.php' method='POST'><table>
      <tr>
        <td><input type='text' name='sendtouser' size='30' class='textbox'></td>
      </tr>
       <tr>
        <td><input type='text' name='subject' size='30' class='textbox'></td>
      </tr>
      <tr>
        <td><textarea name='content' cols='45' rows='7' class='textbox'></textarea></td>
      </tr>
      <tr>
        <td><input type='submit' name='sendbutton' value='Send Message' class='button'></td>
      </tr>
      </table></form>";
      
      if ($_POST['sendbutton']){
			$sendtouser = $_POST['sendtouser'];
			$subject = $_POST['subject'];
			$content = $_POST['content'];
			
			if ($sendtouser && $subject && $content){
				require('scripts/connect.php');
				$query = mysql_query("SELECT * FROM users WHERE username='$sendtouser'");
				$numrows = mysql_num_rows($query);
				if ($numrows == 1){
					$row = mysql_fetch_assoc($query);
					$to_user = $row['username'];
					$to_id = $row['id'];
					$date = date("M d, Y");
					
					$query = mysql_query("SELECT * FROM messages WHERE content='$content' AND to_id='$to_id' AND from_id='$userid' AND date='$date'");
					$numrows = mysql_num_rows($query);
					if ($numrows == 0){
						mysql_query("INSERT INTO messages VALUES ('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date')");
						echo "Your message has been sent.  <a href='inbox.php'>Click Here</a> to return to your inbox.";
					}
					else
						echo "You can not resend the same message again. $form";
				}
				else
					echo "The username you have entered is invalid please try again. $form";
			}
			else
				echo "You did not fill the entire message form. $form";
      }
      else
        echo "$form";
      
      }
      else
        echo "You must be logged in to view this page sorry.";
	
  ?>
  </div>
  
  <div id='right'>
        Advertisements Coming Soon.
  </div>
	
	
<?php require("styles/bottom.php"); ?>
Thanks in advance.
http://www.mbappz.com
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: inserting record help
Filip
Hello,

I had some simular issues before. Here are some tips:

1. If you have phpMyAdmin try running the same query in their interface, it can also give you PHP code for the query.
2. Make yourself a function which will query database:
Code: Select all
	#MySql query function
	function msqlQuery($query) {
		$con=mysqli_connect(MSQL_HOST, MSQL_USERNAME, MSQL_PASSWORD, MSQL_DATABASE);
		if (mysqli_connect_errno()) echo "Error connecting to database". mysqli_connect_error();
	
	
		$result = mysqli_query($con, $query);
		
		$output = Array();
		
		while($row = mysqli_fetch_array($result)) array_push($output, $row);
		  
		mysqli_close($con);
		
		return $output;
	}
and use fuction like this:
Code: Select all
$result = msqlQuery("SELECT * FROM `".STBL_SENSORDATA."`");
Don't forget to put rows' and databases' name between `name`
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
2 posts Page 1 of 1
Return to “Help & Support”