Jump to content

taquitosensei

Members
  • Posts

    676
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by taquitosensei

  1. you have to surround it in quotes if it's text

        $sql .= "WHERE menu_name='" . $_GET['page']."'";

     

    Hello!

     

    I've been into mysql and encountered a problem, not serious one but it is bugging me.

     

    I can do dynamic page linking as follows, in short hand....

     

    echo "<a href=\"foo.php?page=" . $vastaus['id'] ."\">" . $vastaus['menu_name'] . "</a><br />";   // URL LINK

     

    function showcontent() {   /// FUNCTION TO DISPLAY CONTENT FROM SERVER.
            global $yhteys;
            $sql = "SELECT * ";
            $sql .= "FROM subjects ";
            $sql .= "WHERE id=" . $_GET['page'];
            $kysely= mysql_query($sql, $yhteys);
            $content = mysql_fetch_assoc($kysely) or die(mysql_error());
                
            echo strip_tags($content['content'], "<br><dt><dl>");

     

    Problem is... I can make this work with the ID, how ever, i want the URL bar saying it like this -> index.php?page=Info.

     

    This way it looks smarter (tells more to a user) and not just numbers as IDs.

     

    If i try to do the query like this...

     

    $sql = "SELECT * ";
            $sql .= "FROM subjects ";
            $sql .= "WHERE menu_name=" . $_GET['page'];

     

    It says unknown column "Info, Services". etc etc.

    It can only regonize the first column in each row. ( aka the id=number)

    I've tryed num_rows, fetch_array and fetch_assoc. I can't find a way to accomplish it.

     

     

    PLEASE i know this is simple, need help.

    Thanks in advance!

  2. With the way you have your query if the number of columns is different than the number of columns you're trying to insert it will fail. I usually specify my column names.

    insert into table(column1,column2,column3) values('value1','value2','value3')

    I am having trouble getting a simple form to submit data to a database.  I have followed an example in a PHP/MySQL book (Welling and Thomson) and created a simple form to update a DVD collection.  Right now I just have a form started and am just trying to get it to INSERT records into my database.  It is making a connection to the database, but it returns my Error stating that the record could not be added.  While all of my code is very basic,I am just trying to get an understanding as to how it is working... I have looked in MySQL through command prompt and the database exists, but records are not being added.  I can add records to the table through CMD prompt.  I will post my code for the database and my two php files for inserting records.

     

    Database:

     

    create database movie_info;

     

    use movie_info;

     

    create table movies

                    (movieid int unsigned not null auto_increment primary key,

                    title char(50) not null,

                    movieyear char(4) not null,

                    genre char(25) not null,

                    subgenre char(25),

                    director char(30),

                    actor1 char(30),

                    actor2 char(30),

                    actor3 char(30),

                    discs char(2),

                    season char(2),

                    comments char(200)

                    );

     

     

     

    Form:

     

     

     

    function input_form(){

    ?>

    <form method="post" action="insert_movie.php">

      <table bgcolor="#cccccc">

       <tr>

         <td colspan="2">Enter a new DVD:</td>

       <tr>

         <td>Title:</td>

         <td><input type="text" name="title"/></td></tr>

       <tr>

         <td>Year:</td>

         <td><input type="text" name="year"/></td></tr>

       <tr>

       <tr>

         <td>Genre:</td>

         <td><input type="text" name="genre"/></td></tr>

       <tr>

       <tr>

         <td>Sub-Genre:</td>

         <td><input type="text" name="subgenre"/></td></tr>

       <tr>

       <tr>

         <td>Director:</td>

         <td><input type="text" name="director"/></td></tr>

       <tr>

       <tr>

         <td>Actor:</td>

         <td><input type="text" name="actor1"/></td></tr>

       <tr>

       <tr>

         <td>Actor:</td>

         <td><input type="text" name="actor2"/></td></tr>

       <tr>

       <tr>

         <td>Actor:</td>

         <td><input type="text" name="actor3"/></td></tr>

       <tr>

       <tr>

         <td>Number of discs:</td>

         <td><input type="text" name="discs"/></td></tr>

       <tr>

       <tr>

         <td>Season:</td>

         <td><input type="text" name="season"/></td></tr>

       <tr>

       <tr>

         <td>Comments:</td>

         <td><input type="text" name="comments"/></td></tr>

       <tr>

      

         <td colspan="2" align="center">

         <input type="submit" value="Submit"/></td></tr>

       <tr>

     </table></form>

     <?php

     }

     

     

     

    and the INSERT code:

     

     

     

    <?php

                    require_once('movie_functions.php');

                    //require_once('db_functions.php');

                   

                    do_html_header('Moviebase');

                   

                    @$title = $_POST['title'];

                    @$year = $_POST['year'];

                    @$genre = $_POST['genre'];

                    @$subgenre = $_POST['subgenre'];

                    @$director = $_POST['director'];

                    @$actor1 = $_POST['actor1'];

                    @$actor2 = $_POST['actor2'];

                    @$actor3 = $_POST['actor3'];

                    @$discs = $_POST['discs'];

                    @$season = $_POST['season'];

                    @$comments = $_POST['comments'];

     

     if (!$title || !$year || !$genre) {

                    echo "You have not entered all of the required details. <br />"

                                     ."Please go back and try again.<br /><br />"

                                     ."<a href='movies.php'>Go Back</a>";

        exit;

                    }             

     

                    @$db = new mysqli('localhost', 'root', '********', 'movie_info');

       

                    if (mysqli_connect_errno()) {

                                    echo "Error: Could not connect to database.  Please try again later.";

                                    exit;

                                    }

                   

                    $query = "INSERT INTO movies VALUES (NULL, '".$title."', '".$year."', '".$genre."', '".$subgenre."',

                                                    '".$director."', '".$actor1."', '".$actor2."', '".$actor3."',

                                                    '".$discs."', '".$season."', '".$comments."')";

                                                   

                    $result = $db->query($query);

                   

                    if ($result)

                                    {

                                    echo $db->affected_rows." has been inserted into the database.";

                                    //input_form();

                                    }

                                    else

                                    {

                                    echo "An error has occurred. The item was not added.";

                                   

                    //for testing

                    echo "<br />Result: ".$result;

                                    echo "<br />".$title;

                                    echo "<br />".$year;

                                    echo "<br />".$genre;

                                    echo "<br />".$subgenre;

                                    echo "<br />".$director;

                                    echo "<br />".$actor1;

                                    echo "<br />".$actor2;

                                    echo "<br />".$actor3;

                                    echo "<br />".$discs;

                                    echo "<br />".$season;

                                    echo "<br />".$comments;

                                    //input_form();

                                    }

                   

                    $db->close();

                   

                    footer();

                   

                    ?>

     

    This all will return all variable values (except $result), so it seems like $result is empty.

     

    Any help in understanding this would be greatly appreciated, Thanks!

  3. where does $logOptions_id come from and is it an array? Because if $friendArray is an array you probably don't want to compare it to $logOptions_id.

    I'm currently in the middle of developing a privacy options features which will allow members of my site to toggle whether their information is visible to friends only or to the public.

    I'm doing this with PHP. When the privacy_opt variable is set to "fri" though, which means friends should only be able to see the content, the content isn't hidden to the public.

     

    I'm using the following PHP code.

    <?php
    $sqlo = "SELECT * FROM user_optionsc0nf WHERE id='$id' LIMIT 1";
    $opt_query = mysqli_query($db_conx, $sqlo);
    // ------- WHILE LOOP FOR GETTING THE MEMBER DATA ---------
    while($row = mysqli_fetch_array($opt_query, MYSQLI_ASSOC)){ 
        $privacy_opt = $row["privacy_opt"];
    }
    if ($privacy_opt == "fri" && $id != "$logOptions_id" && $friendArray == "$logOptions_id"){
     
    echo "Only this person's friend can see this information.";
    } else {
    echo $website, $youtube, $locationInfo;
    }
    ?>

     

    The $friendArray variable contains the users friends ID's in the form of 51, 100, 22, etc.

  4. Try this. You need to check if color is set and if it matches the color of the row you're on in the loop.

    (isset($_REQUEST['color']) && $_REQUEST['color']==$row['color']) ? 'checked="checked"' : ''
    

     

    Is there a way to make to checkbox react to the form value which is '.$color.' instead of the form name which is color. When I submit right now the code will check all of the colors fetched from the database but I want it to only check the individual color it clicked on. Here is my code.

      <?php
     
    $sidebar_color ="";
    $color_sql = mysql_query("SELECT *,COUNT(color) FROM products GROUP BY color ORDER BY color ASC");
    $coCount = mysql_num_rows($color_sql);
    if ($coCount > 0) {
    	while($row = mysql_fetch_array($color_sql)){
    		
    		$color = $row["color"];
    			
    		$sidebar_color .= '<div id="sidebar"><label><form action="?" method="REQUEST"><input type="checkbox" name="color" value="'.$color.'" onClick="submit(); return false" ' . (isset($_REQUEST['color']) ? 'checked="checked"' : '') . ' /><font size="-2"><a href="?color='.$color.'">'.$color.' ('.$row["COUNT(color)"].')</a></font></form></label></div>';
    	 }
     }
    ?>
    

    My page will look something like this

     

    checkbox black (3)

    checkbox yellow (5)

    checkbox white (9)

    ...

     

    All the pages are different and vary all the time so I can't individually write out the colors in the form which is why I use '.$color.'

     

    I hope this is a little more clear. Any ideas?

  5. do

    print_r($_POST); 
    

    to verify that your $tuturl is correct.

     

     

    I am having a problem with a free comment script I sourced here http://www.zimmertech.com/tutorials/php/25/comment-form-script-tutorial.php that I have implemented into my page here http://www.twowheelmotive.com

    I havent changed any of the PHP from the original script just the .css elements of it however when you submit the comment it takes you to the confirmation page but then continues to refresh that page instead of taking you back to the previous.

    I have been searching everywhere for the solution to make the refresh back to and cant find out a solution. I can not just enter the url because the script is called from multiple pages.

    Here is the submit comment php which I belive is giving me the problem.

     
    <?php
    //Please set the following variables for your mysql database:
    $db_hostname = "localhost";  //usually "localhost be default"
    $db_username = "*******";  //your user name
    $db_pass = "*******";  //the password for your user
    $db_name = "*******";  //the name of the database
    
    
    /*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS
    --------------------------------------*/
    // connect to database
    $dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ($db_name);
    
    
    $tuturl = $_POST["tuturl"];
    $tutid2 = $_POST["tutid2"];
    $name = $_POST["name"];
    $url = $_POST["url"];
    $email = $_POST["email"];
    $message = $_POST["message"];
    
    $sendcomment = mysql_query("INSERT INTO comments SET tutorialid='$tutid2', name='$name', url='$url', email='$email', comment='$message', date=now()");
    if($sendcomment){
    //header("Location: $tuturl");
    echo "<h1>Submission Successful</h1>";
    echo "Your comment has been submitted.  You will now be redirected back to the last page you visited.  Thanks!";
    echo "<meta http-equiv='refresh' content='2;URL=$tuturl'>";
    } else {
    echo "There was an error with the submission. ";
    }
    
    ?>
    

    As I understand this is the line that is calling for the refresh and getting passed the info for which page the comment was sent from thru the $tuturl variable however, I doesn't seem to be working.

    echo "<meta http-equiv='refresh' content='2;URL=$tuturl'>";
    

    Any help would be greatly appreciated!

     

  6. How are you generating your form? You can always create an array of the names. Then loop through and check for them.

    $radio_array=array("radio1","radio2","etc");
    $selected=False;  
    foreach($radio_array as $radio) { 
       if(isset($_REQUEST[$radio] && $_REQUEST['radio'])) { $selected=True; }
    }
    
    if($selected) { 
       // do whatever you need to do here.
    }
    
  7. for some reason instead of parsing the php it's convert the < to %3C    Need to see what's at the top of the page.

     <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform">
            <table width="100%">
              <tr><td>Username:</td><td> <input class="text" name="username" type="text"  /></td></tr>
              <tr><td>Password:</td><td> <input class="text" name="password" type="password" /></td></tr>
              <tr><td colspan="2" align="center"> <input name="submit" type="submit" value="Submit" /> </td></tr>
            </table> 
          </form>

     

    if (isset($_POST['submit'])){
     // Get user input
     $username = isset($_POST['username']) ? $_POST['username'] : '';
     $password = isset($_POST['password']) ? $_POST['password'] : '';
           
     // Try to login the user
     $error = loginUser($username,$password);
    }

     

     

    function loginUser($user,$pass){
     $errorText = '';
     $validUser = false;
     
     // Check user existance 
     $pfile = fopen("userpwd.txt","r");
        rewind($pfile);

        while (!feof($pfile)) {
            $line = fgets($pfile);
            $tmp = explode(':', $line);
            if ($tmp[0] == $user) {
                // User exists, check password
                if (trim($tmp[2]) == trim(md5($pass))){
                 $validUser= true;
                 $_SESSION['userName'] = $user;
                }
                break;
            }
        }
        fclose($pfile);

        if ($validUser != true) $errorText = "Invalid username or password!";
       
        if ($validUser == true) $_SESSION['validUser'] = true;
        else $_SESSION['validUser'] = false;
     
     return $errorText; 
    }

     

     

    Can you please explain why my java scrpit is not working for this above code and also i get error in the url as %3C?php echo $_SERVER['PHP_SELF']; if i remove this and redirect to some other php page it ll work but java scrpit does not work , is there any thing to change to run the above in linux , this code works for windows server i m facing this in linux and i am using PHP5 version  :confused: 

  8. You could try this

     

    $resulta=($result<1)?0:$result;

     

    Hi Zane,

     

    Thanks for helping, I don't think this will not work for what I am trying to do. I may have been too vague.  All the data comes from 1 table except the date range for the where statement, it comes from its own table.  I need to display the zero if the count is less than 1.  Could I use some sort of an if then else statement.  

     

    ie: $resulta=if $result<1 then="0" else=$result

     

    The final table should look like the attached photo:

     

    Thanks again for your assistance.

  9. What happens if you run your ffmpeg command on the command line? That would be the first thing to check. If that works then it's probably an issue with permissions for php creating the file.

     

    Hi Requinix,

     

    Thanks for the pointer. I've had a look and I think it can do what I need. I've installed it as a PHP extension but I'm having a little trouble making it work.

    What I'm doing is as follows:

    echo shell_exec("ffmpeg -ss 90 -t 30 -y -i inputfile.mp3 -acodec copy outputfile.mp3");

     

    So I'm selecting a start point of 90 seconds and a time (duration) of 30 seconds. I'm also telling it to copy the file without changing the bitrate of the file, which is what the -acodec parameter is for. However, it's not creating the output file. Can anyone see anything wrong with the above code, or suggest why it might not be creating the output file?

     

    Thanks,

     

    Willo

  10. Var_hook is already formatted correctly (imploded). So the SQL correctly creates the number of arrays. My problem is that I can't make the arrays contain data? E.g. when I print the first series, it does not contain the data content for that series?

    Then you need to explode it before you do this.

     

    foreach ($var_hook as $id) { 

        $series[$id] = array();

    } 

     

    It's a string because you imploded it before your sql.

  11. This will substract two dates and give you the difference in hours/minutes. Like DaveyK said if you add 7 days to a timestamp then subtract the original timestamp from it. You will always get exactly 7 days.

    $diff = strtotime($timestamp2) - strtotime($timestamp1);
    $hours = floor($diff / 3600);
    $diff %= 3600;
    $minutes = floor($diff / 60);
    

     

    hi guys, 

     

    Im trying to calculate number of days and time passed a time stamp but I always get 0 do you know why? 

     

    Am I making funny mistake again?

            date_bought= "2013-06-02 15:57:04";
    	$add_days = 7;
            $date= date('Y-m-d',strtotime( $date_bought) + (24*3600*$add_days));
            $result_date= $date - $date_bought;
    	echo"$result_date";
    
  12.  

     

    Hey, I'm very new to PHP and I'm trying to create a form that posts data to a PHP document. Here's what I have so far:

     

    form.html:

     

    <form action="phpdoc.php" method="post"> 
    <input type="checkbox" name="fun" value="yes" />Fun
    <input type="checkbox" name="ent" value="yes" />Entertaining
    <input type="checkbox" name="inf" value="yes" />Informative <br>
    <input type="submit" name="formSubmit" value="Submit" />
    </form>

     

    phpdoc.php:

     

    <?php 
     
    if(isset($_POST['fun']) && 
       $_POST['fun'] == 'yes') 
    {
        print "Try fdajkfda.";
    }
    else
    {
        print "You aren't fun.";
    }    
     
    ?>
     
    The objective is to create a form with checkboxes, and so far, if you select the "fun" checkbox and submit the form, it will send the data to the phpdoc.php and the form will then print something depending on your selection. The problem is, the form isn't printing anything at all. This is a really amateur problem so I thank you for whatever help you can give  :happy-04:

     

    You can do print_r($_REQUEST);  at the top of phpdoc.php to see what kind of values are actually being posted. If you do that you should be able to see right away why this isn't working.

  13. It looks like you're not selecting the size.

     

    SELECT  Food,Calories FROM food order by Food

     

     

    i have a table in mysql/phpmyadmin

    Food, Size, Calories

    i concatenated 2 values and its working successfully in the drop down list according to this code:

     
    <?PHP
      $query = "SELECT  Food,Calories FROM food order by Food";
      $result = mysqli_query($con,$query);
    while($row = mysqli_fetch_assoc($result)) {
        echo ("<option VALUE=\"".$row['Food']."\" " . ($food == $row['Food'] ? " selected" : "") . ">".$row['Food'].' - '.$row['Calories']."</option>");
      }
    ?>
    

    i need to show the Size too!!
    and this code isnt working any help??

     
    while($row = mysqli_fetch_assoc($result)) {
        echo ("<option VALUE=\"".$row['Food']."\" " . ($food == $row['Food'] ? " selected" : "") . ">".$row['Food'].' - ' .$row['Size']. ' - '.$row['Calories']."</option>");
      }
    
  14. How permanent do you want it? If it's permanent permanent I would store it in a database somewhere. If it's just somewhat permanent, since you're already using jQuery, use jQuery.ajax to post to server and store a session variable. Then use that session variable to determine whether it's dead or not when initially loading the page.

    I have a table displaying database data and there's a "Dead" button next to each row for users to click when the information in that row is dead. When the button is clicked the info in the row is crossed out. Now this works, but the change isnt permanent. When I refresh the page, the row is no longer crossed out. I think I have to set cookies.. ? but I am unsure on how to do this. Are there any tutorials or something I can watch on this. Just looking at http://php.net/manual/en/function.setcookie.php is not helping. I'm reading it and my brain is like.. what?!?! How do I apply that to what I want to do?

     

    Here's my code

    php

    <?php while($row = $data->fetch_assoc()) { ?>
    <tr>
    
    <td><?php echo $row['title']; ?> </td>
    <td><?php echo  $row['requester']; ?></td>
    <td><?php echo $row['reward']; ?></td>
    <td><?php echo $row['qual']; ?></td>
    <td><?php echo $row['time']; ?></td>
    <td><?php echo $row['category']; ?></td>
    <td><a href="<?php $row['link']; ?>"><button class="btn btn-mini btn-primary" type="button">Do This Hit</button></a></td>
    <td><button class="btn btn-danger btn-mini dead" type="button">Dead</button></td>
    
    </tr>
    <?php } ?>
    

    and here's my javascript

    $('table').on('click','.dead',function(){
    	
    	
              $(this).parent().siblings().css({textDecoration: 'line-through'});
        });
        
    

    I'm just totally stuck right now, so any help is appreciated. Also, if cookies arent the way to go, please feel free to suggest other ways.

     

    Thanks.

  15. Hi,

     

    Thanks for the reply, but the count distinct is only counting distinct contactid's not accountid's so it shouldnt affect the query?

    It does effect the query. Because in first query the value you're getting is ''   The second query you're getting a number.

  16. As far as I know UNION removes duplicate rows, so the count(distinct contactid) in the second part would make it not a distinct row. So in your query you're getting everything, then everything with activity in the last week.

     

     

     

    Hi All,

     

    I have been struggling with what seems a simple enough query.

    I have three tables, Accounts, Contacts & Activities.

    Everytime an Activity is logged it logs the AccountID, Contact Subject, TimeDate.

     

    I query the Activities table to show me all the activity count from the previous week for each AccountID.

    I use:

    select
    accounts.account as Account,
    count(distinct activities.contactid) as Users,
    from accounts, activities
    where activities.accountid=accounts.accountid
    AND completeddate >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
    AND completeddate < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
    group by accounts.account asc;

    The result is something like This:

     

    Account  Users

    ACME Ltd  4

    Warner Bros  6

    RBS   9

    etc..

     

    The activities table has baout 20 million rows and this runs in about 20 seconds.

     

    However, I want a comprehensive list.

    I want to combine the results with a list of AccountID's that havent had any activity for that month.

     

     

    Account  Users

    ACME Ltd  4

    Warner Bros  6

    RBS   9

    Microsoft 0  or NULL

    etc...

     

    i have tried to UNION like this:

    select Account, '' from Accounts
    UNION
    select
    accounts.account as Account,
    count(distinct activities.contactid) as Users
    from accounts, activities
    where activities.accountid=accounts.accountid
    AND completeddate >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
    AND completeddate < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
    group by accounts.account asc;

    From what i understand about UNION is that it should return a unique list (without duplicates).

    But what i get is a list of aprox 1400 accounts with when I only have approx 900 Accounts.

     

    I have tried LEFT OUTER JOIN but this just seemed to run forever ( i killed it after 2 hours)

     

    Does anyone have any suggestions on what I can try?

     

     

    Thanks

    Dark

  17. use a double $$

    $$row[0]="n";
    

     

     

    Hello everyone,

     

    This seems that it should be a fairly easy thing to do, but I'm having some difficulty.  What I'm trying to query a list of items from my database, and then for each result I get, I want to make it a variable itself.  Here's what I have:

    <?php
    
    include("../dbconnect.inc.php");
    
    $result = mysql_query("SELECT `prodid` FROM products") or die (mysql_error());
    
    while ($row = mysql_fetch_row($result)) {
    
    	$prodid = $row[0];
    	
    	// If the result of $prodid is "chair," I would like to create a variable named $chair and set its value to "n" ($chair = "n").  I
    	// would like to do this for each result.
    
    }
    
    ?>
    
  18. Also to make this cleaner you could do something like this

    
    $fields=array("objava","vpr01","vpr03","etc");
    foreach($fields as $field) { 
      if(isset($_POST[$field])) { fwrite($fh, $_POST[$field]."\r\n"); }
    }
     
    

     

    Hey! I need help with this code. I'm trying to get write every answere to be in other line when I get it to my file. SO where do I have to put \n or whatever to get every post in new line. 

    Im in hurry so can you please help me quic.

    if (isset($_POST["objava"]))
     fwrite($fh,$_POST["objava"]);
      if (isset($_POST["vpr01"]))
     fwrite($fh,$_POST["vpr01"]);
    	if (isset($_POST["vpr02"])) 	
     fwrite($fh,$_POST["vpr02"]);
    
    		if (isset($_POST["vpr03"])) 	
     fwrite($fh,$_POST["vpr03"]); and so on....
    
  19. pear is a set of php files. If your web server can parse php files then you can use pear. It's just not in the default location for the operating system. Just upload the "pear" folder from your local machine to the web server. Then set the include path. Then call the files as normal.

  20. why can't you use pear? You should be able to just put your pear directory tree in an includes folder and include the files you need. For example if on your local system pear is in /usr/share/pear  or something like that, and your web root is /var/www/vhosts/yourwebsite.com    put the pear folder in /var/www/vhosts/yourwebsite.com/includes/    then set the include path

    ini_set("include_path",$_SERVER['DOCUMENT_ROOT']."/includes/".PATH_SEPARATOR.$_SERVER['DOCUMENT_ROOT']."/includes/pear/".APATH_SEPARATOR.ini_get("include_path"));
    

     

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