![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hi, All-- I have the following statement in my script, which is a simple script to lookup data from a mysql database: I have several fields in the database, and valid and contact_sales are the last two. This statement is at the end of script and is failing, but I don't know why. Instead of die, it just goes on and gives the information in the row. if(valid == "Invalid" || contact_sales == "1") die("There is a problem with your request. Please contact Sales at: sales@mysite.com"); $row = mysql_fetch_row($result); echo $row[3] As well...I am having another problem with this script. I know how to get the information from 1 column as above, but I don't know how to display the entire row. Is there a way to do this? All My Best, Jeffrey | |||
| Advertisements |
| | #2 | ||
| In article <BB5DDAC0.5566F%support@groundlevel.net>, Jeffrey Ellis <support@groundlevel.net> wrote: > Hi, All-- > > I have the following statement in my script, which is a simple script to > lookup data from a mysql database: > > I have several fields in the database, and valid and contact_sales are the > last two. > > This statement is at the end of script and is failing, but I don't know why. > Instead of die, it just goes on and gives the information in the row. > > > if(valid == "Invalid" || contact_sales == "1") > > die("There is a problem with your request. Please contact Sales at: > sales@mysite.com"); > try putting in brackets {} > $row = mysql_fetch_row($result); > echo $row[3] > > > As well...I am having another problem with this script. I know how to get > the information from 1 column as above, but I don't know how to display the > entire row. Is there a way to do this? > Make sure your sql query calls all the colums you want. I think that mysql_fetch_row should work fine, however I use mysql_fetch_assoc. > All My Best, > Jeffrey > > > | |||
| | #3 | ||
| On 11-Aug-2003, Jeffrey Ellis <support@groundlevel.net> wrote: > I have the following statement in my script, which is a simple script to > lookup data from a mysql database: > > I have several fields in the database, and valid and contact_sales are the > last two. > > This statement is at the end of script and is failing, but I don't know > why. > Instead of die, it just goes on and gives the information in the row. > > > if(valid == "Invalid" || contact_sales == "1") > > die("There is a problem with your request. Please contact Sales at: > sales@mysite.com"); > > $row = mysql_fetch_row($result); > echo $row[3] > > > As well...I am having another problem with this script. I know how to get > the information from 1 column as above, but I don't know how to display > the > entire row. Is there a way to do this? Add the leading $ to the variable names in your if if ($valid == 'Invalid' || $contact_sales == '1') You were actually getting column 4. You can get the data from the $row array by the column name, too. $row['valid'] or $row['contact_sales'], for example. If you want to use the column names as variables, you can use the extract function to copy the variables from the array $row into their scalar variable values, for example extract($row); would create variables $valid and $contact_sales and any other row names returned by the SQL select. as for displaying the entire contents of each row: echo '<table>'; while ($row = mysql_fetch_row($result)) { while (list($key,$value) = each($row)) { echo '<td>',$value,'</td>'; } echo '</tr>'; } echo '</table>'; I suspect some of this is new to you. I suggest reading the following http://www.php.net/manual/en/function.extract.php http://www.php.net/manual/en/function.each.php http://www.php.net/manual/en/function.list.php http://www.php.net/manual/en/ref.mysql.php http://www.php.net/manual/en/language.variables.php study the examples, everything you asked about is there. -- Tom Thackrey www.creative-light.com | |||
| | #4 | ||
| in article Ro0_a.717$eK7.343@newssvr25.news.prodigy.com, Tom Thackrey at tomnr@creative-light.com wrote on 8/12/03 12:09 AM: > > > On 11-Aug-2003, Jeffrey Ellis <support@groundlevel.net> wrote: > >> I have the following statement in my script, which is a simple script to >> lookup data from a mysql database: >> >> I have several fields in the database, and valid and contact_sales are the >> last two. >> >> This statement is at the end of script and is failing, but I don't know >> why. >> Instead of die, it just goes on and gives the information in the row. >> >> >> if(valid == "Invalid" || contact_sales == "1") >> >> die("There is a problem with your request. Please contact Sales at: >> sales@mysite.com"); >> >> $row = mysql_fetch_row($result); >> echo $row[3] >> >> >> As well...I am having another problem with this script. I know how to get >> the information from 1 column as above, but I don't know how to display >> the >> entire row. Is there a way to do this? > > Add the leading $ to the variable names in your if > if ($valid == 'Invalid' || $contact_sales == '1') Hi, Tom-- I thought variables were just for stored information from the form? In any case, I did try using $ for the if statement and it is still failing. > > You were actually getting column 4. You can get the data from the $row array > by the column name, too. $row['valid'] or $row['contact_sales'], for > example. > > If you want to use the column names as variables, you can use the extract > function to copy the variables from the array $row into their scalar > variable values, for example > extract($row); > would create variables $valid and $contact_sales and any other row names > returned by the SQL select. > > as for displaying the entire contents of each row: > echo '<table>'; > while ($row = mysql_fetch_row($result)) > { > while (list($key,$value) = each($row)) > { > echo '<td>',$value,'</td>'; > } > echo '</tr>'; > } > echo '</table>'; Thanks, I'll try that! > > I suspect some of this is new to you. I suggest reading the following > http://www.php.net/manual/en/function.extract.php > http://www.php.net/manual/en/function.each.php > http://www.php.net/manual/en/function.list.php > http://www.php.net/manual/en/ref.mysql.php > http://www.php.net/manual/en/language.variables.php > study the examples, everything you asked about is there. Yes, I've been reading them... Okay, I have also now been told that the error handling in the script is not working ( The if statement?) so that my web page is not displaying properly all the html after this script. This is what comes before and just after the script. Specifically what is happening is that my rollover graphics, which actually come before the php script, are not loading. In the following, only one of the buttons is shown... <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top" width="149" background="images/left-buttonbkg.gif"><a onmouseover="changeImages( /*CMP*/'button_home_up',/*URL*/'images/button-home-down.gif');return true" onmouseout="changeImages( /*CMP*/'button_home_up',/*URL*/'images/button-home-up.gif');return true" href="http://mysite.net/index.shtml"><img src="images/button-home-up.gif" alt="" name="button_home_up" width="149" height="40" border="0"></a><br> <br> <br> <br> <br> </td> <td valign="top"> <div align="center"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td bgcolor="white"> <div class="evenbigger"> <p class="evenbigger"><span class="evenbigger"><b>Registration Lookup</b><br> <br> </span></p> <?php if(empty($email) || empty($lastFour) ) This is the section at the end of the script: $result = mysql_query($dbQuery) or die("Couldn't get file list"); if($valid == "Invalid" || $contact_sales == "1") die("There is a problem with your request. Please contact Sales at: sales@mysite.net"); $row = mysql_fetch_row($result); ?> <b>Here is Your Registration Code:</b> <? echo $row[3] ?> </div> </td> </tr> </table> </div> </td> <td valign="top" width="195" background="images/right-textbkg.gif"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> All My Best, Jeffrey | |||
| Featured Websites | ||||
|
![]() |
| Tags: statement, working |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Find out key from Insert Statement | Erland Sommarskog | PHP | 0 | 07-01-2007 3:17 PM |
| Include statement | RA | HTML | 4 | 07-01-2007 1:45 PM |
| [Newby] help on a statement with both GROUP_CONCAT and JOIN clauses | Stefano Bragaglia | Database | 0 | 06-10-2007 12:25 AM |
| HOW TO : concat text fields using a GROUP BY statement ? | Fred | Database | 1 | 05-31-2007 8:41 PM |
| 2 where clause in same statement Mysql 4.2 | Xavier Houppertz | Database | 3 | 05-31-2007 8:40 PM |
| Featured Websites | ||||
|