Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Everything posted by wildteen88

  1. Use two = and not 1. Otherwise you'll be assign $num to the string '0'. WIth two equal signs you are comparing whats on the left to the right. [code=php:0]<? php $sql = "SELECT cart_id, stock_id, qty, price  FROM t01_cart WHERE cart_id = '".GetCartId()."' "; $result = mysql_query($sql, $dbLink) or die ('sql error<br />' . mysql_error()); if (mysql_num_rows($result) == 0) {     echo 'Your basket is empty';     echo $num; } ?>[/code]
  2. Looks like you have an error with your mod_rewrite rules then. mod_rewrite shouldnt stop your GET paramters from working, as it passes them with the rewrite rule. read my reply [url=http://www.phpfreaks.com/forums/index.php/topic,106374.msg425418.html#msg425418]here[/url]. I have closed that topic in the Apache forum too. Dont double post topics
  3. The result returned may have return two sets of results, however you are only echoing the first set. This code: [code]$row = mysql_fetch_array($result); echo sizeof($row);              -------------> shows 2 rows echo $row[0]; echo $row[1];    -------> error:'Undefined offset: 1'  why ?[/code] Whill only return the first row found by the query. if you want it to return all the rows you'll want to use a while loop [code]while($row = mysql_fetch_array($result)) echo $row[0] . '<br /><br />'; }[/code] Now it'll return the all the results from the query Also the reason why [code]echo sizeof($row);  [/code] returns two is because mysql_fetch_array returns the results into different arrays, numrical indecies ($row[0]) or associative indices ($row['submit'])
  4. [quote author=obsidian link=topic=106306.msg425315#msg425315 date=1157027534] [quote author=fenway link=topic=106306.msg425142#msg425142 date=1156996445] Wow... not a single mention of DB. [/quote] ??? [/quote]obsidian This got moved from MySQL Help. fenway posted that message before I moved it
  5. What is the your mod rewrite code you're using. You should still be able to access the id parameter in your code when using mod_rewrite. Your mod rewrite should be something like this: [code]RewriteRule ^images/([0-9]+)$ images?id=$1[/code]
  6. look into mod rewrite. Following should do the trick: [code]RewriteEngine On RewriteRule ^([a-zA-Z])$ /a/$1[/code] What this will do is serve whats in a/folderLetterHERE. For example when do www.atkherm.com/e it'll server whats in atkherm.com/a/e
  7. Do you have script tags in your code? If you do add a space around script.
  8. Use file_get_contents if you wenat to store the content of the file in a variable.
  9. Post your code to pastebin.com and provide a link to your posted code instead.
  10. Do you have script tags in the code? Some html/php code causes this due to a secrity script running on the server. If its a script tag ad spaces around the brakets eg: [code]< script >code here< /script >[/code]
  11. He wants to create a HTML file from the output generated from the query. He doesnt want to display results from the script that runs the query. Which is what my code above does.
  12. Okay use this: [code]$htmlCode = <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>   <title>Unititled Document</title> </head> <body> HTML; $row = mysql_fetch_array($result); $name = $row['firstname'] . '_' . $row['lastname']; $htmlCode .= <<<HTML <b>{$name}</b><br /> <b>User ID:</b> {$row['userid']}<br /> <b>First Name:</b> {$row['firstname']}<br /> <b>Last Name:</b> {$row['Lastname']}<br /> <b>Email Address:</b> {$row['email']} </body> </html> HTML; // create the HTML File // the html file will be name: // fistname_lastname.html $htmlFile = fopen($name . '.html', "w+"); // write to the html file fwrite($htmlFile, $htmlCode, strlen($htmlCode)); // now we close the file fclose($htmlFile); echo "HTML file created!<br />\n<br />\n<a href=\"{$name}.html\">{$name}.html</a>";[/code] instead of the following: [code]while($row = mysql_fetch_array($result))   {   echo $row['firstname'] . " " . $row['lastname'];   echo " ";   }[/code] NOTE: This code is untested, so it may return errors.
  13. You dont need quotes around club_data, that is fine on its own as its the table name. You only use quotes around the columns values. So use this as the query: [code]UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'[/code] If I put quotes around club_data then I apologiese fro my mistake.
  14. Swap if (isset($user_name)) to if (!isset($user_name)) notice the ! before isset
  15. Add [code]mysql_select_db($database_intranet, $intranet);[/code] after [code]$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);[/code]
  16. Without echo nothing will be outputted. So you'll need to use echo to generate the html. or do you ant to create an HTML file with the output of the query?
  17. Run the function phpinfo in a script, scroll down to find the  Apache Environment heading. Under that will be the list of server variables. Or goto the PHP Variables heading to find the _SERVER variables.
  18. Diod you read this bit of my post above: [quote]Also this code here: else   {     if (isset($user_name))     {       // if they've tried and failed to log in       echo 'Could not log you in';     }     else     {       // they have not tried to log in yet or have logged out       echo 'You are not logged in.<br />';     } Is a little strange. You are checking to see if $user_name exists, and if it does you say you cannot be logged in. Shouldnt this if (isset($user_name)) be if (!isset($user_name)) Otherwise if the user fills in the form correctly and hits submits it always goona say 'Could not log you in'. With the latter code it now checks whether the $user_name var doesnt exist.[/quote]
  19. Post the code from casestudies.php on lines 96 through to 100 here
  20. Glad you got it worked out. However you didnt actually need the foreach loop, all you needed to do is define you variables. Fo example. [code]$cu_s_number = mysql_real_escape_string($_POST['cu_s_number']);[/code] And your for loop will work. Here is (probably unneded) code: [code]<?php //Include Connection information include("include/connection.php"); $test_name = mysql_real_escape_string($_POST['test_name']); //Get the Test id for new info $sql_get_id = "SELECT test_id FROM test_info WHERE test_name = '$test_name'"; $qry_get_id = mysql_query($sql_get_id, $connection) or die ("Could not get the proper info"); $test_id = mysql_fetch_array($qry_get_id); $cu_s_number = mysql_real_escape_string($_POST['cu_s_number']); $cu_s_sample = mysql_real_escape_string($_POST['cu_s_sample']); $cu_s_wt = mysql_real_escape_string($_POST['cu_s_wt']); $cu_s_tare = mysql_real_escape_string($_POST['cu_s_tare']); $cu_s_poste = mysql_real_escape_string($_POST['cu_s_post']); $cu_s_diff_value = mysql_real_escape_string($_POST['cu_s_diff_value']); for ($i = 1; $i <= $cu_s_number; $i++) {     //Insert information in the correct table $sql_insert_cu_s = "INSERT INTO cu_s (test_id, cu_s_sample, cu_s_wt, cu_s_tare, cu_s_post)                         VALUES ('$test_id', '$cu_s_sample[$i]', '$cu_s_wt[$i]', '$cu_s_tare[$i]', '$cu_s_post[$i]')";     //Run Query $qry_insert_cu_s = mysql_query($sql_insert_cu_s, $connection) or die ("Can not execute insert Query"); //Calculations for Cu Liquids     $diff_formatted[$i] = number_format($cu_s_diff_value[$i], 4);     if ($_POST['cu_s_wt'][$i] == '0' or $_POST['cu_s_wt'][$i] == null)     {     $cu_per_formatted[$i] = "DIV/0"; }     else     {     $cu_per_value[$i] = ($cu_s_diff_value[$i] / $_POST['cu_s_wt'][$i]) * 100; $cu_per_formatted[$i] = number_format($cu_per_value[$i], 1); } } $display_block .= <<<HTML <br> <table border="1" cellspacing="1"> <tr> <th colspan="6" align="center">Copper (Solids)</th> </tr> <tr> <td>&nbsp;&nbsp;Sample&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;&nbsp;&nbsp;Weight&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tare&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Post&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Diff.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>Copper (%)</td> </tr> HTML; // DO NOT INDENT ABOVE LINE! for ($i = 1; $i <= $cu_s_number; $i++) {     $display_block .= <<<HTML <tr> <td align="center">{$cu_s_sample[$i]}</td> <td align="center">{$cu_s_wt[$i]}</td> <td align="center">{$cu_s_tare[$i]}</td> <td align="center">{$cu_s_post[$i]}</td> <td align="center">{$diff_formatted[$i]}</td> <td align="center">{$cu_per_formatted[$i]}</td> </tr> HTML; // DO NOT INDENT ABOVE LINE! } $display_block .= "</table>"; ?>[/code]
  21. I think I know whats happing. You are setting up your query before you define the variables you use in your query. The query should be defined before this: [code=php:0]if(mysql_query($sqlqup))[/code] This si what your code should be: [code]<?php $hostname_intranet = "localhost"; $database_intranet = "intranet"; $username_intranet = "root"; $password_intranet = "***"; $intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR); if(isset($_POST['Submit_1'])) {     $gethead = $_POST['head']; $getteacher = $_POST['teacher']; $getnews = $_POST['news']; $getmessage = $_POST['message']; $getmembers = $_POST['members']; $error = "";     if($gethead =="") $error.="*Please enter a head"."<br>"; if($getteacher=="") $error.="*Please enter a Teacher"."<br>"; if($getnews=="") $error.="*Please enter some news"."<br>"; if($getmessage=="") $error.="*Please enter a message"."<br>"; if($getmembers=="") $error.="*Please enter the members of this club"."<br>"; if(isset($errro))     {         $sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'";         if(mysql_query($sqlqup)) {         echo " Club page updated ";     echo '<hr>';     echo 'head:'; echo $gethead; echo '<hr>'; echo 'Teacher:'; echo $getteacher; echo '<hr>'; echo 'News:'; echo $getnews; echo '<hr>'; echo 'Message:'; echo $getmessage; echo '<hr>'; echo 'Members'; echo $getmembers; echo '<hr>'; }   else         {     echo " Failed to upadate"; } } else     {         echo "<div align='center'>". $error ."</div>"; } } else {     $sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'";     $mclubqu = mysql_query($sqlview);     $club = mysql_fetch_array($mclubqu); ?>   <div align="center">     <h1><? echo $club['Club']?> Club</h1>       <form action="" method="POST">   <table width="588"  border="1.2">     <tr>       <td width="95">Head</td>   <td width="7">&nbsp;</td>         <td width="302"><input name="head" type="text"/></td>   <td width="166"><? echo $club['Head']?> </td>     </tr>         <tr>       <td>Teacher</td>   <td>&nbsp;</td>       <td><input name="teacher" type="text"/></td>   <td><? echo $club['Teacher']?> </td>     </tr>     <tr>       <td>News</td>   <td>&nbsp;</td>       <td><textarea name="news" cols="40" rows="10"></textarea></td>   <td><? echo $club['News']?> </td>     </tr>   <tr>       <td>Message</td>   <td>&nbsp;</td>       <td><textarea name="message" cols="40" rows="10"></textarea></td>   <td><? echo $club['Message']?> </td>     </tr>   <tr>       <td>Members</td>   <td>&nbsp;</td>         <td><textarea name="members" cols="40" rows="10"></textarea></td>   <td><? echo $club['members']?> </td>     </tr>   </tr>   <tr>       <td>&nbsp;</td>   <td>&nbsp;</td>       <td><center><input type="submit" name="Submit_1" value="Submit" /> </center> </td>     <td>&nbsp;</td>   </tr>   </table> </form>     </div> <?php } ?>[/code]
  22. It connects to mysql and selects the database vwso. If mysql_connect or mysql_select_db fail the or die clause will kick in and display the mysql error. Click the links below to learn how to use these functions [url=http://php.net/mysql-connect]mysql_connect[/url] [url=http://php.net/mysql-select-db]mysql_select_db[/url]
  23. I cant see any code that is relvent to the code you posted in your first post. So I'm assuming the following is the code you are having difficulty with: [code=php:0] for ($i = 1; $i <= $_POST[cu_s_number]; $i++){ $display_block .= " <tr> <td align='center'>$cu_s_sample[$i]</td> <td align='center'>$cu_s_wt[$i]</td> <td align='center'>$cu_s_tare[$i]</td> <td align='center'>$cu_s_post[$i]</td> <td align='center'>$diff_formatted[$i]</td> <td align='center'>$cu_per_formatted[$i]</td> </tr>"; }[/code] is that the code you are having problems with.
  24. So this should work fine: [code=php:0]$i = 1; foreach($_POST['co2_s_sample'] as $co2_example) {     echo '<td align="center">' . $co2_example . '</td> <td align="center"> ' $_POST['test_type'][$i] . "</td>\n"; $i++; }[/code] Did you try it? The format of the array is fine.
  25. AFAIK without a recent SQL dump/backup you cannot roll back. Check with your host they automatically do database backups. If they do see if they have a recent backup you could use.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.