PHP MySQL NULL Values ??
Hi,
I am trying to implement a CMS in Dreamweaver MX 2004 using
PHP MySQL. My Product table contains fields that are not relavent
to all products and at the moment i have given these the value
NULL. Is there anyway for dreamweaver not to display the NULL
fields or is my problem with the database.
Thanks for any help,
Ian
On Sun, 22 Oct 2006 16:53:07 +0000 (UTC), "irl_123"
<[email protected]> wrote:
>Hi,
> I am trying to implement a CMS in Dreamweaver MX 2004
using PHP MySQL. My
>Product table contains fields that are not relavent to
all products and at the
>moment i have given these the value NULL. Is there anyway
for dreamweaver not
>to display the NULL fields or is my problem with the
database.
> Thanks for any help,
> Ian
Something like this:
if (!is_null(your recordset field here)) {
//show the recordset field
Steve
steve at flyingtigerwebdesign dot com
Similar Messages
-
Hello all,
I'm pulling my hair out--thank you for any help you can give
me.
I have a form that a person fills out that has a field that
asks "How
many visitors including you" and I'd like them to type in a
number, and
on submit of the form, have that value -2 multiplied by 20
and inserted
into a "total cost" column.
I'm using the standard DW server behaviors and I've searched
the
internet. How do I perform basic math on that value and
insert it into
the database?
If you have any pointers, that would be great.
Thank you!
-JohnJohn R. Lenz wrote:
> Your code below works great, and I just noticed links to
your book were
> available on your web site, and it's in the mail to me.
Looking forward
> to it.
Thanks, hope you find it useful.
> After the form is posted, I'd like to address the person
who posted it
> by their first name and last name, as well as some of
the details. How
> would you go about doing this in the best way? Would you
set a variable
> and echo it on the 'Thank you' page, or are there better
ways of doing
> it with a recordset and filtering it on form submit?
To pass the details to a thank you page, you would need to
store the
information in $_SESSION variables. You could amend the
earlier script
like this:
<?php
session_start();
if (isset($_POST['visitors'])) {
if ($_POST['visitors'] < 3) {
$num = 0;
} else {
$num = $_POST['visitors'] - 2;
$_POST['total_cost'] = $num * 20;
$_SESSION['total_cost'] = $_POST['total_cost'];
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['last_name'] = $_POST['last_name'];
?>
In the thank you page, put the following at the top of the
page:
<?php session_start(); ?>
It must go before anything is output to the browser, so put
it above the
DOCTYPE declaration, and make sure there's no space before
it.
You can then use the $_SESSION variables in the thank you
page.
At the end of the page, add this to clear up the session
variables:
<?php
$_SESSION = array();
destroy_session();
?>
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
PHP+MySQL query with empty value
Hi!
Software is DW8 with Apache 2.0.48, MySQL ver. 4.0.15a, PHP
4.2.3.
We had problem when a submitted value for 'regionID' in the
submit page
was left blank and the following error message appears in the
result page:
"You have an error in your SQL syntax. Check the manual that
corresponds
to your MySQL server version for the right syntax to use near
'LIMIT 0,
3' at line 1"
The problem was solved by adding at the top of the page:
<?php
if (isset($_POST['regionID']) &&
empty($_POST['regionID'])) {
$_POST['regionID'] = '0';
?>
How to change the above code to retrieve ALL records when an
empty \
blank value is submitted for 'regionID'?
TIA
Nanubbgirl wrote:
> Something I picked up at a PHP/MySQL seminar...
$_REQUEST works in place of
> either $_GET or $_POST. It basically means use either
get or post. But it is
> less precise because it can pick up either variable and
has to think about the
> request...
I'm afraid you've picked up rather poor information.
$_REQUEST relies on
register_globals being turned on. Since register_globals is
considered a
major security risk, the default setting has been off since
April 2002.
Many hosting companies have turned register_globals on, in
spite of the
security problems, because so many poorly written scripts
rely on it.
The PHP development team has decided to resolve this security
issue once
and for all by removing register_globals from PHP 6.
Forget $_REQUEST. Use $_POST and $_GET always. It's safer,
and it's
futureproof.
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/ -
Storing NULL Value in Mysql database
Hi all,
Can anybody help me ? How can I store a NULL value in my Mysql database file using JSP.
I have got a blank input from the user's form but in place of blank I want to store NULL value in my database.
What should i do ?
Thanks for any help in advance.
regards
savdeephttp://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html#setNull(int,%20int)
-
Show NULL values in an SQL query
Hi,
Please excuse my ignorance, but I am very green in Oracle.
I am trying to create a simple function in PHP to return a list of the entire table row in an Oracle DB, however no matter I do Oracle skipps the columns with NULL values, which means that I don't even get the number of the columns corect. The query is as simple as it can get:
SELECT * FROM table_name;
I've tried NVL, DECODE and god knows what else. Please give me a hand with this.
Cheers,
PimmyOnce you can use ODBC it should be possible to use MySQL with HS:
http://www.idevelopment.info/data/Oracle/DBA_tips/Heterogeneous_Services/HETERO_2.shtml
What concerns the licenses: We are not referring to transparent gateways but to heterogenous services (generic connectivity) which come free with the DB:
http://www.oracle.com/technology/products/gateways/faq.html#A707 -
I've posted this before and didn't get the answer that I need, probably because I didn't post all of my codes. I am using PHP/MySql. I created a website that has several forms. When I process three of the forms, I get the error messages below:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Condition, Length, Color, City, `State`, Email, Photo) VALUES ('29', '4', 'Used'' at line 1.
Below I am posting the codes. Hopefully, this time I posted everything that I should have so that I can get assistance.
FORM
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="individual" class="individual" id="individual">
<table width="594" border="0" class="test">
<tr></tr>
<tr>
<td width="166" class="td">Posting Title</td>
<td colspan="3"><span id="sprytextfield1">
<label>
<input name="Posting Title" type="text" class="test" id="Posting Title" size="35" />
</label>
<span class="textfieldRequiredMsg">Required</span></span></td>
</tr>
<tr>
<td class="td">Price</td>
<td colspan="3"><span id="sprytextfield2">
<label>
<input name="price" type="text" class="test" id="price" size="35" />
</label>
<span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td class="td">Size(s)</td>
<td colspan="3"><label>
<select name="size" size="1" multiple="multiple" class="test" id="size">
<option>0</option>
<option>2</option>
<option>4</option>
<option>6</option>
<option>8</option>
<option>10</option>
<option>12</option>
<option>14</option>
<option>16</option>
<option>18</option>
<option>20</option>
<option>22</option>
<option>24</option>
<option>26</option>
</select>
</label></td>
</tr>
<tr>
<td class="td">Condition</td>
<td colspan="3"><label>
<select name="Condition" class="test" id="Condition">
<option>New</option>
<option>Used</option>
</select>
</label></td>
</tr>
<tr>
<td class="td">Length</td>
<td colspan="3"><label>
<select name="Length" class="test" id="Length">
<option>Long</option>
<option>Short</option>
<option>Mid-Length</option>
</select>
</label></td>
</tr>
<tr>
<td class="td">Color</td>
<td colspan="3" class="td"><span id="sprytextfield5">
<label>
<input name="Color" type="text" class="test" id="Color" size="35" />
</label>
<span class="textfieldRequiredMsg">Required</span></span></td>
</tr>
<tr>
<td class="td">City</td>
<td class="td"><span id="sprytextfield4">
<label>
<input name="City" type="text" class="test" id="City" size="35" />
</label>
<span class="textfieldRequiredMsg">Required</span></span></td>
<td class="td"> </td>
<td class="td"> </td>
</tr>
<tr>
<td class="td">State</td>
<td colspan="3"><label>
<select name="State" class="test" id="State">
<option>AL</option>
<option>AK</option>
<option>AZ</option>
<option>AR</option>
<option>CA</option>
<option>CO</option>
<option>CT</option>
<option>DE</option>
<option>DC</option>
<option>FL</option>
<option>GA</option>
<option>HI</option>
<option>ID</option>
<option>IL</option>
<option>IN</option>
<option>IA</option>
<option>KS</option>
<option>KY</option>
<option>LA</option>
<option>ME</option>
<option>MD</option>
<option>MA</option>
<option>MI</option>
<option>MN</option>
<option>MS</option>
<option>MO</option>
<option>MT</option>
<option>NE</option>
<option>NV</option>
<option>NH</option>
<option>NJ</option>
<option>NM</option>
<option>NY</option>
<option>NC</option>
<option>ND</option>
<option>OH</option>
<option>OK</option>
<option>OR</option>
<option>PA</option>
<option>RI</option>
<option>SC</option>
<option>SD</option>
<option>TN</option>
<option>TX</option>
<option>UT</option>
<option>VT</option>
<option>VA</option>
<option>WA</option>
<option>WV</option>
<option>WI</option>
<option>WY</option>
</select>
</label></td>
</tr>
<tr>
<td class="td">Email</td>
<td colspan="3"><span id="sprytextfield3">
<label>
<input name="Email" type="text" class="test" id="Email" size="35" />
</label>
<span class="textfieldRequiredMsg">Required</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td height="26" class="td">Confirm Email</td>
<td colspan="3"><span id="spryconfirm1">
<label>
<input name="Confirm Email2" type="text" class="test" id="Confirm Email2" size="35" />
</label>
<span class="confirmRequiredMsg">Required</span><span class="confirmInvalidMsg">The values don't match.</span></span></td>
</tr>
<tr>
<td height="26" class="td">Photo(s)</td>
<td colspan="3"><label>
<input name="Photo" type="file" class="test" id="Photo" size="35" />
</label></td>
</tr>
<tr>
<td height="131" class="td">Additional Details</td>
<td colspan="3"><label>
<textarea name="Additional Details" cols="40" rows="6" class="test" id="Additional Details"></textarea>
</label></td>
</tr>
</table>
<p>
<label>
<input name="Submit" type="submit" class="test" id="Submit" value="Post" />
</label>
</p>
<input type="hidden" name="MM_insert" value="individual" />
</form>
SERVER BEHAVIOR
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "individual")) {
$insertSQL = sprintf("INSERT INTO donations (postingTitle, `size`, condition, length, color, city, `state`, email, photo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Posting Title'], "text"),
GetSQLValueString($_POST['size'], "text"),
GetSQLValueString($_POST['Condition'], "text"),
GetSQLValueString($_POST['Length'], "text"),
GetSQLValueString($_POST['Color'], "text"),
GetSQLValueString($_POST['City'], "text"),
GetSQLValueString($_POST['State'], "text"),
GetSQLValueString($_POST['Email'], "text"),
GetSQLValueString($_POST['Photo'], "text"));
mysql_select_db($database_bridesmaidsrack_db, $bridesmaidsrack_db);
$Result1 = mysql_query($insertSQL, $bridesmaidsrack_db) or die(mysql_error());
$insertGoTo = "donations.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $insertGoTo));
DATABASE CONNECTION
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_bridesmaidsrack_db = "localhost";
$database_bridesmaidsrack_db = "bridesmaidsrack";
$username_bridesmaidsrack_db = "";
$password_bridesmaidsrack_db = "";
$bridesmaidsrack_db = mysql_pconnect($hostname_bridesmaidsrack_db, $username_bridesmaidsrack_db, $password_bridesmaidsrack_db) or trigger_error(mysql_error(),E_USER_ERROR);Hi David,
I did as you recommended. For good measure, I even changed the case of the letters to make sure that they coincide with exactly what's in the database. I still kept getting the same error message. So I deleted the recordset and attempted to recreate it. When I attempted to recreate the record set, I got the following error message: "RangeError: invalid array length". My codes are listed below:
Form:
<form method="POST" enctype="multipart/form-data" name="individual" class="individual" id="individual">
<table width="594" border="0" class="test">
<tr></tr>
<tr>
<td width="166" class="td">Posting Title</td>
<td colspan="3"><span id="sprytextfield1">
<label>
<input name="posting_title" type="text" class="test" id="posting_title" size="35" />
</label>
<span class="textfieldRequiredMsg">Required</span></span></td>
</tr>
<tr>
<td class="td">Size(s)</td>
<td colspan="3"><label>
<select name="size" size="1" multiple="multiple" class="test" id="size">
<option>0</option>
<option>2</option>
<option>4</option>
<option>6</option>
<option>8</option>
<option>10</option>
<option>12</option>
<option>14</option>
<option>16</option>
<option>18</option>
<option>20</option>
<option>22</option>
<option>24</option>
<option>26</option>
</select>
<span class="Text">To select multiple sizes, hold ctrl and select each size.</span></label></td>
</tr>
<tr>
<td class="td">Condition</td>
<td colspan="3"><label>
<select name="condition" class="test" id="condition">
<option>New</option>
<option>Used</option>
</select>
</label></td>
</tr>
<tr>
<td class="td">Length</td>
<td colspan="3"><label>
<select name="length" class="test" id="length">
<option>Long</option>
<option>Short</option>
<option>Mid-Length</option>
</select>
</label></td>
</tr>
<tr>
<td class="td">Color(s)</td>
<td colspan="3" class="td"><span id="sprytextfield5">
<label>
<input name="color" type="text" class="test" id="color" size="35" />
</label>
<span class="textfieldRequiredMsg">Required</span></span></td>
</tr>
<tr>
<td class="td">City</td>
<td class="td"><span id="sprytextfield4">
<label>
<input name="city" type="text" class="test" id="city" size="35" />
</label>
<span class="textfieldRequiredMsg">Required</span></span></td>
<td class="td"> </td>
<td class="td"> </td>
</tr>
<tr>
<td class="td">State</td>
<td colspan="3"><label>
<select name="state" class="test" id="state">
<option>AL</option>
<option>AK</option>
<option>AZ</option>
<option>AR</option>
<option>CA</option>
<option>CO</option>
<option>CT</option>
<option>DE</option>
<option>DC</option>
<option>FL</option>
<option>GA</option>
<option>HI</option>
<option>ID</option>
<option>IL</option>
<option>IN</option>
<option>IA</option>
<option>KS</option>
<option>KY</option>
<option>LA</option>
<option>ME</option>
<option>MD</option>
<option>MA</option>
<option>MI</option>
<option>MN</option>
<option>MS</option>
<option>MO</option>
<option>MT</option>
<option>NE</option>
<option>NV</option>
<option>NH</option>
<option>NJ</option>
<option>NM</option>
<option>NY</option>
<option>NC</option>
<option>ND</option>
<option>OH</option>
<option>OK</option>
<option>OR</option>
<option>PA</option>
<option>RI</option>
<option>SC</option>
<option>SD</option>
<option>TN</option>
<option>TX</option>
<option>UT</option>
<option>VT</option>
<option>VA</option>
<option>WA</option>
<option>WV</option>
<option>WI</option>
<option>WY</option>
</select>
</label></td>
</tr>
<tr>
<td class="td">Email</td>
<td colspan="3"><span id="sprytextfield3">
<label>
<input name="email" type="text" class="test" id="email" size="35" />
</label>
<span class="textfieldRequiredMsg">Required</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td height="26" class="td">Confirm Email</td>
<td colspan="3"><span id="spryconfirm1">
<label>
<input name="confirm_email2" type="text" class="test" id="confirm_email2" size="35" />
</label>
<span class="confirmRequiredMsg">Required</span><span class="confirmInvalidMsg">The values don't match.</span></span></td>
</tr>
<tr>
<td height="26" class="td">Photo(s)</td>
<td colspan="3"><label>
<input name="Photo" type="file" class="test" id="Photo" size="35" />
</label></td>
</tr>
<tr>
<td height="131" class="td">Additional Details</td>
<td colspan="3"><label>
<textarea name="Additional Details" cols="40" rows="6" class="test" id="Additional Details"></textarea>
<input name="hiddenField" type="hidden" id="hiddenField" value="Date" />
</label></td>
</tr>
</table>
<p>
<label>
<input name="Submit" type="submit" class="test" id="Submit" value="Post" />
</label>
</p>
</form>
Server Behavior
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "individual")) {
$insertSQL = sprintf("INSERT INTO donations (posting_title, `size`, condition, length, color, city, `state`, email, photo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['posting_title'], "text"),
GetSQLValueString($_POST['size'], "text"),
GetSQLValueString($_POST['condition'], "text"),
GetSQLValueString($_POST['length'], "text"),
GetSQLValueString($_POST['color'], "text"),
GetSQLValueString($_POST['city'], "text"),
GetSQLValueString($_POST['state'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['Photo'], "text"));
mysql_select_db($database_bridesmaidsrack_db, $bridesmaidsrack_db);
$Result1 = mysql_query($insertSQL, $bridesmaidsrack_db) or die(mysql_error());
$insertGoTo = "donations.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $insertGoTo)); -
I am new to php/MYSQL but I am trying to learn. I built an
insert page using DW8. I was looking back over the code trying to
figure it out. Is it just me or does dreamweaver an a bunch of junk
to there code to do a simple insert from 4 form fields.
Can anyone explain what DW is doing since I am now dumber for
having looked at it.
<?php
function GetSQLValueString($theValue, $theType,
$theDefinedValue = "", $theNotDefinedValue = "")
$theValue = (!get_magic_quotes_gpc()) ?
addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) .
"'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" :
"NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
return $theValue;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" .
htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) &&
($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO reviews (review_date,
review_name, review_address1, review_city, review_state) VALUES
(%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['textfield'], "text"),
GetSQLValueString($_POST['textfield2'], "text"),
GetSQLValueString($_POST['textfield3'], "text"),
GetSQLValueString($_POST['textfield4'], "text"));
mysql_select_db($database_siteData, $siteData);
$Result1 = mysql_query($insertSQL, $siteData) or
die(mysql_error());
$insertGoTo = "
http://www.yahoo.com/";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $insertGoTo));
mysql_select_db($database_siteData, $siteData);
$query_Recordset1 = "SELECT * FROM reviews";
$Recordset1 = mysql_query($query_Recordset1, $siteData) or
die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>newhorizonhosting.com wrote:
> I am new to php/MYSQL but I am trying to learn. I built
an insert page using
> DW8. I was looking back over the code trying to figure
it out. Is it just me or
> does dreamweaver an a bunch of junk to there code to do
a simple insert from 4
> form fields.
No, it's not a bunch of junk. It's filtering the input to
make sure that
things are inserted correctly into your database.
> Can anyone explain what DW is doing since I am now
dumber for having looked at
> it.
This function filters the form content to prepare it for
insertion in
the database.
> function GetSQLValueString($theValue, $theType,
$theDefinedValue = "",
> $theNotDefinedValue = "")
This sets the action value of the form tag, including any
query string.
> $editFormAction = $_SERVER['PHP_SELF'];
> if (isset($_SERVER['QUERY_STRING'])) {
> $editFormAction .= "?" .
htmlentities($_SERVER['QUERY_STRING']);
> }
This builds the SQL query and inserts the form content into
the database.
> if ((isset($_POST["MM_insert"])) &&
($_POST["MM_insert"] == "form1")) {
> $insertSQL = sprintf("INSERT INTO reviews (review_date,
review_name,
> review_address1, review_city, review_state) VALUES (%s,
%s, %s, %s, %s)",
> GetSQLValueString($_POST['date'], "date"),
> GetSQLValueString($_POST['textfield'], "text"),
> GetSQLValueString($_POST['textfield2'], "text"),
> GetSQLValueString($_POST['textfield3'], "text"),
> GetSQLValueString($_POST['textfield4'], "text"));
>
> mysql_select_db($database_siteData, $siteData);
> $Result1 = mysql_query($insertSQL, $siteData) or
die(mysql_error());
This redirects the page after the database query has
finished.
> $insertGoTo = "
http://www.yahoo.com/";
> if (isset($_SERVER['QUERY_STRING'])) {
> $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" :
> $insertGoTo .= $_SERVER['QUERY_STRING'];
> }
> header(sprintf("Location: %s", $insertGoTo));
> }
This is unrelated to the insert. It's a recordset that
retrieves
everything from the reviews table of your database.
> mysql_select_db($database_siteData, $siteData);
> $query_Recordset1 = "SELECT * FROM reviews";
> $Recordset1 = mysql_query($query_Recordset1, $siteData)
or die(mysql_error());
> $row_Recordset1 = mysql_fetch_assoc($Recordset1);
> $totalRows_Recordset1 = mysql_num_rows($Recordset1);
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
PHP/MySQL field recognize carriage returns?
I'm a novice PHP/MySQL database driven site builder. I need
to have users enter text into a field with carriage returns and
have the database recognize and store those carriage returns so it
displays when the data is displayed on a PHP page.
How do I do this and please keep it simple?
Do I need to use a particular type of MySQL datafield?
Will I be able to use the same code on an "update"
page?quote:
Originally posted by:
geschenk
>>
so it displays when the data is displayed on a PHP page
>>
if you just need to replace the \n - type line breaks
generated by multiline textareas with <br /> on a page, just
use PHP´s native "nl2br"
(new line to break) function:
<?php echo nl2br($row_queryname['field_name']); ?>
That works... sort of...
When I use the update page to modify the entry it puts the
proper "br" code in it's proper place. However when I return to
that page to edit the text again (as my customer likely will), it
displays the "br" code in the text field, and if I submit the
update with the "br" code in place, it duplicates the "br" code
again, so I get double "br" statements. How do I get the update
field to read the "br" code back as carriage returns?
In addition, my insert page uses the following code to write
the original entry, and I'm not sure where to place the "nl2br"
statement in the following query (generated by WebAsssist DW
extensions):
<?php
// WA Application Builder Insert
if (isset($_POST["Insert_x"])) // Trigger
$WA_connection = $nm_connect;
$WA_table = "tb_news";
$WA_sessionName = "WADA_Insert_tb_news";
$WA_redirectURL = "tb_news_Results.php";
$WA_keepQueryString = false;
$WA_indexField = "id";
$WA_fieldNamesStr =
"sort|s_head|s_text|head|subhead|bodytext|photoid|photocaption|name|phone|email|linktitle |linkaddress|show_pfm|show_arch|show_cab";
$WA_fieldValuesStr =
"".((isset($_POST["sort"]))?$_POST["sort"]:"") ."" . "|" .
"".((isset($_POST["s_head"]))?$_POST["s_head"]:"") ."" . "|" .
"".((isset($_POST["s_text"]))?$_POST["s_text"]:"") ."" . "|" .
"".((isset($_POST["head"]))?$_POST["head"]:"") ."" . "|" .
"".((isset($_POST["subhead"]))?$_POST["subhead"]:"") ."" . "|" .
"".((isset($_POST["bodytext"]))?$_POST["bodytext"]:"") ."" . "|" .
"".((isset($_POST["photoid"]))?$_POST["photoid"]:"") ."" . "|" .
"".((isset($_POST["photocaption"]))?$_POST["photocaption"]:"") .""
. "|" . "".((isset($_POST["name"]))?$_POST["name"]:"") ."" . "|" .
"".((isset($_POST["phone"]))?$_POST["phone"]:"") ."" . "|" .
"".((isset($_POST["email"]))?$_POST["email"]:"") ."" . "|" .
"".((isset($_POST["linktitle"]))?$_POST["linktitle"]:"") ."" . "|"
. "".((isset($_POST["linkaddress"]))?$_POST["linkaddress"]:"") .""
. "|" . "".((isset($_POST["show_pfm"]))?$_POST["show_pfm"]:"") .""
. "|" . "".((isset($_POST["show_arch"]))?$_POST["show_arch"]:"")
."" . "|" . "".((isset($_POST["show_cab"]))?$_POST["show_cab"]:"")
$WA_columnTypesStr =
"none,none,NULL|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',n one,''|',none,''|',none,''|',none,''|',none,''|none,none,NULL|none,none,NULL|none,none,NUL L";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_nm_connect;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj =
WA_AB_generateInsertParams($WA_fieldNames, $WA_columns,
$WA_fieldValues, -1);
$WA_Sql = "INSERT INTO " . $WA_table . " (" .
$insertParamsObj->WA_tableValues . ") VALUES (" .
$insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or
die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != ""
&& isset($_SERVER["QUERY_STRING"]) &&
$_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') ===
false)?"?":"&").$_SERVER["QUERY_STRING"];
header("Location: ".$WA_redirectURL);
?> -
PHP/mySQL Insert/Update Problems
I hope someone can help because I can't find anything online
that is helping me with this problem. I can't get the Dreamweaver
controls to work when coding a PHP insert or update record page. It
looks like it creates the code correctly but when I put them out on
my webserver and then fill out the form and click submit the page
submits and tries to use a URL string of (null)/admin/index.php
where index.php is the form page not the page I told it to redirect
to. I don't know why the (null) value keeps getting inserted into
the string either. The browser obviously can't find this URL so
gives a page cannot be displayed screen and nothing get's inserted
or updated in the mySQL database.
Any help would be greatly appreciated. This problem is
driving me crazy because I want to save time not having to hand
code things. Below is a User Authentication page using the
Dreamweaver controls that does the same thing when I try to
login.tobyd wrote:
> the page submits and tries to use a URL string of
(null)/admin/index.php
> where index.php is the form page not the page I told it
to redirect to. I don't
> know why the (null) value keeps getting inserted into
the string either.
The following two lines set the URL for login success and
failure.
> $MM_redirectLoginSuccess = "../admin_index.php";
> $MM_redirectLoginFailed = "../admin/index.php";
As you can see, they are relative paths, suggesting that the
login form
is in a different subfolder, but at the same level as
admin_index.php
and the admin folder. The (null) almost certainly comes from
the fact
that your login page is in the site root. If you're typing in
the
redirect filenames manually, use the Browse button instead.
Dreamweaver
should set the correct path for you.
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
Conditional content from 2 tables in PHP/MYSQL
I am developing a site in DWCS4 that has a database with 2 tables: audio and notes.
The tables contain the following fields:
AUDIO
audio_id (ai)
title (varchar)
filename (varchar)
(plus other fields for date, speaker etc)
NOTES
notes_id (ai)
audio_id (int) - foreign key
title (varchar)
file_location (varchar)
(plus other fields for date, author etc)
I have a page which lists audio files which enables a selection to be made that then leads to a page (audio_detail.php) which has full details of the audio and contains a player (see www.wscnf.org/audio.php).
Some of these audio files have associated notes and others do not - those that do contain the reference from audio.audio_id in notes.audio_id - if there are no notes then the foreign key defaults to a value of 0.
I have been asked to amend the audio_detail.php page so that, if there is an associated notes file, a link to that file is shown on the page - what I have in mind is if there are asscoiated notes, a new line appears beneath the player which says "Notes accompanying this audio are available:" followed by a download link. If there are no associated notes then this line does not appear.
Any assistance on how to achieve this would be most welcome - my knowledge of PHP/MYSQL is fairly basic (but growing!)There are several ways to go about this, but the one that comes to mind is to use an outer join to select columns from both tables. The outer join will return results from the main table AUDIO regardless of if there are matching results in NOTES. You can then test the column values in NOTES. If the row has a NULL value in NOTES.notes_id, then there is no associate note for that row. If there is an notes_id value, then you can use conditional logic to display the NOTE details, link to other pages, etc.
-
Inserting special character like apostrophes with PHP/Mysql
Hi friends,
I have a problem with php/mysql. I have created a form inton a php page with dreamweaver and when i try to fill the form with a string containing apostrophe ( ' ), i have a error. It seems that the insertion is not possible. Could you have any idea for that. I give you the php dreamweaver code and thank you for your help.
<?php require_once('Connections/Mainconnect.php'); ?>
<?php require_once('Zend/Date.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
if ($theValue=="")
$theValue="NULL";
else
$zendDate=new Zend_Date($theValue,"dd/MM/yyyy");
$theValue="'".$zendDate->toString("yyyy-MM-dd")."'";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE pers_soc_reg SET field1=%s, field2=%s,
GetSQLValueString($_POST['field1'], "text"),
GetSQLValueString($_POST['field2'], "double"));"Normally, you canot use mysql_real_escape_string without connection to database"
That is not true at all. Try running the following script.
<?php
if ($_POST['submit']){
$x1=$_POST['test1'];
foreach ($_POST as $key => $value) {
if (!is_array($value)){
$_POST[$key] = mysql_real_escape_string($value);
extract($_POST);
echo "The text after 'becomes' should be escaped (\')<br/>";
echo "$x1 becomes $test1<br/>";
?>
<hr/>
<form action="#" method="post" />
Enter some text, including an apostrophe: <input name="test1" type="text"><br/>
<p><input name="submit" value="submit" type="submit"/>
</form> -
I have created a site for a local artist at
http://www.everythingheidi.com/iloveyoucards.org/postExperience.php
When a user upload a message without a photo the mySQL
database table get a new row with 4 simple pieces of data, the
name, the message and the location of the image. This all works
great except for some reason, the image_url field in my database is
not updated with the default value in the case where the user
uploads a message with no photo. This field is configured to be not
null and a default value is set according to the view of the table
in phpMyAdmin. If I use the command line to run the following sql
the default value is updated.
insert into posts(name, post)
values('test name', 'test post');
I am a little bit at a loss as to how the app is able to get
a null value into this field which is set to not null and has a
default value declared.
Any help is greatly appreciated.
thanks,
- TannerOn Fri, 30 Nov 2007 20:21:13 +0000 (UTC), "mediaMan6476"
<[email protected]> wrote:
>If I
>use the command line to run the following sql the default
value is updated.
>
> insert into posts(name, post)
> values('test name', 'test post');
That suggests that you are inserting zero length strings,
which is not
the same thing as a null value. Your code that does the
insert needs to
validate the image_url and not include it in the insert if
nothing was
provided.
Gary -
Football/soccer results grid advice php/mysql
I need to create the above from my database, and I am not sure how to go about it.
Basically this calculates all the goals scored against another team. If team 1 (column) is the same as team 1 (row) an "x" is put in place as team 1 cannot play itself
I have added my database structure
Image of example
http://filedb.experts-exchange.com/incoming/2010/08_w34/t337870/Untitled-1.jpg
CREATE TABLE IF NOT EXISTS `matches` (
`match_id` int(8) NOT NULL auto_increment,
`date` date default NULL,
`time` varchar(5) default NULL,
`report` longtext,
`referee_id` int(8) NOT NULL,
`season_id` int(8) NOT NULL,
PRIMARY KEY (`match_id`),
KEY `referee_id` (`referee_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
-- Dumping data for table `matches`
INSERT INTO `matches` (`match_id`, `date`, `time`, `report`, `referee_id`, `season_id`) VALUES
(1, '2010-08-02', '15:00', 'N/A', 1, 2010),
(2, '2010-08-10', '15:00', 'n/a', 1, 2010);
CREATE TABLE IF NOT EXISTS `matchscores` (
`matchscores_id` int(8) NOT NULL auto_increment,
`match_id` int(8) NOT NULL,
`team` int(8) NOT NULL,
`score` int(8) default NULL,
PRIMARY KEY (`matchscores_id`),
KEY `match_id` (`match_id`,`team`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
-- Dumping data for table `matchscores`
INSERT INTO `matchscores` (`matchscores_id`, `match_id`, `team`, `score`) VALUES
(1, 1, 1, 2),
(2, 1, 2, 1);
CREATE TABLE IF NOT EXISTS `team` (
`team_id` int(8) NOT NULL auto_increment,
`team_name` varchar(255) NOT NULL,
`team_address` text,
`team_phone` varchar(25) default NULL,
`team_email` varchar(255) default NULL,
`team_web` varchar(255) default NULL,
`colours_home` varchar(50) default NULL,
`colours_away` varchar(50) default NULL,
`manager` varchar(255) default NULL,
`assistant` varchar(255) default NULL,
`club_rep` varchar(255) default NULL,
`division` varchar(255) default NULL,
`team_pic` varchar(255) default NULL,
`team_logo` varchar(255) default NULL,
`profile` mediumtext,
`honours` mediumtext,
`password` varchar(10) NOT NULL,
PRIMARY KEY (`team_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;Tbilly,
I have just the thing you are looking for. Check this out
here:
http://www.smithmediafusion.com/poll/poll.html
MySQL and php with a Flash front.
drop me an email if you are interested and would like more
info.
danswhc AT yahoo dot Com
Dan Mode
--> Adobe Community Expert
*Flash Helps*
http://www.smithmediafusion.com/blog/?cat=11
*THE online Radio*
http://www.tornadostream.com
<--check this
*Must Read*
http://www.smithmediafusion.com/blog
"tbilly" <[email protected]> wrote in
message
news:erfeo6$9a$[email protected]..
> Can anyone recommend a book or tutorial for a survey or
poll script I
> could
> implement using php/MySQL? Preferably one with options
such as: changing
> question types (radio vs. checkboxes), sessions, and
graphical displays of
> results. Would like to use dreamweaver to set up content
management pages
> to
> edit/add answers and questions in a database. Thanks in
advance.
> -
Not to display the null values from data base
Hiiii.
In a jsp file i have ten check boxes.The jsp file is mapped to a servlet file for parameter requesting and to
store it in DB.
The unchecked box values has null values.All the values are store in a Mysql DB table.
Again i have to display it in a jsp page from table.
The problem am facing was,how can i display only the values in a row.it must not display the null values and the crresponding column name.
Or any other way is their like below
How i can retrieve only the selected check boxes from tht jsp file.and store in backend.
Thanks in Advance
regards,
satheesh kannanHere is a rough example that may give you some ideas:
On the JSP page:
<%if(myData.getFirstName()!=null){%>
Your First Name'
<input type="text" name="firstName" value="<%=myData.getFirstName()%>">
<%}%>
In the servlet:
String firstName= request.getParameter("firstName");
if(firstName!=null){
//write it to the database
} -
Servlet only gets null values from mobile
OK, i'm doing a project for college which involves inputting data into an application on a mobile device, sending them to a servlet and updating a database. I've got my mobile app working and sending but the servlet is only receiving null values for it. I'll post the code for d servlet and see if anyone can figure out whats wrong. The problem might not even be the servlet so i'll post part of the mobile app as well. The problem could well be when i'm buffering the content on the mobile to a string. Anyway, any help appreciated, thanks.
The Servletimport java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.util.logging.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ThisServlet extends HttpServlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>ThisServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String connectionURL = "jdbc:mysql://localhost:3306/database";
Connection connection = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String MobileNumber = req.getParameter("user");
String field1 = req.getParameter("h1");
String field2 = req.getParameter("h2");
String field3 = req.getParameter("h3");
try {
// Load the database driver
Class.forName("com.mysql.jdbc.Driver");
// Get a Connection to the database
connection = DriverManager.getConnection(connectionURL, "root", "root");
try {
stmt = connection.createStatement();
} catch (SQLException ex) {
Logger.getLogger(ThisServlet.class.getName()).log(Level.SEVERE, null, ex);
rs = stmt.executeQuery("SELECT UserID FROM User WHERE MobileNumber = '" + MobileNumber + "'");
while (rs.next()) {
String UserID = rs.getString("UserID");
String insert = "INSERT INTO newTable(UserID, One, Two, Three) VALUES (?,?,?,?)";
PreparedStatement pst = connection.prepareStatement(insert);
pst.setString(1, UserID);
pst.setString(2, field1);
pst.setString(3, field2);
pst.setString(4, field3);
pst.executeUpdate();
pst.close();
catch(ClassNotFoundException e){
System.out.println(e.toString());
catch(SQLException e){
System.out.println(e.toString());
catch (Exception e){
System.out.println(e.toString());
finally {
// Always close the database connection.
try {
if (connection != null) connection.close();
System.out.print("closing db connection ... \n");
catch (SQLException ignored){
out.println(ignored);
@Override
public String getServletInfo() {
return "Short description";
}The Mobile App (only part where putting the content together to send)
buffer.append("user="+mobileNumber).append("?h1="+field1)
.append("?h2="+field2).append("?h3="+field3);
content = buffer.toString();
sendToServer(url, content);For sure you would have to do following on your mobile:
buffer.append("?user="+mobileNumber).append("&h1="+field1)
.append("&h2="+field2).append("&h3="+field3);
content = buffer.toString();
sendToServer(url, content);'?' - is a delimiter of GET parameters and '&' - is a delimiter between GET parameters
Edited by: ivanovpv on 30.04.2009 10:57
Maybe you are looking for
-
Redetermination of item category in deliveries
Hi, Let me explain with an example i have sales order with item category TAN and when i do delivery i want the item category should redetermine as TAS(example) what are all the setting in need to do? Please guide me its really urgent for me. Thanks a
-
Rectangle size grows while uploading in server
hi all, i put two table inside a ractangle. the two table has some data. while uploading the same in the server the rectangle size grows automatically but while checking in local it doesn't shows any problem. i am using ssrs 2008r2 for creating repor
-
Hi, I have a column "unit price" in a table with precision (number), it is rouding 0 whenever price in 0.nn, is there any way to call the values in decimals in report or in query. Thanks in advance Ahon
-
Can I find the equivalent to the Main.db file on m...
I built a new PC recently and whiped all of my files on my old PC to give it to somebody else. After realising I couldn't go far back in my chat history and finding out that the Main.db file is what I'd need, I started wondering if I could find this
-
I'd like to use iPhoto to create a slide show from old family slides. What size and resolution should I use for the scans so that they will look good when enlarged on a TV screen? After the slide show is created, how do I burn a DVD so that my mother