Jump to content

DiscoTrio

Members
  • Posts

    78
  • Joined

  • Last visited

    Never

Posts posted by DiscoTrio

  1. I used to be good at this but I changed servers and everything is different...  Heres my code so far:

     

    <?php
    $rated=$_REQUEST['rated'];
    echo $rated;
    $rating=$_REQUEST['rating'];
    echo $rating;
    
    // Make a MySQL Connection
    mysql_connect("localhost", "********", "********") or die(mysql_error());
    mysql_select_db("*********") or die(mysql_error());
    
    $result = mysql_query("SELECT * FROM main WHERE username = '$rated'")
    or die(mysql_error());  
    
    $row = mysql_fetch_array( $result );
    
    $votes = $db_field['$rating'];
    $newvotes = $votes + 1;
    
    echo $newvotes;
    
    mysql_query("UPDATE main SET $rating = '$newvotes'
    WHERE username = '$rated'");
    
    
    ?>

     

    Whats going on here is the colomb that I want to update comes as a variable $rated (That works) and then the database selects the  row to update with $username (That works) and gets the variable $newvotes by taking the original value of the data its about to update and add 1 to it (That works)  Then it updates the field to $newvotes....

     

    I don't know why the update won't go through... there are no errors....

  2. I have a code from my friend that was written about two years back and there is one part I need help with:  Somehow it remebers what page you came from and you stay on that page after you log in.  I need help changing that to a certain page.  Keep in mind the browser never goes to these log in scripts.

     

    This is the part of the session controll script that logs you in and somehow marks what page you came from:

       function startSession(){
          global $database;
          session_start();
    
          $this->logged_in = $this->checkLogin();
          if(!$this->logged_in){
             $this->username = $_SESSION['username'] = GUEST_NAME;
             $this->userlevel = GUEST_LEVEL;
             $database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
          }
    
          else{
             $database->addActiveUser($this->username, $this->time);
          }
          $database->removeInactiveUsers();
          $database->removeInactiveGuests();
    
          if(isset($_SESSION['url'])){
             $this->referrer = $_SESSION['url'];
          }else{
             $this->referrer = "/";
          }
    
          $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
       }

     

    This finishes up your log in in another script:

       function procLogin(){
          global $session, $form;
          /* Login attempt */
          $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
          if($retval){
             header("Location: ".$session->referrer);
          }
          else{
             $_SESSION['value_array'] = $_POST;
             $_SESSION['error_array'] = $form->getErrorArray();
             header("Location: ".$session->referrer);
          }
       }

     

    In the first script I think (Not sure) these lines find out where your from and makes a value:

     

          if(isset($_SESSION['url'])){
             $this->referrer = $_SESSION['url'];
          }else{
             $this->referrer = "/";
          }

     

    And this probably has somthing to do with making you go there...  I am not familiar with ever using the header function...

    header("Location: ".$session->referrer);

     

     

    If I can I want to specify what page you go to after logging in...

     

    Thanx!

  3. So I made this code but nothing comes up...  No errors, connects to database fine...

     

    <html><head></head><body>
    <script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script>
    <script type="text/javascript">
    bkLib.onDomLoaded(function() {
    	new nicEditor({buttonList : ['bold','italic','underline','left','center','right','ol','ul','fontSize','fontFamily','indent','outdent','link','unlink','striketrhough','forecolor','bgcolor','upload','xhtml']}).panelInstance('content');
    });
    
    <?
    include ('../variables.php');
    
    $result = mysql_query("SELECT * FROM subjects WHERE id = '$id' LIMIT 0, 1");
    while($row = mysql_fetch_array($result)){$appear = $row['appear'];
    $media = $row['media'];
    $title = $row['title'];
    $content = $row['content'];
    $text = $row['text'];
    $numlinks = $row['numlinks'];
    $link1 = $row['link1'];
    $link2 = $row['link2'];
    $link3 = $row['link3'];
    $link4 = $row['link4'];
    $link5 = $row['link5'];
    $link1name = $row['link1name'];
    $link2name = $row['link2name'];
    $link3name = $row['link3name'];
    $link4name = $row['link4name'];
    $link5name = $row['link5name'];
    echo "<form method=post action=editsub.php?fire=change>";
    echo "Media type:<input type=text name='s_media' id='s_media' value='$media'><br>";
    echo "Title:<input type=text name='s_title' id='s_title' value='$title'><br>";
    echo "Content:<input type=text name='s_content' id='s_content' value='$content'><br>";
    
    echo "# of links:<input type=text name='s_title' id='s_title' value='$numlinks'><br>";	
    echo "Link1:<input type=text name='s_link1' id='s_link1' value='$link1'> Text:<input type=text name='s_link1' id='s_link1' value='$link1'><br>";
    echo "Link2:<input type=text name='s_link2' id='s_link2' value='$link2'> Text:<input type=text name='s_link2' id='s_link1' value='$link2'><br>";
    echo "Link3:<input type=text name='s_link3' id='s_link3' value='$link3'> Text:<input type=text name='s_link3' id='s_link1' value='$link3'><br>";
    echo "Link4:<input type=text name='s_link4' id='s_link4' value='$link4'> Text:<input type=text name='s_link4' id='s_link1' value='$link4'><br>";
    echo "Link5:<input type=text name='s_link5' id='s_link5' value='$link5'> Text:<input type=text name='s_link5' id='s_link1' value='$link5'><br>";
    echo "<input type=submit value=Update></form>";
    }
    
    ?>
    </body>
    </html>

     

    Whats really fishy is the info shows up fine in the page source....  Have a look:

     

    <html><head></head><body>
    <script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script>
    <script type="text/javascript">
    bkLib.onDomLoaded(function() {
    	new nicEditor({buttonList : ['bold','italic','underline','left','center','right','ol','ul','fontSize','fontFamily','indent','outdent','link','unlink','striketrhough','forecolor','bgcolor','upload','xhtml']}).panelInstance('content');
    });
    
    <form method=post action=editsub.php?fire=change>Media type:<input type=text name='s_media' id='s_media' value='text'><br>Title:<input type=text name='s_title' id='s_title' value='Sample Text'><br>Content:<input type=text name='s_content' id='s_content' value='fdghdhghfghgjghjghjghjghjghjghj ghjghn ghjgfjgh'><br># of links:<input type=text name='s_title' id='s_title' value='0'><br>Link1:<input type=text name='s_link1' id='s_link1' value=''> Text:<input type=text name='s_link1' id='s_link1' value=''><br>Link2:<input type=text name='s_link2' id='s_link2' value=''> Text:<input type=text name='s_link2' id='s_link1' value=''><br>Link3:<input type=text name='s_link3' id='s_link3' value=''> Text:<input type=text name='s_link3' id='s_link1' value=''><br>Link4:<input type=text name='s_link4' id='s_link4' value=''> Text:<input type=text name='s_link4' id='s_link1' value=''><br>Link5:<input type=text name='s_link5' id='s_link5' value=''> Text:<input type=text name='s_link5' id='s_link1' value=''><br><input type=submit value=Update></form></body>
    </html>

     

    Any ideas on why this is happening?

  4. So im making a php button to click (like an up or down arrow) to re-order a table but first I need a way to re-assign the primary key 'id' that is auto-increment.

     

    Heres a quick look at the table:

     

    idmediatitlecontenttext

    1photoSample item 1http://media-cdn.tripadvisor.com/media/photo-s/00/...Lorem ipsum dolor sit amet, consectetur adipiscing...

    2videoSample item 2media/himmler-poznan-large.flvIn quis nisi tellus, ut gravida elit. Sed aliquet,...

     

    So anyways see the id?  Its auto increment and primary...  I need a sql statement to switch the two numbers that I can run from php variables.

     

    Thank you.

  5. The following code works perfect but on the insert query the variable $id only rcords as 0.  I have no idea why becuase if I echo that variable it shows correctly...

     

    The $id is in a address.

     

    	if ($action == 'new_topic'){echo "<a href='forum.php?action=view'>GamePage101 Forums</a> >> <a href='$currentpage'>$forumname</a>";
    echo "<form action='$currentpage?action=new_topic&go=post' method='POST'>";
    echo "<br>Title:<br><input name='title' id='title' size='100'>";
    echo "<br><br><textarea name='content' id='content' style='width:700px;height:400px;'></textarea>";
    echo "<br><br><input type=submit value=Post></form>";
    	if ($go == 'post'){
    	if (!$title || !$content) {print "You must fill out all fields.";}
    	if ($session->username == 'Guest') {print "You must be signed in to post.";}
    	mysql_query ("INSERT INTO `bmvybfbk_website`.`forum` (`id2`, `title`, `content`, `writer`, `parent`)VALUES ('3', '$title', '$content', '$session->username', '$forum');");
    	echo "<b>Posted, <a href='$currentpage'>Click here</a></b>";}}

  6. Kk, I dont really have any notation but I used tabs and made my ifs the best I could to simplify it.

    By the way im not getting any error messages, just need help getting it to do what I want.

     

    <?php
    $con = mysql_connect("localhost","********","**********");
    if (!$con){die('Could not connect: ' . mysql_error());}
    mysql_select_db("bmvybfbk_website", $con);
    $result = mysql_query("SELECT * FROM templatesearch ORDER BY id");
    while($row = mysql_fetch_array($result))
    {
    $tid = $row['id'];
    $tprice = $row['price'];
    echo $row['tname'] . "<br>" . $row['preview'] . "<br>" . "Costs: " . $row['price'] . " points.	 ";
    echo "<a href='templatesearch.php?action=buy&temp=$tid'><font face='Papyrus' size='3'> Buy</font></a>";
    echo "<br><br>";
    	if ($action == buy) 
    	{
    	$result2 = mysql_query ("SELECT * FROM users WHERE username = '$session->username';");
    	while($row = mysql_fetch_array($result2)){
    	$totalpoints = $row['points'];}
    		if ($totalpoints >= $tprice){
    			$result2 = mysql_query ("SELECT * FROM items2 WHERE username = '$session->username';");
    			while($row = mysql_fetch_array($result2)){
    			$usedid = $row['name2'];
    				if ($usedid <> $tid){
    				mysql_query ("UPDATE users SET points = points - '$tprice' WHERE CONVERT( `users`.`username` USING utf8 ) = '$session->username' LIMIT 1;");
    				mysql_query ("INSERT INTO `items2` (`username`, `name2`, `id2`) VALUES ('$session->username', '$tid', '1');");
    				mysql_query ("UPDATE users SET tempid = $tid WHERE username = '$session->username' LIMIT 1;");
    				echo"  You bought it!  ";
    				?><meta http-equiv="refresh" content="1;url=/$session->username"><?
    				}
    				else {
    				echo "You already own it!";
    				?><meta http-equiv="refresh" content="1;url=templateowned.php"><?
    				}
    			}
    		}
    	}
    }
    ?>

     

    So whats happening here is at the very top of the code its spits out a few templates on the screen each with a buy button that adds ?action=buy&temp=$tid as defined above $tid is the id number of the template in the database.  Also defined (but not used yet) is the price.

     

    A bit further down it detects if action == buy then the next three lines grab the value of the users points they have at the moment.

     

    The next if statement decides if you have enough points with the >= (heres my first trouble point.  No matter how many points I have it comes out false.)  If that had passed it, the next three lines ask if you already own that template.  What it does is check the table 'items2' if there is already a table in there that has the colomb equal to your username,  if there is then it sets the value of the template owned into $usedid  (Im adding more to that later)

     

    The next if statement will be true if $usedid does not equal the template you are trying to buy. Then three actions hapen in the database.  First it will take away your points that you spent.  Next it inserts a row into items2 so in the future if will not let you but the same template twice.  Last it will set you to that template.

     

    So look to the bold text above to see where im stuck first...

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