Jump to content

adding info into mysql


lmcgr44

Recommended Posts

hello

 

i am trying to add infomation into the mysql but it always seems to add it a 0 instead of what i am typeing into the form, the form is to add recipies to a users file. these are the scriprts, the fields that arnt showing up is prep and cook

 

add_recipie.php

<?php
// Start_session, check if user is logged in or not, and connect to the database all in one included file
include_once("scripts/checkuserlog.php");
// Include the class files for auto making links out of full URLs and for Time Ago date formatting
include_once("wi_class_files/autoMakeLinks.php");
include_once ("wi_class_files/agoTimeFormat.php");
// Create the two objects before we can use them below in this script
$activeLinkObject = new autoActiveLink;
$myObject = new convertToAgo;
?>
<?php
// Include this script for random member display on home page
include_once "scripts/homePage_randomMembers.php"; 
?>
<?php
$sql_blabs = mysql_query("SELECT id, mem_id, the_blab, blab_date FROM blabbing ORDER BY blab_date DESC LIMIT 30");

$blabberDisplayList = ""; // Initialize the variable here

while($row = mysql_fetch_array($sql_blabs)){

$blabid = $row["id"];
$uid = $row["mem_id"];
$the_blab = $row["the_blab"];
$notokinarray = array("fag", "gay", "shit", "fuck", "stupid", "idiot", "asshole", "cunt", "douche");
    $okinarray   = array("sorcerer", "grey", "shug", "farg", "smart", "awesome guy", "asshole", "cake", "dude");
$the_blab = str_replace($notokinarray, $okinarray, $the_blab);
$the_blab = ($activeLinkObject -> makeActiveLink($the_blab));
$blab_date = $row["blab_date"];
$convertedTime = ($myObject -> convert_datetime($blab_date));
    $whenBlab = ($myObject -> makeAgo($convertedTime));
//$blab_date = strftime("%b %d, %Y %I:%M:%S %p", strtotime($blab_date));
// Inner sql query
$sql_mem_data = mysql_query("SELECT id, username, firstname, lastname FROM myMembers WHERE id='$uid' LIMIT 1");
while($row = mysql_fetch_array($sql_mem_data)){
		$uid = $row["id"];
		$username = $row["username"];
		$firstname = $row["firstname"];
		if ($firstname != "") {$username = $firstname; } // (I added usernames late in  my system, this line is not needed for you)
		///////  Mechanism to Display Pic. See if they have uploaded a pic or not  //////////////////////////
		$ucheck_pic = "members/$uid/image01.jpg";
		$udefault_pic = "members/0/image01.jpg";
		if (file_exists($ucheck_pic)) {
		$blabber_pic = '<div style="overflow:hidden; width:40px; height:40px;"><img src="' . $ucheck_pic . '" width="40px" border="0" /></div>'; // forces picture to be 100px wide and no more
		} else {
		$blabber_pic = "<img src=\"$udefault_pic\" width=\"40px\" height=\"40px\" border=\"0\" />"; // forces default picture to be 100px wide and no more
		}

		$blabberDisplayList .= '
      			<table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC">
        <tr>
          <td width="7%" bgcolor="#FFFFFF" valign="top"><a href="profile.php?id=' . $uid . '">' . $blabber_pic . '</a>
          </td>
          <td width="93%" bgcolor="#EFEFEF" style="line-height:1.5em;" valign="top"><span class="greenColor textsize10">' . $whenBlab . ' <a href="profile.php?id=' . $uid . '">' . $username . '</a> said: </span><br />
          ' . $the_blab . '</td>
        </tr>
      </table>';
		}

}
?>
<!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" />
    <meta name="Description" content="Web Intersect is a deft combination of powerful free open source software for social networking, mixed with insider guidance and tutorials as to how it is made at its core for maximum adaptability. The goal is to give you a free website system that has a network or community integrated into it to allow people to join and interact with your website when you have the need." />
    <meta name="Keywords" content="web intersect, how to build community, build social network, how to build website, learn free online, php and mysql, internet crossroads, directory, friend, business, update, profile, connect, all, website, blog, social network, connecting people, youtube, myspace, facebook, twitter, dynamic, portal, community, technical, expert, professional, personal, find, school, build, join, combine, marketing, optimization, spider, search, engine, seo, script" />
    <title>CookBookers</title>
    <link href="style/main.css" rel="stylesheet" type="text/css" />
    <link rel="icon" href="favicon.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <script src="js/jquery-1.4.2.js" type="text/javascript"></script>
