Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2004, 02:43 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default initialize variables

Hi Rich,

I have SQL query to upadate new data in dbase.
I have follow your script using function check (&$var)to initialize the variable and print these variable's value.

The problem is the page can get and display the updated values BUT dbase does not UPDATE the value. It still store the old value. That mean the update is not successful.

So, what's the problem?

Attach code:

<?php
.....
//Formulate and execute the query
$sql = "UPDATE product SET
    prod_id= '$_POST[prod_id]',
    b_type= '$_POST[b_type]',
    descp=' $_POST[descp]',
    cust_id= '$_POST[cust_id]',
    person= '$_POST[person]',
    mod= '$_POST[mod]'
    WHERE prod_id= '$pro_id'";
....
?>

<?php
....
//query
$sql = "SELECT * FROM product WHERE prod_id = '$prod_id'";
.....

//function

    function check(&$var)
    {
        return (isset($var))? $var :'';
    }

    echo" <br><b>\n".
        " ".check($_POST['prod_id'])."\n".
        " </b>\n".
        " - The product has been updated to the database.\n".
        " <p> </p>\n".
        " <table width='45%' border='1'>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Product ID:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['prod_id'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Board Type:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['b_type'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Description:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;\n".
        " </td>\n".
        " <td>\n";
?>
             <textarea name='descp' cols='80' rows='5' id='desc'><? echo "".check($_POST['descp'])."\n"; ?></textarea>

<?php
     echo " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Customer ID:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['cust_id'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Last Person:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['person'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Last Modified:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['mod'])."\n".
        " </td>\n".
        " </tr>\n".
        " </table>\n";


?>

Thanks in advance.


 
Old July 15th, 2004, 02:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

hi

i never worked with dbase, but i think you should have something like mysql has, say you create $sql variable which contains sql query, you have to call mysql_query() to run it against the mysql server...

well, i also suggest you echo the $sql variable to browser's window and see how it looks, then just copy it and run it in dbase or do this (as if it was done in mysql):

$sql = "UPDATE .... SET ....";

if(!mysql_query($sql,$conn))
{
      echo "query could not be executed";
      exit;
}

try doing something like that... :D



www.campusgrind.com the college portal
 
Old July 15th, 2004, 03:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'd also suggest adding {} around your gobal array variables - as in:

$sql = "UPDATE product SET
    prod_id= '{$_POST[prod_id]}',
    b_type= '{$_POST[b_type]}',
    descp='{$_POST[descp]}',
    cust_id= '{$_POST[cust_id]}',
    person= '{$_POST[person]}',
    mod= '{$_POST[mod]}'
    WHERE prod_id= '$pro_id'";

Only simple types can be referred to within a string. Arrays must be surrounded in {} braces before their values will be retrieved and evaluated.

Dan





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to initialize arrays in c# apoorvchandra C# 2005 1 July 12th, 2008 08:35 PM
Initialize data in an HTML Control bnewton1 BOOK: Beginning Ruby on Rails 5 July 27th, 2007 05:24 PM
Need to be able to re-initialize a form kscase Visual Basic 2005 Basics 14 May 10th, 2007 09:54 AM
Can't initialize variables auguri Visual Basic 2005 Basics 1 March 26th, 2007 05:05 PM
initialize serial port miguel.ossa C++ Programming 0 February 13th, 2004 01:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.