Jump to content

nbbcj

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Posts posted by nbbcj

  1. hi there PFMaBiSmAd

     

    i read over the info and links you posted but im still running in to probs could you take a look at my new code and correct me please

    ( i started with just 2 images thumbnail,image1 for testing and when its running ok add the other image2,3,4 code )

    FYI the info is going in to the db but not the thumbnail name or the image1 name and

    it dont seem to be uploading the thumbnail's to thum folder but is uploading the image1 to the images folder both folders have 777 chmod.

     

    im hoping iv got at least some of the code right like i said be for im a noob lol THANK YOU for any help.

     

    the new add.php

    <?php
    error_reporting(E_ALL);
    include ("../includes/db_config.php");
    /////
    // Connects to your Database
    $con = mysql_connect("$db_hostname", "$db_username", "$db_password") or die(mysql_error()) ;
    @mysql_select_db("$db_database") or die(mysql_error()) ;
    ///////
    if($_SERVER['REQUEST_METHOD']=='POST'){
    
    foreach ($_FILES["thumbnail"]["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["thumbnail"]["tmp_name"][$key];
            $name = $_FILES["thumbnail"]["name"][$key];
            move_uploaded_file($tmp_name, "../thum/$name");
        }
    }
    ///
    foreach ($_FILES["image1"]["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["image1"]["tmp_name"][$key];
            $name = $_FILES["image1"]["name"][$key];
            move_uploaded_file($tmp_name, "../images/$name");
        }
    }
    
    }
    ////
    $sql="INSERT INTO $db_table (pro_name, thumbnail, short_details, full_details, cat, image1, image2, image3, image4)
    VALUES
    ('$_POST[pro_name]','$_POST[thumbnail]','$_POST[short_details]','$_POST[full_details]','$_POST[cat]','$_POST[image1]','$_POST[image2]','$_POST[image3]','$_POST[image4]')";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con)
    ?>

     

    and the new form page

     

    <html>
    <body>
    
    <form method="post" action="add.php" enctype="multipart/form-data">
    pro name <input type="text" name="pro_name"/><p>
    short details <input type="text" name="short_details"/><p>
    full_details <input type="text" name="full_details"/><p>
    cat <input type="text" name="cat"/><p>
    
    <input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
    thumbnail:  <input name="thumbnail[]" type="file" /><p>
    
    <input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
    image1  <input name="image1[]" type="file" /><p>
    
    <input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
    image2  <input name="image2[]" type="file" /><p>
    
    <input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
    image3  <input name="image3[]" type="file" /><p>
    
      <input type="hidden" name="MAX_FILE_SIZE" value="1029120" />
    image4  <input name="image4[]" type="file" /><p>
    
    <input TYPE="submit" name="upload" title="Add data to the Database" value="Add"/>
              </form>
    </body>
    </html>

     

    also im getting this error

     

    Warning: Invalid argument supplied for foreach() in /customers/0/8/d/nbbcj.co.uk/httpd.www/project/backend/add.php on line 11 Notice: Undefined index: thumbnail in /customers/0/8/d/nbbcj.co.uk/httpd.www/project/backend/add.php on line 31 Notice: Undefined index: image1 in /customers/0/8/d/nbbcj.co.uk/httpd.www/project/backend/add.php on line 31 Notice: Undefined index: image2 in /customers/0/8/d/nbbcj.co.uk/httpd.www/project/backend/add.php on line 31 Notice: Undefined index: image3 in /customers/0/8/d/nbbcj.co.uk/httpd.www/project/backend/add.php on line 31 Notice: Undefined index: image4 in /customers/0/8/d/nbbcj.co.uk/httpd.www/project/backend/add.php on line 31 1 record added

     

    i have tryed what i can but no look 

  2. hi all

     

    i need a script that will allow me upload images to 2 dif folders on my server and then add the info to my database along with some other form data.

    iv been looking all over for code or scripts for days now and have been playing with cut and copyed code but no look

     

    again any help i will be greatful for as im a noob to php but al learning quick

     

    here is my html form

     

     
    <html>
    <body>
    
    <form action="add.php" method="post">
    Project Name: <input type="text" name="pro_name" /><br>
    Thumbnail: <input type="file" name="thumbnail" /><br> ////// this image to ../thum
    Short Details: <input type="text" name="short_details" /><br>
    Full Details: <input type="text" name="full_details" /><br>
    Category: <input type="text" name="cat" /><br>
    Image1: <input type="file" name="image1" /><br>//// and image1,2,3,4 to ../images
    Image2: <input type="file" name="image2" /><br>
    Image3: <input type="file" name="image3" /><br>
    Image4: <input type="file" name="image4" /><br>
    <input type="submit" />
    </form></body></html>

     

    here is my code for add.php witch only adds the info to the DB

     

    <?php
    error_reporting(E_ALL);
    
    include ("../includes/db_config.php");
    
    $con = mysql_connect($db_hostname,$db_username,$db_password);
    @mysql_select_db($db_database) or die( "Unable to select database");
    
    $sql="INSERT INTO $db_table (pro_name, thumbnail, short_details, full_details, cat, image1, image2, image3, image4)
    VALUES
    ('$_POST[pro_name]','$_POST[thumbnail]','$_POST[short_details]','$_POST[full_details]','$_POST[cat]','$_POST[image1]','$_POST[image2]','$_POST[image3]','$_POST[image4]')";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con)
    
    
    ?>

     

  3. hay all

     

    here is my prob i have a page that show images and info from a db shows ok in a 3x3 grid but now i want to have a list at the side to filter the query to only show the enters with the right cat filter

     

    ie index.php?cat=cars to only show the images of cars from the db

     

    i have a field called cat in my db i have tryed this

     

    $query="SELECT * FROM `shaun` WHERE `cat` ='".$_GET['cat']."'";

    as this worked with an other page i have but errors this time  and no display on page

     

    or can i do it where if the val is set in the url (ie. ?cat=filter) then run the above query if no val is sent via the url then to run a basic query

    $query="SELECT * FROM `shaun`"

     

    here is my page code

    <table border="1" ALIGN="center">
    <tr>
    	<td>Filters<p><a href="?cat=filter1">•Filter1</a><br>•	Filter2<br>•Filter3</td>
    	<td><table cellspacing="3" cellpadding="3">
    <?php
    error_reporting(E_ALL);
    
    include ("includes/db_config.php");
    
    mysql_connect($db_hostname,$db_username,$db_password);
    @mysql_select_db($db_database) or die( "Unable to select database");
    $query="SELECT * FROM `shaun`";
    
    $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); 
    if($result && mysql_num_rows($result) > 0)
    {
        $i = 0;
        $max_columns = 3;
        while($row = mysql_fetch_array($result))        
       {
           // make the variables easy to deal with
           extract($row);
    
           // open row if counter is zero
           if($i == 0)
              echo "<tr>";
    
           // make sure we have a valid product
           if($pro_name != "" && $pro_name != null)
              echo "<td><a href=\"detalis.php?id=$id\"><img src=\"/project/thum/$thumbnail\" alt=\"$thumbnail\" height=\"150\" width=\"150\" /><br>$pro_name<br></a>$short_details $cat</td>";
        
           // increment counter - if counter = max columns, reset counter and close row
           if(++$i == $max_columns) 
           {
               echo "</tr>";
               $i=0;
           }  // end if 
       } // end while
    } // end if results
    
    // clean up table - makes your code valid!
    if($i > 0){    for($j=$i; $j<$max_columns;$j++) echo "<td> </td>";   echo '</tr>';} ?></table></td>
    </tr>
    </table>
    

     

    Any help i would be greatful

     

     

    nbbcj

     

    >>>>>>>. edit the address in question is http://nbbcj.co.uk/project/

  4. Alll Sorted now thank u every one did a bit of fiddling and it works now part form one thing

     

    If you could help again please

     

    i can get the dropdown box working but not when i change page it drops the cat selection and no results.

     

    I got the ddb to work by changing.....

    // get the info from the db 

    $sql = "SELECT * FROM penapps LIMIT $offset, $rowsperpage";

    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

     

    to

     

    // get the info from the db

    $cat = mysql_real_escape_string($_POST['D1']);

    $sql = "SELECT * FROM penapps WHERE `category` = '$cat' LIMIT $offset, $rowsperpage";

    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

     

    Witch make this work

     

    <form method="POST" action="test1.php">

    <select size="1" name="D1">

    <option selected value="audio">audio</option>

    <option value="internet">internet</option>

    <option value="file man">file man</option>

    <option value="games">games</option>

    </select><input type="submit" value="Go Get It"></p>

    </form>

     

    But any help on getting the ddm selection to stay after page change may be by adding $cat to this

     

    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";

      // get previous page num

      $prevpage = $currentpage - 1;

      // show < link to go back to 1 page

      echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";

     

    thanks in advance :)

  5. dumb question, but did you change the info you need to supply in

     

    $conn = mysql_connect('conn','user','pass') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('db name',$conn) or trigger_error("SQL", E_USER_ERROR);
    

     

    yer changed the conn,user,and pass and db name t there proper ones :P

     

  6. Thanks premiso that link was just what im looking for the only prob i have now is putting it with my code

     

    im getting this error Fatal error: SQL in /customers/nbbcj.co.uk/nbbcj.co.uk/httpd.www/testd/test.php on line 10

    with this code ###### i wanted to leave the $cat bit in so i can use the dropdown menu i have alredy on page

     

     

    <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?>
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>test page one</title>
    </head>
    
    <body>
    Welcome to the test page #
    <form method="POST" action="test.php">
    <select size="1" name="D1">
    <option value="audio">audio</option>
    <option selected value="internet">internet</option>
    <option value="file man">file man</option>
    <option value="games">games</option>
    </select><input type="submit" value="Go Get It"></p>
    </form>
    Ues the drop down box to select the cat you want 
    <?php
    //thanks to Crayon Violent for the pagination code 
    // database connection info
    $conn = mysql_connect('conn','user','pass') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('db name',$conn) or trigger_error("SQL", E_USER_ERROR);
    
    // find out how many rows are in the table 
    $cat = mysql_real_escape_string($_POST['D1']); 
    $sql = "SELECT COUNT(*) FROM penapps WHERE `cat` = '$cat' LIMIT 10";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];
    
    // number of rows to show per page
    $rowsperpage = 10;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);
    
    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       // cast var as int
       $currentpage = (int) $_GET['currentpage'];
    } else {
       // default page num
       $currentpage = 1;
    } // end if
    
    // if current page is greater than total pages...
    if ($currentpage > $totalpages) {
       // set current page to last page
       $currentpage = $totalpages;
    } // end if
    // if current page is less than first page...
    if ($currentpage < 1) {
       // set current page to first page
       $currentpage = 1;
    } // end if
    
    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage;
    
    // get the info from the db 
    $sql = "SELECT id, number FROM numbers LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    
    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) {
       // echo data
       echo $list['id'] . " : " . $list['number'] . "<br />";
    } // end while
    
    /******  build the pagination links ******/
    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
                     
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
    } // end if
    /****** end build pagination links ******/
    ?>
    ########################################
    i also tryed it like this 
    
    // find out how many rows are in the table 
    // $cat = mysql_real_escape_string($_POST['D1']); 
    $sql = "SELECT COUNT(*) FROM penapps ";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];

    but just get blank page :(

     

    please help its driving me mad lol

     

    thanks in advance

    kaine

  7. hi there alll newbie here lol

     

    just needed help with the code for the next page of results ?

     

    IE i have say 30 results returned from a sql query but only want to show ten at a time i no how to limit the result with the LIMIT 10 but how do i get it to put link show the other ten and so on.

    the code i have is here at the bottom of page http://www.phpfreaks.com/forums/index.php/topic,307971.0.html

     

    thanks in advance for any help

     

    kaine

  8. WOOP WOOP WOOP

     

    It works now THANK YOU so much  :D so simple a little bit of code can change every thing

    Ill enter the code at end of post case it can help some one else.

     

    this bit of code $cat = mysql_real_escape_string($_POST['D1'])); is what i was on bout with )); at the end it didnt work but like this ); it works for me.

     

    THANK YOU!!!! again thorpe your a god among men  O0

    Heres the code

    ###########################################################

    <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?>

    <html>

     

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

    <title>test page one</title>

    </head>

     

    <body>

    Welcome to the test page #

    <form method="POST" action="test1.php">

    <select size="1" name="D1">

    <option value="audio">audio</option>

    <option value="internet">internet</option>

    <option value="file man">file man</option>

    <option value="games">games</option>

    </select><input type="submit" value="Submit"></p>

    </form>

     

    <?

    $db_host = '*******';

    $db_user = '******';

    $db_pwd = '******';

    $database = '*****';

    $table = '*********';

     

    if (!mysql_connect($db_host, $db_user, $db_pwd))

        die("Can't connect to database");

     

    if (!mysql_select_db($database))

        die("Can't select database");

     

    // sending query

    $cat = mysql_real_escape_string($_POST['D1']);

    $result = mysql_query("SELECT * FROM {$table} WHERE `cat` = '$cat' LIMIT 10 ");

     

    if (!$result) {

        die("Query to show fields from table failed");

    }

     

    $fields_num = mysql_num_fields($result);

     

    //echo "<h1>Table: {$table}</h1>";

    echo "<table border='1' width='100%'><tr>";

    // printing table headers

    for($i=0; $i<$fields_num; $i++)

    {

        $field = mysql_fetch_field($result);

        //echo "<td>{$field->name}</td>";

    }

    echo "</tr>\n";

    // printing table rows

    while($row = mysql_fetch_row($result))

    {

        echo "<tr>";

     

        // $row is array... foreach( .. ) puts every element

        // of $row to $cell variable

        foreach($row as $cell)

            echo "<td>$cell</td>";

     

        echo "</tr>\n";

    }

    mysql_free_result($result);

    ?>

     

     

    </body>

     

    </html>

     

  9. Hi again sorry im such a newbie

     

    could u take a look at this and correct as needed thank u in advance this is hard think i need to read more books lol

     

    <html>

     

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

    <title>test page one</title>

    </head>

     

    <body>

    Welcome to the test page

    <form method="POST" action="test1.php">

    <select size="1" name="D1">

    <option value="audio">audio</option>

    <option value="internet">internet</option>

    <option value="file man">file man</option>

    <option value="games">games</option>

    </select><input type="submit" value="Submit"></p>

    </form>

     

    <?php

     

    $db_host = '****;

    $db_user = '****';

    $db_pwd = '*****';

    $cat = mysql_real_escape_string($_POST['D1'])); // when there is 2) the page is blank no html or page tital with 1) the html and tital is there but no db results and the ddm dont do ne thing //

    $database = 'nbbcj_co_uk';

    $table = 'penapps';

     

     

    if (!mysql_connect($db_host, $db_user, $db_pwd))

        die("Can't connect to database");

     

    if (!mysql_select_db($database))

        die("Can't select database");

     

    // sending query

     

    $result = mysql_query("SELECT * FROM {$table} WHERE `cat` = '$cat' LIMIT 10 ");

    if (!$result) {

        die("Query to show fields from table failed");

    }

     

    $fields_num = mysql_num_fields($result);

     

    //echo "<h1>Table: {$table}</h1>";

    echo "<table border='1' width='100%'><tr>";

    // printing table headers

    for($i=0; $i<$fields_num; $i++)

    {

        $field = mysql_fetch_field($result);

        //echo "<td>{$field->name}</td>";

    }

    echo "</tr>\n";

    // printing table rows

    while($row = mysql_fetch_row($result))

    {

        echo "<tr>";

     

        // $row is array... foreach( .. ) puts every element

        // of $row to $cell variable

        foreach($row as $cell)

            echo "<td>$cell</td>";

     

        echo "</tr>\n";

    }

    mysql_free_result($result);

    ?>

     

     

    </body>

     

    </html>

    the page with only 1 ) in the above code shows this www.nbbcj.co.uk/testd/1/test1.php

  10. Hi there.

     

    Im a noob to sql and php not sure if this is right place to post,

     

    Im trying to get a dynamic drop down menu to show the 1st column in my sql database the column is called cat and holds category info ie audio, internet, music ect. ( i have no idea how to do lol )

     

    it has taken me 2 days to find and edit this  the bold and underline'd bit is what im trying to change with the dropdown menu.

     

    Or thinking bout it is there a way to do it with the URL. IE.. page name.php?cat=audio ?

    would that be easer ? is there any security issues with doing it that way ?

     

     

    Code==================================

    $db_host = '*******';

    $db_user = '******';

    $db_pwd = '*****;

     

    $database = 'nbbcj_co_uk';

    $table = 'penapps';

     

    if (!mysql_connect($db_host, $db_user, $db_pwd))

        die("Can't connect to database");

     

    if (!mysql_select_db($database))

        die("Can't select database");

     

    // sending query

    $result = mysql_query("SELECT * FROM {$table} WHERE `cat` = 'audio' LIMIT 10 ");

    if (!$result) {

        die("Query to show fields from table failed");

    }

     

    $fields_num = mysql_num_fields($result);

     

    //echo "<h1>Table: {$table}</h1>";

    echo "<table border='1' width='100%'><tr>";

    // printing table headers

    for($i=0; $i<$fields_num; $i++)

    {

        $field = mysql_fetch_field($result);

        //echo "<td>{$field->name}</td>";

    }

    echo "</tr>\n";

    // printing table rows

    while($row = mysql_fetch_row($result))

    {

        echo "<tr>";

     

        // $row is array... foreach( .. ) puts every element

        // of $row to $cell variable

        foreach($row as $cell)

            echo "<td>$cell</td>";

     

        echo "</tr>\n";

    }

    mysql_free_result($result);

    ?>

    code end ======================

     

    the test page can been seen here http://www.nbbcj.co.uk/testd/1/test1.php

     

    Any more questions let me know

     

    Thanks for any help you can give, a we all have to start some ware lol

     

    thanks kaine.

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