Jump to content

[SOLVED] PHP & SQL Error


Shinee

Recommended Posts

I've been working on this script for a while, I've searched for answers, and I finally gave up. Therefore I registered to this site to get me some answers. Here's my code. It's for a profiling system. (Note: 'removed' was the replacing message I used to cover up my real MySQL data.)

 

<?php

$connection = mysql_connect("removed","removed","removed");
mysql_select_db("removed", $connection);

if(isset($_GET['search']))
{
    $search = explode(" ",$_GET['search']);
    $str = "SELECT * FROM `removed` WHERE firstname='{$search[0]}'";
    if(count($search)>1)
    {
        $str .= " AND lastname='{$search[1]}'";
    }
}
else if(isset($_GET['add']))
{
    $firstname = $_GET['firstname'];
    $lastname = $_GET['lastname'];
    $color = $_GET['color'];
    $name = $_GET['name'];
    $sex = $_GET['sex'];
    $status = $_GET['status'];
    $species = $_GET['species'];
    $thoughts = $_GET['thoughts'];
    $orientation = $_GET['orientation'];
    $comments = $_GET['comments'];
    $password = $_GET['password'];
    $double = "SELECT * FROM `removed` WHERE firstname='{$firstname}'";
    if(double)
    {
        if($password=="toads")
        {
            echo "Preferences updated successfully.";
            mysql_query("UPDATE `removed` SET firstname='{$firstname}',lastname='{$lastname}',color='{$color}',name='{$name}',sex='{$sex}',status='{$status}',species='{$species}',thoughts='{$thoughts}',orientation='{$orientation}',comments='{$comments}'");
        }
    }
    else
    {
        if($password=="toads")
        {
            echo "Preferences saved successfully.";
            mysql_query("INSERT INTO `removed` SET firstname='{$firstname}',lastname='{$lastname}',color='{$color}',name='{$name}',sex='{$sex}',status='{$status}',species='{$species}',thoughts='{$thoughts}',orientation='{$orientation}',comments='{$comments}'");
        }
    }
}
else $str ="SELECT * FROM `removed` ORDER BY firstname";

if(!empty($str))
{
    $query = mysql_query($str);
    while($r=mysql_fetch_array($query))
    {
        if($count)
        {
            echo "<br />";
        }
        echo "{$r['firstname']} {$r['lastname']} {$r['color']} {$r['name']} {$r['sex']} {$r['status']} {$r['species']} {$r['thoughts']} {$r['orientation']} {$r['comments']}";
        $count++;
    }
}

?>

 

(edited by kenrbnsn to change tags to


tags)

Link to comment
Share on other sites

Your organization is rather hectic...

 

From the get go, line 29:

if(double)

 

shouldn't that be if($double) ?

 

Also, double is never used... you give the variable a string value.. then ask if it's true (it is), then you don't do anything with it.. were you meaning to query the db first?

Link to comment
Share on other sites

Well, I assume you are wanting it to query $double, and then do something based on the result of that query?

 

Also, if I'm going to mess with this, I'll probably reorganize your code...these elseifs frighten me.

But it will be more readable.. and i'll try to explain it... k?

 

Please confirm these things:

1) if nothing is set for $_GET, then it will display rows of data from your table?

2) "if double" will update only the row where $_POST[firstname] == $firstname in database

3) Otherwise from 2 , it will create a new record..

4) The update/add feature are protected by a password, and if the password doesn't match, it fails?

 

And FYI timeframe on this is "ill get to it in about 1 hr", time permitting..

Link to comment
Share on other sites

@ xtopolis; Alright. $double checks if there is already a query for that first name, if so, it updates the other data posted. If nothing is set it does display rows of data. And $double is only for that row/user, yes. So if there is no data from the $double (If there is not a row/user to update.) it creates one. The update and add are password protected, if the password is wrong then the script doesn't respond. Thanks, I started scripting LSL (Linden Scripting Language) 3 years ago and got really good, that's where a lot of my formatting came from.  :-X

Link to comment
Share on other sites

awesome, i'll check this out in about 30 mins probably.

 

I tried to learn LSL back about 1-2 years ago, but at the time there weren't any good tutorials I could find, and I'm not very good at 3D modeling either.. so I gave up on SL.  Hope you're making bank on script though lol :P  Maybe you can teach me a bit sometime ^^

Link to comment
Share on other sites

@ xtopolis; Haha that's awesome. It's always good to hear I'm not alone when it comes to Second Life. :P I'd also be glad to teach you a few things since you're helping me with this. :D And, I've done custom scripting since the time I began, I even have a gadget/tool type thing. In fact, the PHP script I'm needing help on is for in-game profiling, like advanced Second Life profiles, for my gadget/tool users. The in-game script does all the posting. My in-game name is Alba Ashby, or Organized Republic. Either one is checked several times a week. Second Life is addicting when you're good at it. ;D

Link to comment
Share on other sites

@ xtopolis; I'll send you my executed SQL Query. It's basically all strings. The line(s) of LSL I use is also listed below. (See the llHTTPRequest().)

 

 

LSL;

default
{
    link_message(integer sender_num, integer num, string str, key id)
    {
        if(num==10)
        {
            if(str=="save")
            {
                sound();
                llMessageLinked(LINK_SET,8,"Saving preferences.",NULL_KEY);
                pref=TRUE;
                list t=llParseString2List(llKey2Name(llGetOwner()),[" "],[]);
                text="&name="+t_name+"&sex="+t_sex+"&status="+t_status+"&species="+t_species+"&thoughts="+t_thoughts+"&orientation="+t_orientation+"&comments="+t_comments;
                string queryid=llHTTPRequest("http://shineelab.com/mg/mgprefdba.php?add=1&password=*removed*&firstname="+llList2String(t,0)+"&lastname="+llList2String(t,1)+"&color="+(string)c_color+(string)text,[HTTP_METHOD,"POST"],"");
                llSay(0,"http://shineelab.com/mg/mgprefdba.php?add=1&password=*removed*&firstname="+llList2String(t,0)+"&lastname="+llList2String(t,1)+"&color="+(string)c_color+(string)text);
            }
            if(str=="load")
            {
                sound();
                llMessageLinked(LINK_SET,8,"Loading preferences.",NULL_KEY);
                pref=TRUE;
                load=TRUE;
                string queryid=llHTTPRequest("http://shineelab.com/mg/mgprefdba.php?search="+llKey2Name(llGetOwner()),[HTTP_METHOD,"GET"],"");
            }
        }
    }
}

 

SQL Query;

-- phpMyAdmin SQL Dump
-- version 2.11.0
-- http://www.phpmyadmin.net
--
-- Host: mysql.mesgahosters.com
-- Password: ****
-- Generation Time: Oct 07, 2008 at 09:43 PM
-- Server version: 3.23.32
-- PHP Version: 4.4.8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `shinee1_slkeys`
--

-- --------------------------------------------------------

--
-- Table structure for table `multigadgetpref`
--

CREATE TABLE `multigadgetpref` (
  `firstname` varchar(255) NOT NULL,
  `lastname` varchar(255) NOT NULL,
  `color` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `sex` varchar(255) NOT NULL,
  `status` varchar(255) NOT NULL,
  `species` varchar(255) NOT NULL,
  `thoughts` varchar(255) NOT NULL,
  `orientation` varchar(255) NOT NULL,
  `comments` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

(edited by kenrbnsn to add


tags)

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.