<style type="text/css">
#Layer1 {
height:210px;

}
body {
background-color: #3c60a4;
}
.style4 {font-size: 36px}
</style>
</head>
<body>
<p>
  <?php include_once "header_template.php"; ?>
  </head>
  <body 
style="margin:0px;">
  <center>
</p>
<p> </p>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="mainBodyTable">
  <tr>
    <td width="124" valign="top">
    <td width="776" colspan="2" align="left" valign="top" style="background-color:#EFEFEF; border:#999 0px; padding:10px;">
<table border="0" cellpadding="6">

  </table>
  <table width="574" border="0">
  <form method="POST" action="include/recipe.php">
    <span class="style4">Add Recipie</span>
  
    <tr>
      <th width="232" scope="col"> </th>
      <th width="332" scope="col"> </th>
    </tr>
    <tr>
      <td><span style="margin-bottom:5px; color:brown;">Public:</span></td>
      <td><span style="margin-bottom:5px; color:brown;">
        <input name="Pub" value="1" type="checkbox" id="Pub"/>
      </span></td>
    </tr>
    <tr>
      <td><span style="margin-bottom:5px; color:brown;">Title:</span></td>
      <td><span style="margin-bottom:5px; color:brown;">
        <input type="text" name="title" />
      </span></td>
    </tr>
    <tr>
      <td><span style="margin-bottom:5px; color:brown;">Prep time:</span></td>
      <td><span style="margin-bottom:5px; color:brown;">
        <input name="prep" type="text" size="7" maxlength="10" />
    </tr>
    <tr>
      <td><span style="margin-bottom:5px; color:brown;">Cooking time:</span></td>
      <td><span style="margin-bottom:5px; color:brown;">
        <input name="cook" type="text" size="7" maxlength="10" />
    </tr>
    <tr>
      <td><span style="margin-bottom:5px; color:brown;">Makes:</span></td>
      <td><span style="margin-bottom:5px; color:brown;">
         <input type="text" name="make" />
      </span></td>
    </tr>
    <tr>
      <td><span style="margin-bottom:5px; color:brown;">Ingrediants:</span></td>
      <td><span style="margin-bottom:5px; color:brown;">
        <textarea rows="5" name="ingr" cols="40"></textarea>
      </span></td>
    </tr>
    <tr>
      <td><span style="margin-bottom:5px; color:brown;">Method: </span></td>
      <td><span style="margin-bottom:5px; color:brown;">
        <textarea rows="5" name="desc" cols="40"></textarea>
      </span></td>
    </tr>
    <tr>
      <td><span style="margin-bottom:5px; color:brown;">Notes:</span></td>
      <td><span style="margin-bottom:5px; color:brown;">
        <textarea rows="5" name="note" cols="40"></textarea>
      </span></td>
    </tr>
<tr>
       <td><input name="submit" type="submit" style="padding:5px 10px;" value="Submit" /></td>
</tr>
  </table>
    </tr>
</table>
            </td>
</tr>
        </table>
	<?php include_once "footer_template.php"; ?>
</body>

 

recipie.php

<?php
//include("session.php");          
include("database.php");
@session_start();

$user = $_SESSION['username'];
    
//die($user);
$Pub=$_POST['Pub'];
    $title=$_POST['title'];
$prep=$_POST['prep'];
    $cook=$_POST['cook'];
    $make=$_POST['make'];
    $ingr=$_POST['ingr'];
    $desc=$_POST['desc'];
    $note=$_POST['note'];
    //if($user=="Guest"||$user==""){
    //header("Location: ../index.php");
    //}
    //else{
    $database->AddRecipe($user,$Pub,$title,$prep,$cook,$make,$ingr,$desc,$note);
    header("Location: ../recipe_added.php");
    //}
?>

 

database.php

<?
/**
* Database.php
* 
* The Database class is meant to simplify the task of accessing
* information from the website's database.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 17, 2004
*/
include("constants.php");
      
