SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with update using mysqli

    I am woking from Kevin Yank's new book Database driven web sites 4th edition, but have a problem. Working from the pdf of edition3 I built an update script which could update the 31 fields on my web page, all worked fine. Now using the new 4th edition I need to change the code to work with mysqli

    This code below works fine with 11 fields.
    Question is there a limit to the number of fields that can be updated at the same time ? using mysqli_real_escape_string.
    When I add in the other fields taking the number up to 31 I get the error message at the bottom of this post. All lines of code are the same they were pasted from the line above and just the name changed so if the first 11 fields work why don't the others?



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

    <?php
    include ('../includes/unmagic.php');
    $filter = $_POST['filter'];
    include ('../includes/connect.php');

    if (isset($_POST['page_name']));
    $id = mysqli_real_escape_string($link, $_POST['id']);
    $page_title = mysqli_real_escape_string($link, $_POST['page_title']);
    $page_number = mysqli_real_escape_string($link, $_POST['page_number']);
    $keyword1 = mysqli_real_escape_string($link, $_POST['keyword1']);
    $keyword2 = mysqli_real_escape_string($link, $_POST['keyword2']);
    $keyword3 = mysqli_real_escape_string($link, $_POST['keyword3']);
    $keyword4 = mysqli_real_escape_string($link, $_POST['keyword4']);
    $keyword5 = mysqli_real_escape_string($link, $_POST['keyword5']);
    $keyword6 = mysqli_real_escape_string($link, $_POST['keyword6']);
    $page_descript = mysqli_real_escape_string($link, $_POST['descript']);
    $page_name = mysqli_real_escape_string($link, $_POST['page_name']);


    $sql ="UPDATE site SET
    id='$id',
    page_title='$page_title',
    page_number='$page_number',
    keyword1='$keyword1',
    keyword2='$keyword2',
    keyword3='$keyword3',
    keyword4='$keyword4',
    keyword5='$keyword5',
    keyword6='$keyword6',
    descript='$page_descript',
    page_name='$page_name'
    WHERE id='$filter'";
    if (!mysqli_query($link, $sql))
    {
    $error = 'Error updating page: ' . mysqli_error($link);
    include 'error.html.php';
    exit();
    }


    ?>
    <a href="index.htm">Return To Index</a>

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



    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 26

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 27

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 28

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 29

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 30

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 31

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 32

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 33

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 34

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 35

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 36

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 37

    Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 70

    Warning: mysqli_error() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 72

    Error adding submitted page:

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do a var_dump of $link and see if it's an actual resource on around line 5.

    Errr.. this here:

    PHP Code:
    if (isset($_POST['page_name'])); 
    You need to use braces to wrap around all the multiple statements you have... eg

    PHP Code:
    if (isset($_POST['page_name'])) {
    $id mysqli_real_escape_string($link$_POST['id']);
    $page_title mysqli_real_escape_string($link$_POST['page_title']);
    $page_number mysqli_real_escape_string($link$_POST['page_number']);
    $keyword1 mysqli_real_escape_string($link$_POST['keyword1']);
    $keyword2 mysqli_real_escape_string($link$_POST['keyword2']);
    $keyword3 mysqli_real_escape_string($link$_POST['keyword3']);
    $keyword4 mysqli_real_escape_string($link$_POST['keyword4']);
    $keyword5 mysqli_real_escape_string($link$_POST['keyword5']);
    $keyword6 mysqli_real_escape_string($link$_POST['keyword6']);
    $page_descript mysqli_real_escape_string($link$_POST['descript']);
    $page_name mysqli_real_escape_string($link$_POST['page_name']);


    $sql ="UPDATE site SET
    id='
    $id',
    page_title='
    $page_title',
    page_number='
    $page_number',
    keyword1='
    $keyword1',
    keyword2='
    $keyword2',
    keyword3='
    $keyword3',
    keyword4='
    $keyword4',
    keyword5='
    $keyword5',
    keyword6='
    $keyword6',
    descript='
    $page_descript',
    page_name='
    $page_name'
    WHERE id='
    $filter'";
    if (!
    mysqli_query($link$sql))
    {
    $error 'Error updating page: ' mysqli_error($link);
    include 
    'error.html.php';
    exit();
    }


    Cross browser css bugs

    Dan Schulz you will be missed

  3. #3
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok Thanks for that here are the results. First I added the other braces where you said but made no difference to error.
    then added var_dump($link); at line 5.
    1st message below is when I have 11 names and code works


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

    object(mysqli)#1 (0) { } Return To Index

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

    This is the mesage when I add in the other lines and code does not work.

    object(mysqli)#1 (0) { }
    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 27

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 28

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 29

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 30

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 31

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 32

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 33

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 34

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 35

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 36

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 37

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 38

    Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 71

    Warning: mysqli_error() expects parameter 1 to be mysqli, string given in /home/wrbrown/domains/wrbrown.co.uk/public_html/builder/admin_site/sub_page_update.php on line 73

    Error adding submitted page:

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    According to the errors you’re seeing, when PHP gets to line 27 in your script, the variable $link does not contain a MySQLi connection identifier. To confirm this, try putting the var_dump line you used above just before the statement on line 27.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kevin Yank View Post
    According to the errors you’re seeing, when PHP gets to line 27 in your script, the variable $link does not contain a MySQLi connection identifier. To confirm this, try putting the var_dump line you used above just before the statement on line 27.
    So I now have a new tool up my sleeve the var_dump .

    Thank you Kevin for your advice re putting the var_dump in just before the problem line.
    With your help I have now found the problem.!!
    So to anyone reading this post in the future if you are as daft as me than look at the names you have used for your input names etc.
    I had used a field name of link to store the nav link for a page. Now that was fine with mysql BUT mysqli uses $link for the connection I also had
    $link = mysqli_real_escape_string($link, $_POST['link']); so that is why my code was not happy.

    PS

    Nice book Kevin. If you are new to php and mysql then I can recommend Build Your Own Database Driven Web Site Using PHP & Mysql 4th edition from Sitepoint.

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hooray! Glad to hear you found the source of the problem.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •