Re: Subject: Wont create data in my tables

From: Date: Sat, 19 Apr 2003 22:22:19 +0000
Subject: Re: Subject: Wont create data in my tables
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-19504@lists.php.net to get a copy of this message
Hi Morten - no , the code is not correct. That is, because PHP handles variables within quotes differently for double quotes ( " ) where it replaces with the *actual value* of the variable, and within single quotes ( ' ) where it doesn't touch the value inside the quotes (it assumes you mean literally, the string '$name') The way to construct the SQL is like this instead : $query = "insert into guestbook (
        name,
        location,
        email,
        url,
        comments
        )
values ('".$name."', '
        ".$location."', '
        ".$email."', '
        ".$url."', '
        ".$comments."
        ')";
Hope that's clear (You can happily tab down like that in real PHP code too, to make the SQL more readable. Main thing is just to make sure you match the quotes on each end : I usually *print* the SQL until I'm sure I have the statement correct. HTH Neil Smith. At 20:43 19/04/2003 +0000, you wrote:
From: "Morten Nielsen" <fantomcat@hotmail.com> To: <php-windows@lists.php.net> Date: Sat, 19 Apr 2003 13:27:43 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative;
        boundary="----=_NextPart_000_0109_01C30677.7590E1D0"
Message-ID: <BAY1-DAV30arcR4ZDgC00000dbd@hotmail.com> Subject: Wont create data in my tables. Can anybody tell me if this code is correct or not ?. <?php if ($submit =="Sign!") { $query = "insert into guestbook (name,location,email,url,comments) values ('$name', '$location', '$email', '$url', '$comments')"; mysql_query($query) or die (mysql_error()) ?>


« previous php.windows (#19504) next »