class MySQLDB
{
   var $connection;         //The MySQL database connection
   var $num_active_users;   //Number of active users viewing site
   var $num_active_guests;  //Number of active guests viewing site
   var $num_members;        //Number of signed-up users
   /* Note: call getNumMembers() to access $num_members! */

   /* Class constructor */
   function MySQLDB(){
      /* Make connection to database */
      $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
      mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
      
      /**
       * Only query database to find out number of members
       * when getNumMembers() is called for the first time,
       * until then, default value set.
       */
      $this->num_members = -1;
      
      if(TRACK_VISITORS){
         /* Calculate number of users at site */
         $this->calcNumActiveUsers();
      
         /* Calculate number of guests at site */
         $this->calcNumActiveGuests();
      }
   }

   /**
    * confirmUserPass - Checks whether or not the given
    * username is in the database, if so it checks if the
    * given password is the same password in the database
    * for that user. If the user doesn't exist or if the
    * passwords don't match up, it returns an error code
    * (1 or 2). On success it returns 0.
    */
   function confirmUserPass($username, $password){
      /* Add slashes if necessary (for query) */
      if(!get_magic_quotes_gpc()) {
      $username = addslashes($username);
      }

      /* Verify that user is in database */
      $q = "SELECT password FROM ".TBL_USERS." WHERE username = '$username'";
      $result = mysql_query($q, $this->connection);
      if(!$result || (mysql_numrows($result) < 1)){
         return 1; //Indicates username failure
      }

      /* Retrieve password from result, strip slashes */
      $dbarray = mysql_fetch_array($result);
      $dbarray['password'] = stripslashes($dbarray['password']);
      $password = stripslashes($password);

      /* Validate that password is correct */
      if($password == $dbarray['password']){
         return 0; //Success! Username and password confirmed
      }
      else{
         return 2; //Indicates password failure
      }
   }
   
   /**
    * confirmUserID - Checks whether or not the given
    * username is in the database, if so it checks if the
    * given userid is the same userid in the database
    * for that user. If the user doesn't exist or if the
    * userids don't match up, it returns an error code
    * (1 or 2). On success it returns 0.
    */
   function confirmUserID($username, $userid){
      /* Add slashes if necessary (for query) */
      if(!get_magic_quotes_gpc()) {
      $username = addslashes($username);
      }

      /* Verify that user is in database */
      $q = "SELECT userid FROM ".TBL_USERS." WHERE username = '$username'";
      $result = mysql_query($q, $this->connection);
      if(!$result || (mysql_numrows($result) < 1)){
         return 1; //Indicates username failure
      }

      /* Retrieve userid from result, strip slashes */
      $dbarray = mysql_fetch_array($result);
      $dbarray['userid'] = stripslashes($dbarray['userid']);
      $userid = stripslashes($userid);

      /* Validate that userid is correct */
      if($userid == $dbarray['userid']){
         return 0; //Success! Username and userid confirmed
      }
      else{
         return 2; //Indicates userid invalid
      }
   }
   
   /**
    * usernameTaken - Returns true if the username has
    * been taken by another user, false otherwise.
    */
   function usernameTaken($username){
      if(!get_magic_quotes_gpc()){
         $username = addslashes($username);
      }
      $q = "SELECT username FROM ".TBL_USERS." WHERE username = '$username'";
      $result = mysql_query($q, $this->connection);
      return (mysql_numrows($result) > 0);
   }
   function showRecipees($username){
      $q = "SELECT * FROM recipies WHERE user = '$username'";
      $result = mysql_query($q, $this->connection);
      /* Error occurred, return given name by default */
      if(!$result || (mysql_numrows($result) < 1)){
         return NULL;
      }
      /* Return result array */   
        $rows;
        $i=0;
      while($row=mysql_fetch_row($result))
      {
             $rows[$i]=$row;
             $i++;
      }
      return $rows;
   }

   function showRecipees1(){
      $q = "SELECT * FROM recipies";
      $result = mysql_query($q, $this->connection);
      /* Error occurred, return given name by default */
      if(!$result || (mysql_numrows($result) < 1)){
         return NULL;
      }
      /* Return result array */   
        $rows;
        $i=0;
      while($row=mysql_fetch_row($result))
      {
             $rows[$i]=$row;
             $i++;
      }
      return $rows;
   }

   /**
    * usernameBanned - Returns true if the username has
    * been banned by the administrator.
    */
   function usernameBanned($username){
      if(!get_magic_quotes_gpc()){
         $username = addslashes($username);
      }
      $q = "SELECT username FROM ".TBL_BANNED_USERS." WHERE username = '$username'";
      $result = mysql_query($q, $this->connection);
      return (mysql_numrows($result) > 0);
   }
   
   /**
    * addNewUser - Inserts the given (username, password, email)
    * info into the database. Appropriate user level is set.
    * Returns true on success, false otherwise.
    */
   function addNewUser($username, $password, $email){
      $time = time();
      /* If admin sign up, give admin user level */
      if(strcasecmp($username, ADMIN_NAME) == 0){
         $ulevel = ADMIN_LEVEL;
      }else{
         $ulevel = USER_LEVEL;
      }
      $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', $time)";
      return mysql_query($q, $this->connection);
   }
   
   /**
    * updateUserField - Updates a field, specified by the field
    * parameter, in the user's row of the database.
    */
   function updateUserField($username, $field, $value){
      $q = "UPDATE ".TBL_USERS." SET ".$field." = '$value' WHERE username = '$username'";
      return mysql_query($q, $this->connection);
   }
   
   /**
    * getUserInfo - Returns the result array from a mysql
    * query asking for all information stored regarding
    * the given username. If query fails, NULL is returned.
    */
   function getUserInfo($username){
      $q = "SELECT * FROM ".TBL_USERS." WHERE username = '$username'";
      $result = mysql_query($q, $this->connection);
      /* Error occurred, return given name by default */
      if(!$result || (mysql_numrows($result) < 1)){
         return NULL;
      }
      /* Return result array */
      $dbarray = mysql_fetch_array($result);
      return $dbarray;
   }
   
   /**
    * getNumMembers - Returns the number of signed-up users
    * of the website, banned members not included. The first
    * time the function is called on page load, the database
    * is queried, on subsequent calls, the stored result
    * is returned. This is to improve efficiency, effectively
    * not querying the database when no call is made.
    */
   function getNumMembers(){
      if($this->num_members < 0){
         $q = "SELECT * FROM ".TBL_USERS;
         $result = mysql_query($q, $this->connection);
         $this->num_members = mysql_numrows($result);
      }
      return $this->num_members;
   }
   
   /**
    * calcNumActiveUsers - Finds out how many active users
    * are viewing site and sets class variable accordingly.
    */
   function calcNumActiveUsers(){
      /* Calculate number of users at site */
      $q = "SELECT * FROM ".TBL_ACTIVE_USERS;
      $result = mysql_query($q, $this->connection);
      $this->num_active_users = mysql_numrows($result);
   }
   
   /**
    * calcNumActiveGuests - Finds out how many active guests
    * are viewing site and sets class variable accordingly.
    */
   function calcNumActiveGuests(){
      /* Calculate number of guests at site */
      $q = "SELECT * FROM ".TBL_ACTIVE_GUESTS;
      $result = mysql_query($q, $this->connection);
      $this->num_active_guests = mysql_numrows($result);
   }
   
   /**
    * addActiveUser - Updates username's last active timestamp
    * in the database, and also adds him to the table of
    * active users, or updates timestamp if already there.
    */
   function addActiveUser($username, $time){
      $q = "UPDATE ".TBL_USERS." SET timestamp = '$time' WHERE username = '$username'";
      mysql_query($q, $this->connection);
      
      if(!TRACK_VISITORS) return;
      $q = "REPLACE INTO ".TBL_ACTIVE_USERS." VALUES ('$username', '$time')";
      mysql_query($q, $this->connection);
      $this->calcNumActiveUsers();
   }
   
   /* addActiveGuest - Adds guest to active guests table */
   function addActiveGuest($ip, $time){
      if(!TRACK_VISITORS) return;
      $q = "REPLACE INTO ".TBL_ACTIVE_GUESTS." VALUES ('$ip', '$time')";
      mysql_query($q, $this->connection);
      $this->calcNumActiveGuests();
   }
   
   /* These functions are self explanatory, no need for comments */
   
   /* removeActiveUser */
   function removeActiveUser($username){
      if(!TRACK_VISITORS) return;
      $q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE username = '$username'";
      mysql_query($q, $this->connection);
      $this->calcNumActiveUsers();
   }
   
   /* removeActiveGuest */
   function removeActiveGuest($ip){
      if(!TRACK_VISITORS) return;
      $q = "DELETE FROM ".TBL_ACTIVE_GUESTS." WHERE ip = '$ip'";
      mysql_query($q, $this->connection);
      $this->calcNumActiveGuests();
   }
   
   /* removeInactiveUsers */
   function removeInactiveUsers(){
      if(!TRACK_VISITORS) return;
      $timeout = time()-USER_TIMEOUT*60;
      $q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE timestamp < $timeout";
      mysql_query($q, $this->connection);
      $this->calcNumActiveUsers();
   }

   /* removeInactiveGuests */
   function removeInactiveGuests(){
      if(!TRACK_VISITORS) return;
      $timeout = time()-GUEST_TIMEOUT*60;
      $q = "DELETE FROM ".TBL_ACTIVE_GUESTS." WHERE timestamp < $timeout";
      mysql_query($q, $this->connection);
      $this->calcNumActiveGuests();
   }
   function AddRecipe($user,$Pub,$title,$prep,$cook,$make,$ingr,$desc, $note){
      if(!TRACK_VISITORS) return;
      $q = "INSERT INTO recipies (`user` ,`Pub` ,`title` ,`prep` ,`cook` ,`makes` ,`ingredients` ,`recipe` ,`notes`)VALUES ('$user', '$Pub', '$title', 'prep', 'cook','$make', '$ingr', '$desc', '$note');";
      mysql_query($q, $this->connection) or die(mysql_error());
      $this->calcNumActiveGuests();
   }
   function recipie_comment($user,$comment,$recipie_id){
      if(!TRACK_VISITORS) return;
      $q = "INSERT INTO recipie_comment (`user` ,`comment`, `recipie_id`);";
      mysql_query($q, $this->connection) or die(mysql_error());
      $this->calcNumActiveGuests();
   }
   /**
    * query - Performs the given query on the database and
    * returns the result, which may be false, true or a
    * resource identifier.
    */
   function query($query){
      return mysql_query($query, $this->connection);
   }
};

/* Create database connection */
$database = new MySQLDB;

?>

 

and also the fields in the database are int 11 for both prep and cook

 

thanks

Link to comment
Share on other sites

function AddRecipe($user,$Pub,$title,$prep,$cook,$make,$ingr,$desc, $note){
      if(!TRACK_VISITORS) return;
      $q = "INSERT INTO recipies (`user` ,`Pub` ,`title` ,`prep` ,`cook` ,`makes` ,`ingredients` ,`recipe` ,`notes`)VALUES ('$user', '$Pub', '$title', 'prep', 'cook','$make', '$ingr', '$desc', '$note');";
      mysql_query($q, $this->connection) or die(mysql_error());
      $this->calcNumActiveGuests();
   }

 

What do YOU think is wrong with this piece of code?

You gave the answer in your question :)

Link to comment
Share on other sites

function AddRecipe($user,$Pub,$title,$prep,$cook,$make,$ingr,$desc, $note){
      if(!TRACK_VISITORS) return;
      $q = "INSERT INTO recipies (`user` ,`Pub` ,`title` ,`prep` ,`cook` ,`makes` ,`ingredients` ,`recipe` ,`notes`)VALUES ('$user', '$Pub', '$title', 'prep', 'cook','$make', '$ingr', '$desc', '$note');";
      mysql_query($q, $this->connection) or die(mysql_error());
      $this->calcNumActiveGuests();
   }

 

I really don't no I have been trying this for almost a day now

 

What do YOU think is wrong with this piece of code?

You gave the answer in your question :)

Link to comment
Share on other sites

What raknjak means with, you gave the answer in your question, is "both prep and cook" so have a look at those values in your code and you will see what is wrong.

 

hey

 

thats the thing i do not see anything wrong, im new to php and mysql and when i look at it, it looks good to me

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.