PHP - Unable To Create Temp Table In Proc.
Have any of you ever run into this one. Can't quite figure this one out.
Error Code: 1064. 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 'DECLARE cUserID INT; DECLARE done INT DEFAULT FALSE; DECLARE CUR1 CURSOR FOR ' at line 9
Similar TutorialsHow would I create a prepared mysql temp table using PHP? I currently write my prepared statements like the example below. How would I create a "TEMP" table? Thanks!
$connection8y = new mysqli("host", "xxx", "xxx", "db"); Hello everyone !!! I am sorry if my vocabulary is not exact because english is not my first language. Also i am a newbie at PHP. I am doing this project for myself and if it work might be able to use it at work. But i am doing this to learn. I have been stuck on this problem for 2 weeks and i can t figure it out on my own. Ihave spend many hours searching forums but no success. Oh yeah i almost forgot some part of code are from me, some are scripts from internet i adapted. I have a form with a dropdown menu and when i submit the form the value selected in the dropdown would be inserted in a table. The problem i have is that whatever the value i select it always inserts the last value of the dropdown in the table??? The form is made with the dropdown as an include. It is populated with values from an another table. Here is the code for the dropdown list: Code: [Select] <form> <select name="nom_pcu_form" method="post"> <?php $SQL = "SELECT * FROM pcu ORDER BY nom_pcu"; $res = mysql_query($SQL); while($val=mysql_fetch_array($res)) { $nom=$val["nom_pcu"]; $prenom=$val["prenom_pcu"]; $nom_complet = $prenom . $nom; echo "<option>".$val["nom_pcu"].", ".$val["prenom_pcu"]."</option>\n"; $nom_pcu_form="".$val["nom_pcu"].", ".$val["prenom_pcu"].""; } ?> </select> </form> Here is the part of the form wich calls the dropdown: Code: [Select] <form name="form2" method="post" action="Grille ecoute Permanent.php"> <p>Nom : <?php include 'liste_deroulante_pcu.php' ;?> <p>no carte appel <input name="no_carte_appel" type="text" id="no_carte_appel"> </p> <?php echo date("Y/m/d"); ?> </form> And this is the part where it is inserted in the table: Code: [Select] <?php if($_POST['doSubmit'] == 'Create') mysql_query("INSERT INTO grille_ecoute_pcu_permanent (`user_name`,`nom_pcu`,`no_carte_appel`,`question_1`,`question_2`,`question_3`,`question_4`, `question_5`,`question_6`,`question_7`,`question_8`,`question_9`,`question_10`,`question_11`,`question_12`,`question_13`,`question_14`,`question_15`, `question_16`,`question_17`,`question_18`,`question_19`,`question_20`,`question_21`,`question_22`,`question_23`,`question_24`,`question_25`,`question_26`, `question_27`,`question_28`,`question_29`) VALUES ('$user_name','$nom_pcu_form','$no_carte_appel','$question_1','$question_2','$question_3','$question_4','$question_5','$question_6', '$question_7','$question_8','$question_9','$question_10','$question_11','$question_12','$question_13','$question_14','$question_15','$question_16','$question_17', '$question_18','$question_19','$question_20','$question_21','$question_22','$question_23','$question_24','$question_25','$question_26','$question_27','$question_28', '$question_29') ") or die(mysql_error()); Note:$user_name and all $question are inserted correctly in the table. $nom_pcu_form is the dropdown and it only records the last value of the dropdown even if it s not the value selected. $no_carte_appel are not recorded at all thanks for your time I'm working on creating a Realtors website. Currently mysql DB has 4 tables. 3 of them are needed in this script to show up as 1 item. Table called Listings has 2 fields that call on 2 other tables. one is MLS which calls on the Images Table the other agent calls on the Agents table. I'm trying to see why I can't While loop all 3 tables together? How can I connect all 3? <?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": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } //mysql_select_db($database_CarneyRealty, $CarneyRealty); //$query_Update1 = "SELECT * FROM listings"; //$Update1 = mysql_query($query_Update1, $CarneyRealty) or die(mysql_error()); //$rrows = mysql_fetch_assoc($Update1); //$totalRows_Update1 = mysql_num_rows($Update1); include 'dbc.php'; page_protect(); $err = array(); $msg = array(); $page_limit =4; //CHANGE FOR THE NUMBER OF LISTINGS PER PAGE! $page_num_limit =10; $ret = $_SERVER['HTTP_REFERER']; $host = $_SERVER['HTTP_HOST']; $host_upper = strtoupper($host); $login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF'])); $path = rtrim($login_path, '/\\'); // filter GET values foreach($_GET as $key => $value) { $get[$key] = filter($value); } foreach($_POST as $key => $value) { $post[$key] = filter($value); } $rs_all = mysql_query("select count(*) as total_all from listings") or die(mysql_error()); $rs_active = mysql_query("select count(*) as total_active from listings where status='ACTIVE'") or die(mysql_error()); $rs_total_contingent = mysql_query("select count(*) as tot2 from listings where status='CONTINGENT'"); $rs_total_pending = mysql_query("select count(*) as tot from listings where status='PENDING'"); $rs_total_sold = mysql_query("select count(*) as tot1 from listings where status='SOLD'"); $rs_resall = mysql_query("select count(*) as res from listings where class='Resident'") or die(mysql_error()); $rs_comall = mysql_query("select count(*) as com from listings where class='Commerical'"); $rs_farmall = mysql_query("select count(*) as farm from listings where class='Farmland'"); $rs_otherall = mysql_query("select count(*) as other from listings where class='Other'"); list($all) = mysql_fetch_row($rs_all); list($active) = mysql_fetch_row($rs_active); list($total_contingent) = mysql_fetch_row($rs_total_contingent); list($total_pending) = mysql_fetch_row($rs_total_pending); list($total_sold) = mysql_fetch_row($rs_total_sold); list($resall) = mysql_fetch_row($rs_resall); list($comall) = mysql_fetch_row($rs_comall); list($farmall) = mysql_fetch_row($rs_farmall); list($otherall) = mysql_fetch_row($rs_otherall); /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// $sqlagents = mysql_query("select * from agents where id='$_SESSION'"); //$agentname= mysql_query($sqlagents) or die(mysql_error()); $sqllistings = mysql_query("select * from listings where id='$_SESSION'"); $sqlimages = mysql_query("select * from images where id='$_SESSION'"); //////////////////////////////////////////////////////////////////////////////////////////////////////// ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Search CarneyRealty Listings</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="../css/mm_brochure.css" type="text/css"> <style type="text/css"> <!-- body { background-image: url(http://www.carneyrealty.com/newsite/images/IMG_0161a.jpg); } .style1 { font-size: 16px } .style2 { font-family: Geneva, Arial, Helvetica, sans-serif } .style10 { font-size: 13px; font-weight: bold; color: #FF0000; } .style7 { color: #FF0000; font-weight: bold; } .style8 { color: #0000FF; font-weight: bold; } --> </style> </head> <body bgcolor="#bcbc85" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <div align="center"> <table width="81%" border="0" cellspacing="0" cellpadding="0"> <tr bgcolor="#999966"> <td width="25" nowrap="nowrap"><center> <img src="../images/mm_spacer.gif" alt="" width="15" height="1" border="0" /></td> <td height="60" colspan="3" class="logo" nowrap="nowrap"><div align="center"><img src="images/Carney_Logo1_000.jpg" width="630" height="158" /><br /> </div></td> <td width="4"></td> </tr> <tr bgcolor="#797947"> <td width="25" nowrap="nowrap"></td> <td colspan="3" valign="top"><div align="center"> <table width="460" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="59" align="center" nowrap="nowrap"><div align="center"><a href="../index.htm" class="style1"><strong>HOME</a></div></td> <td width="127" align="center" nowrap="nowrap"><div align="center"><strong><a href="../SearchCarneyRealtyListings.php" class="style5">LISTINGSEARCH</a></strong></div></td> <td width="94" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Aboutus.html" class="style5">ABOUT US</a></strong></div></td> <td width="10" align="center" nowrap="nowrap"><div align="center"></div></td> <td width="95" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Community.htm" class="style5">COMMUNITY </a></strong></div></td> <td width="81" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Login.php" class="style5">LOGIN</a></strong></div></td> </tr> </table> <table width="307" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="84" align="center" nowrap="nowrap"><div align="center"><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Resident" class="style1">Residential</a></div></td> <td width="103" align="center" nowrap="nowrap"><div align="center"><strong><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Commerical" class="style5">Commercial</a></strong></div></td> <td width="102" align="center" nowrap="nowrap"><div align="center"><strong><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Farmland" class="style5">Farms & Land</a></strong></div></td> <td width="18" align="center" nowrap="nowrap"><div align="center"></div></td> </tr> </table> <table width="573" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="72" align="center" nowrap="nowrap"><div align="center"><a href="residental0-60.php" class="style1">$0-$60K</a></div></td> <td width="80" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental61-85.php" class="style5">$61K-$85K</a></strong></div></td> <td width="87" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental86-115.php" class="style5">$86K-$115K</a></strong></div></td> <td width="1" align="center" nowrap="nowrap"><div align="center"></div></td> <td width="103" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental116-160.php" class="style5">$116K-$160K</a></strong></div></td> <td width="93" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental161-230.php" class="style5">$161K-230K</a></strong></div></td> <td width="126" align="center" nowrap="nowrap"><div align="center"><strong><a href="residential231up.php" class="style5">$231K-And Up</a></strong></div></td> <td width="11" align="center" nowrap="nowrap"> </td> </tr> </table> </div></td> </tr> <td width="25" valign="top"><?php /*********************** MY MLS MENU **************************** This code shows MLS account menu only to logged in users. Copy this code till END and place it in a new html or php where you want to show myaccount options. This is only visible to logged in users *******************************************************************/ ?> <?php if(!empty($msg)) { echo $msg[0]; } ?> <? //$row_settings1=mysql_fetch_array($sqllistings1);?> <?php while ($row_settings1 = mysql_fetch_array($sqllistings)){ $row_settings2=mysql_fetch_array($sqlimages); $row_settings3=mysql_fetch_array($sqlagents); ?> <?php } ?> </table> <table width="81%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color: #FF9933;padding: 2px 5px;border: 1px solid #F90;" > <tr> <td height="44" align="center"><form name="form1" method="get" action="listingsearch.php"> <p> <input name="doSearch" type="submit" id="doSearch2" value="MLS Search" /> <input name="q" type="text" id="q" size="40"> <strong> S CARNEY& ASSOCIATES INC 800-757-5783</strong> <br> </p> </form></td> </tr> </table> </td> </tr> </table> </div> <p> <?php if ($get['doSearch'] == 'MLS Search') { $cond = ''; if($get['qoption'] == 'active') { $cond = "where `status`='ACTIVE' order by date desc"; } if($get['qoption'] == 'contingent') { $cond = "where `status`='CONTINGENT' order by date desc"; } if($get['qoption'] == 'pending') { $cond = "where `status`='PENDING' order by date desc"; } if($get['qoption'] == 'sold') { $cond = "where `status`='SOLD' order by date desc"; } if($get['qoption'] == 'resident') { $cond = "where `class`='Resident' order by price desc"; } if($get['qoption'] == 'farmland') { $cond = "where `class`='Farmland' order by price desc"; } if($get['qoption'] == 'commerical') { $cond = "where `class`='Commerical' order by price desc"; } if($get['qoption'] == 'other') { $cond = "where `class`='Other' order by price desc"; } //if($get['qoption'] == '') { if($get['q'] == '') { $sql = "select * from listings order by price asc"; // $sql = "select * from listings $cond"; // } } else { $sql = "select * from listings where `price` = '$_REQUEST[q]' or `mls`='$_REQUEST[q]' or `seller`='$_REQUEST[q]' or `class`='$_REQUEST[q]' or `status`='$_REQUEST[q]' order by `price` asc"; //$sql1="select * from images where `mls`='$sql'"; //$sql2="select * from agents where `tag`='$sql'"; // $sql = "select * from listings where `mls`='$_REQUEST[q]' or `price`='$_REQUEST[q]'"; } //$rs_total1=mysql_query($sql1) or die(mysql_error()); $rs_total = mysql_query($sql) or die(mysql_error()); $total = mysql_num_rows($rs_total); // $total1=mysql_num_rows($rs_total1); if (!isset($_GET['page']) ) { $start=0; } else { $start = ($_GET['page'] - 1) * $page_limit; } $rs_results = mysql_query($sql . " limit $start,$page_limit") or die(mysql_error()); $total_pages = ceil($total/$page_limit); // $rs_results1 = mysql_query($sql1 ."limit $start,$page_limit") or die (mysql_error()); ?> <?php // outputting the pages if ($total > $page_num_limit) { echo "<table width='81%' border='0' align='center' cellpadding='2' cellspacing='0' background='#fcfcdd'><span class='subHeader'><center>Pages: "; $i = 0; while ($i < $page_num_limit) { $page_no = $i+1; $qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']); echo "<a href=\"listingsearch.php?$qstr&page=$page_no\">$page_no</a> "; $i++; } echo "</span></td></table>"; } ?> <? //while ($rrows3 = mysql_fetch_array($rrows3)){ ?> <form name "searchform" action="listingsearch.php" method="post"> </form> </table> <?php ////////////////////////////////////////////////////////////////////////////// while ($rrows = mysql_fetch_array($rs_results)) { $rrows2=mysql_fetch_array($sqlimages); $rrows3=mysql_fetch_array($sqlagents); /////////////////////////////////////////////////////////////////////////////// //$imagenamevar=($rrows['mls']=$rrows2['mls']); //echo $rrows3['id']; //$agentpicvar=($rrows['seller']=$rrow3['tag']); ?> <tr> <table width="81%" border="0" align="center" cellpadding="2" cellspacing="0" background="#fcfcdd"> <? echo $rrows['agents'.'seller_id'];?> <td width="161" height="211" align="center" valign="top" bgcolor="#fcfcdd"><div align="center"><img src="http://www.carneyrealty.com/newsite/uploads/<?php echo $rrows['mls'];?>/<? echo $mainimagevar; ?> width="214" height="160" /> </p> </div> <p class="tagline">Click for Additional Pictures</p></td> <td width="568" align="center" valign="top" bgcolor="#fcfcdd" class="calendarText"><div align="left"> <table width="592" height="180" border="1"> <tr valign="top"> <td width="74" height="27" bgcolor="#fcfcdd" class="tagline">Location </td> <td width="249" bgcolor="#fcfcdd"><strong><?php echo $rrows['location'];?> <br> <? echo $rrows['location1'];?> <br> <? echo $rrows3['tag'];?> </strong></td> <td width="180" rowspan="2" bgcolor="#fcfcdd" class="tagline"><div align="center"> <table width="180" height="62" border="1"> <tr valign="top"> <td width="70" rowspan="2" class="tagline"><a href="http://www.carneyrealty.com/newsite/upload/<?php echo $rrows['mls'];?>/<? echo "SD_disp.pdf";?>"><img align="absbottom" src="http://www.carneyrealty.com/newsite/Listing_pages/images/datasheet_018.jpg" width="58" height="50" /></a></td> <td width="50" class="tagline"><div align="left">Status </div></td> <td width="68"><div align="right" class="subHeader"><?php echo $rrows['status']; ?></div></td> </tr> <tr valign="top"> <td height="24" class="tagline"><div align="left">PRICE</div></td> <td align="center" valign="top"><div align="right"><strong class="subHeader"><?php echo $rrows['price']; ?></strong></div></td> </tr> </table> <span style="color: #fcfcdd"><strong><a href="mailto:<? echo $rrows['selleremail'];?>"><img src="http://www.carneyrealty.com/newsite/Listing_pages/images/mail_004.gif" width="14" height="15" /><? echo $rrows['seller'];?></a></strong></span></div></td> <td width="61" rowspan="2" bgcolor="#fcfcdd" class="tagline"><div align="right"></div> <span style="color: #fcfcdd"><img src="<? ///////////////////////////////////////////////////////////// while ($rrows3=($rrows['seller']=$rrows3['seller_id'])){ echo $rrows3['agentimage']; } ////////////////////////////////////////////////////////////// ?>" width="60" height="91" /></a></span></td> </tr> <tr valign="top"> <td height="64" bgcolor="#fcfcdd" class="tagline">Specs</td> <td bgcolor="#fcfcdd"><strong><?php echo $rrows['specs']; ?></strong></td> </tr> <tr valign="top"> <td height="77" bgcolor="#fcfcdd" class="tagline">Description</td> <td colspan="3" bgcolor="#fcfcdd" ><strong>MLS #<?php echo $rrows['mls'];?><br> <? echo $rrows['description'];?></strong> <p><strong>Call <? echo $rrows['seller'];?> at <? echo agentnumbervar;?> to view or for more information.</strong></p></td> </tr> </table> <tr> <td height="18" colspan="2" align="center" valign="top" bgcolor="#FF9933"><span class="bodyText style2" style="color: #fcfcdd"></span><span class="bodyText style2">S Carney & Associates Real Estate Brokerage 800 757 5783 </span></td> </tr> </div></td> </tr> </span> <? } ?> <td height="4"></td> </table> <? } ?> <? //} ?> </tr> <?php // outputting the pages if ($total > $page_limit) { echo "<table width='81%' border='0' align='center' cellpadding='2' cellspacing='0' background='#fcfcdd'><span class='subHeader'><center>Pages: "; $i = 0; while ($i < $page_num_limit) { $page_no = $i+1; $qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']); echo "<a href=\"listings.php?$qstr&page=$page_no\">$page_no</a> "; $i++; } echo "</span></td></table>"; } ?> </td> </tr> <tr> <td height="22" class="bodyText"><? include 'footer1.shtml'; ?> </td> </tr> <tr> <td height="194" class="bodyText"><div align="center"> <table width="513" border="0"> <tr valign="top"> <th width="94" scope="col"><div align="center"><a href="http://www.realtor.org/technology/crt_secure/home?opendocument"><img src="images/index.1.gif" width="43" height="42" border="0" /></a></div></th> <th width="46" scope="col"><div align="center"></div></th> <th width="100" valign="middle" scope="col"><div align="center" class="style7"> <div align="center"><a href="http://www.nacogdochesmls.com/nag/passwd.php"><img src="images/MLS_a_94-50.gif" width="92" height="51" alt="Multiple Listing Service" /></a></div> </div></th> <th width="119" scope="col"><div align="center"><a href="http://www.hud.gov/offices/fheo/FHLaws/"><img src="http://www.habitatwhitley.org/equal_housing_logo.jpg" alt="Equal Housing Opportunity" width="60" height="62" border="0" /></a></div></th> <th width="129" scope="col"><div align="center"></div></th> </tr> <tr valign="top"> <td height="32"><div align="center" class="style8"><a href="http://www.realtor.org/technology/crt_secure/home?opendocument">REALTOR.ORG</a></div></td> <td><div align="center"></div></td> <td valign="middle"><div align="center"><span class="style10"><a href="http://www.nacogdochesmls.com/nag/passwd.php">Multiple Listing System</a></span></div></td> <td><div align="center"><strong><a href="http://www.hud.gov/offices/fheo/FHLaws/">Equal Housing Opportunity</a></strong></div></td> <td><div align="center"><a href="http://www.bbb.org/">BETTER BUSINESS BUREAU</a></div></td> </tr> </table> </div></td> </tr> </table> <div align="left"> <br /> </div> </div> </td> <td valign="top"><div align="left"></div></td> <td width="4"><div align="left"></div></td> </tr> <tr> <td width="15"> </td> <td width="35"> </td> <td width="698"><div align="center"> <?php include 'footer.shtml'; ?> </div> </td> <td width="1"><div align="center"></div></td> <td width="4"> </td> </tr> </table> </table> </table> </div> </body> </html> Hi, I need some help here, the one which I have highlighted in red, 'dob' and 'gender', are not inputting any values into my database table. I'm just wondering did I miss out something important, or should I change the 'type' in my database table? Thanks <?php $dob = $_POST['dob']; $gender = $_POST['gender']; /**INSERT into tutor_profile table**/ $query2 = "INSERT INTO tutor_profile (name, nric, dob, gender, race) VALUES ('$name', '$nric', '$dob', '$gender', '$race')"; $results2 = mysqli_query($dbc, $query2) or die(mysqli_error()); ?> <html> <div> <label for="dob" class="label">Date Of Birth</label> <input name="dob" type="text" id="dob"/> </div> </html> <!--Race--> <div> <label for="race" class="label">Race</label> <?php echo '<select name="race" id="race"> <option value="">--Please select one--</option>'; $dbc = mysqli_connect('localhost', '111', '111', '111') or die(mysqli_error()); $query = ("SELECT * FROM race ORDER BY race_id ASC"); $sql = mysqli_query($dbc, $query) or die(mysqli_error()); while($data = mysqli_fetch_array($sql)) { echo'<option value="'.$data['race_id'].'">'.$data['race_name'].'</option>'; } echo '</select><br/>'; mysqli_close($dbc); ?> </div> From the beginning, the user accesses my website and uploads an image. Currently I'm using SimpleImage.php available at http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php to resize uploaded pictures. I create two copies, a regular size and a thumbnail size. Then I transfer the converted files through FTP to my storage server. The regular size works great, but the thumbnail transfers as a blank file. I don't want to save the files on the non-storage server at all, so I'm trying to work with temporary files. include('./SimpleImage.php'); // A few variables $file_name = basename($_FILES['photo1']['name']); $random_digit=mt_rand(111111111,2147483647); // New file name $new_file_name = $userInfo['id'].'_'.$random_digit.$random_digit.'_'.substr($file_name, -5); // Paths to temporary files $target_path = $_FILES['photo1']['tmp_name']; $thumb_path = tmpfile(); // Start SimpleImage and load temp file $simImage = new SimpleImage(); $simImage->load($target_path); // Get the temp image dimensions list($width, $height) = getimagesize($target_path); // Resize the file if it's too tall if ($height > $var['maxPhotoHeight']) { $simImage->resizeToHeight($var['maxPhotoHeight']); $simImage->save($target_path); } // Get the newly resized image dimensions list($width, $height) = getimagesize($target_path); // Resize the image if it's too wide if ($width > $var['maxPhotoWidth']) { $simImage->resizeToWidth($var['maxPhotoWidth']); $simImage->save($target_path); } // Resize for thumbnail width $simImage->resizeToWidth($var['thumbWidth']); $simImage->save($thumb_path); // Get thumbnail dimensions list($width, $height) = getimagesize($thumb_path); // Resize the thumbnail if it's too tall if ($height > $var['thumbHeight']) { $simImage->resizeToHeight($var['thumbHeight']); $simImage->save($thumb_path); } // Was told this was important, but I've tried with and without it and got the same result fseek($thumb_path,0); // Perform File Transfer ftpTransfer($target_path, "$new_file_name"); ftpTransfer($thumb_path, "thumbs/$new_file_name"); // My Simple FTP Transfer Function: function ftpTransfer($source, $name) { global $ftp; $ftpMeta = "ftp://" . $ftp['user_name'] . ":" . $ftp['user_pass'] . "@" . $ftp['server'] . $ftp['dir'] . $name; $ftpData = file_get_contents($source); file_put_contents($ftpMeta, $ftpData); } Like I said, the regular sized image works great!! the thumbnail file is only created on the storage server but it has a 0kb file size. I'm sure it has to do with me working with a temporary file. tmpfile() claims to remove the file after it's closed, so maybe by using the Save feature in SimpleImage, it's closing the file and then the server automatically removes the temporary file? SimpleImage has a feature where I can write the image output [possibly to a file] using $simImage->output() for the data. If that helps with a solution? I don't know. I know it might be complicated, but any help is appreciated! I set up functionality for a client that got moved to their server after I wrote and tested the functionality. It does not work on their server and I am trying to trouble shoot the problem as I do not have ftp access to the server.
I believe that I have narrowed it down to either I do not know how to access the temp files on their server, Windows IIS, OR the security on the server is not allowing me to upload to the temp files.
Here is the form used to upload to the server.
<form enctype="multipart/form-data" action="#" method="post" > <input type="hidden" name="upload_csv" value="TRUE" /> <p><label for="userfile">Upload CSV:</label> <input type="hidden" name="MAX_FILE_SIZE" value="45000000" /> <input type="file" id="userfile" name="userfile" title="userfile" value="" /></p> <p><input type="submit" name="upload_csv" value="Upload CSV" /></p> </form> Here is the test code: <?php $csvfile = $_FILES['userfile']['tmp_name']; $size = $_FILES['userfile']['size']; if($_POST['upload_csv']){ //---------------------------------validation code here if($problem){ echo '<div class="error">Did not pass validation</div>'; include("upload_csv.inc.php"); }else{ if (($handle = fopen($csvfile, "r")) !== FALSE) { //--------------------------------------------------------------this is where the code that imports the data from the csv and to the database goes echo '<div class="message"><p>CSV has been opened!</p></div>'; }elseif(!$csvfile){ echo '<div class="error">Problem #1</div>'; }else{ echo '<div class="error">Problem #2</div>'; } } }else{ include("upload_csv.inc.php"); } ?> This code generated the error message: Problem #2. One more bit of information: the permissions on the server is set so that nothing can be uploaded by an external script. I do not know much about servers, but it seems to me that because the security is so tight on the server, the security is the reason that this does not work...??? I appreciate help with this. I just am not knowledgeable on how the $_FILES['userfile']['tmp_name'] code actually works? I am trying to split a simple string from my db it is in the format #/# 1/5 2/5 3/3 4/2 etc... I have the following: Code: [Select] echo $value.'<BR>'; $temp=explode('/',$value['field']); print_r($temp); echo '<br>'; when I execute the above (it's in a for loop) I get the following output 1/5 Array ( => 1 ) 2/5 Array ( => 2 ) 3/3 Array ( => 3 ) 4/2 Array ( => 4 ) I am expecting 1/5 Array ( => 1 [1] => 5) for the first entry and so on down the line showing both values after the explode. I'm trying to figure out how to create a temporary table of a query join, so I can paginate the results. I kind of made half of this up as i was going along - which is dangerous for a beginner like me. I'm getting this error, and no results on the page: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 179 also, is there a way to combine the two queries (create temp and insert from/into) Code: [Select] $sql2 = "CREATE TEMPORARY TABLE temp_search (plant_id INT PRIMARY KEY AUTO_INCREMENT, scientific_name VARCHAR(75), common_name VARCHAR(75), leaf_shape VARCHAR(75))"; $sqlx = "SELECT descriptors.leaf_shape ,plantae.scientific_name, plantae.common_name FROM descriptors INNER JOIN plantae ON (descriptors.plant_id = plantae.plant_name) WHERE descriptors.leaf_shape LIKE 'auriculate' AND descriptors.leaf_venation LIKE '%$select3%' AND descriptors.leaf_margin LIKE '%$select4%' INTO temp_search (leaf_shape, scientific_name, common_name)"; $sql = "SELECT * FROM temp_search ORDER BY scientific_name ASC LIMIT $start, $limit"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo $row['scientific_name'] . $row['common_name'] . $row['leaf_shape'] ; } This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=343981.0 Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $hostname='xxx'; $username='xxx'; $password='xxx'; $dbname='xxx; $usertable=xxx; $myconn=mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); if ((($_FILES["file"]["type"] =="image/gif") || ($_FILES["file"]["type"] =="image/jpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"]< 200000)) { if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br/>"; } else { if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo "File already exists. Choose another name."; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]); } } } else { echo "Invalid file"; } $path="uploads/" . $_FILES["file"]["name"]; $desc=$_POST["desc"]; if (!myconn) { die ('Could not connect: ' . $mysql_error()); } $db_selected=mysql_select_db('xxx',$myconn); if (!$db_selected) { die ('Can\'t use xxxx : ' . mysql_error()); } mysql_query("INSERT INTO partners (desc,photopath,state) VALUES ('$desc','$path','$state')"); mysql_close($myconn); ?> </body> </html> Hello, We've been working on a page that allows users to create their own avatar to be displayed on their page. We can get the script working but the only way to show the image is to save it to a temp folder, we want to just save the string in the database and let the php show this wehen required here are the file http://test.digitaldemocracy.org.uk/test_avatar.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="author" content="John Munro, Democratise Ltd" /> <meta name="copyright" content="Democratise Ltd 2010" /> <meta name="description" content="Digital Democracy -" /> <meta name="keywords" content=" add here" /> <meta name="robots" content="index, follow" /> <meta name="revisit-after" content="1 week" /> <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5)" /> <link rel="SHORTCUT ICON" href="http://www.digitaldemocracy.co.uk/favicon.ico" /> <title>Digital Democracy -</title> <link href="css/site.css" rel="stylesheet" type="text/css" /> <link href="css/basic.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="avatars/avatar.css" type="text/css" /> <script type="text/javascript" src="avatars/avatar.js"></script> <style type="text/css"> /*<![CDATA[*/ <!-- body { background-image: url(images/background_paper.jpg); background-repeat: repeat; } --> /*]]>*/ </style> <script type="text/javascript"> //<![CDATA[ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-15681567-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); //]]> </script> </head> <body> <div id="wrapper"> <div id="inner_wrapper"> <div class="header"> <div class="header_logo"> <img src="images/header_logo.png" width="190" height="55" alt="Digital Democracy" /> </div> <div class="header_link"> Make a<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> View<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> Vote on top<br/>proposal </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link"> View<br/>results </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link_single_line"> Profile </div> <div class="header_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="header_link_single_line"> More </div> <div id="header_search_bar"> <form action="Search" method="post"> <input name="Search" type="text" value="Search" size="15" /> <input name="Submit" type="button" value="Go" /> </form> </div> <div class="header_login"> <span class="header_login_text">Login / Register</span> </div> </div> <div id="info"> <div id="chosen_avatar"> <!--<p> avatar to be shown here when completed only - image shown below is thee to reference the saved code</p>--> <p><img src="<?php if (!empty($image)) { echo $filename; } else { echo 'http://test.digitaldemocracy.org.uk/avatar_creator.php?avatar[background]=bg_08&avatar[body]=body_01&avatar[head]=head_01&avatar[eyes]=blank&avatar[mouth]=blank&avatar[moustache]=blank&avatar[glasses]=blank&avatar[male_hair]=blank&avatar[female_hair]=blank';} ?>" title="Your chosen avatar (assembled as a PNG image)" alt="Your chosen avatar (PNG image)" /></p> <p>Your chosen avatar</p> </div> <form action="http://test.digitaldemocracy.org.uk/avatar_creator.php" method="get"> <div id="avatar_section"> <div id="avatar_stack"> <p> <img src="avatars/bg_01.png" alt="" /><input name="avatar[background]" type="radio" value="bg_01" checked="checked" /> <img src="avatars/bg_02.png" alt="" /><input name="avatar[background]" type="radio" value="bg_02" /> <img src="avatars/bg_03.png" alt="" /><input name="avatar[background]" type="radio" value="bg_03" /> <img src="avatars/bg_04.png" alt="" /><input name="avatar[background]" type="radio" value="bg_04" /> <img src="avatars/bg_05.png" alt="" /><input name="avatar[background]" type="radio" value="bg_05" /> <img src="avatars/bg_06.png" alt="" /><input name="avatar[background]" type="radio" value="bg_06" /> <img src="avatars/bg_07.png" alt="" /><input name="avatar[background]" type="radio" value="bg_07" /> <img src="avatars/bg_08.png" alt="" /><input name="avatar[background]" type="radio" value="bg_08" /> <img src="avatars/bg_09.png" alt="" /><input name="avatar[background]" type="radio" value="bg_09" /> </p> <p> <img src="avatars/body_01.png" alt="" /><input name="avatar[body]" type="radio" value="body_01" checked="checked" /> <img src="avatars/body_02.png" alt="" /><input name="avatar[body]" type="radio" value="body_02" /> <img src="avatars/body_03.png" alt="" /><input name="avatar[body]" type="radio" value="body_03" /> <img src="avatars/body_04.png" alt="" /><input name="avatar[body]" type="radio" value="body_04" /> <img src="avatars/body_05.png" alt="" /><input name="avatar[body]" type="radio" value="body_05" /> <img src="avatars/body_06.png" alt="" /><input name="avatar[body]" type="radio" value="body_06" /> <img src="avatars/body_07.png" alt="" /><input name="avatar[body]" type="radio" value="body_07" /> <img src="avatars/body_08.png" alt="" /><input name="avatar[body]" type="radio" value="body_08" /> </p> <p> <img src="avatars/head_01.png" alt="" /><input name="avatar[head]" type="radio" value="head_01" checked="checked" /> <img src="avatars/head_02.png" alt="" /><input name="avatar[head]" type="radio" value="head_02" /> <img src="avatars/head_03.png" alt="" /><input name="avatar[head]" type="radio" value="head_03" /> <img src="avatars/head_04.png" alt="" /><input name="avatar[head]" type="radio" value="head_04" /> <img src="avatars/head_05.png" alt="" /><input name="avatar[head]" type="radio" value="head_05" /> <img src="avatars/head_06.png" alt="" /><input name="avatar[head]" type="radio" value="head_06" /> <img src="avatars/head_07.png" alt="" /><input name="avatar[head]" type="radio" value="head_07" /> <img src="avatars/head_08.png" alt="" /><input name="avatar[head]" type="radio" value="head_08" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[eyes]" type="radio" value="blank" checked="checked" /> <img src="avatars/eyes_1.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_1" /> <img src="avatars/eyes_2.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_2" /> <img src="avatars/eyes_3.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_3" /> <img src="avatars/eyes_4.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_4" /> <img src="avatars/eyes_5.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_5" /> <img src="avatars/eyes_6.png" alt="" /><input name="avatar[eyes]" type="radio" value="eyes_6" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[mouth]" type="radio" value="blank" checked="checked" /> <img src="avatars/mouth_1.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_1" /> <img src="avatars/mouth_2.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_2" /> <img src="avatars/mouth_3.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_3" /> <img src="avatars/mouth_4.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_4" /> <img src="avatars/mouth_5.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_5" /> <img src="avatars/mouth_6.png" alt="" /><input name="avatar[mouth]" type="radio" value="mouth_6" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[moustache]" type="radio" value="blank" checked="checked" /> <img src="avatars/moustache_01.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_01" /> <img src="avatars/moustache_02.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_02" /> <img src="avatars/moustache_03.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_03" /> <img src="avatars/moustache_04.png" alt="" /><input name="avatar[moustache]" type="radio" value="moustache_04" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[glasses]" type="radio" value="blank" checked="checked" /> <img src="avatars/glasses_01.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_01" /> <img src="avatars/glasses_02.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_02" /> <img src="avatars/glasses_03.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_03" /> <img src="avatars/glasses_04.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_04" /> <img src="avatars/glasses_05.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_05" /> <img src="avatars/glasses_06.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_06" /> <img src="avatars/glasses_07.png" alt="" /><input name="avatar[glasses]" type="radio" value="glasses_07" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[hair 1]" type="radio" value="blank" checked="checked" /> <img src="avatars/m_hair_01.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_01" /> <img src="avatars/m_hair_02.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_02" /> <img src="avatars/m_hair_03.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_03" /> <img src="avatars/m_hair_04.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_04" /> <img src="avatars/m_hair_05.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_05" /> <img src="avatars/m_hair_06.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_06" /> <img src="avatars/m_hair_07.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_07" /> <img src="avatars/m_hair_08.png" alt="" /><input name="avatar[hair 1]" type="radio" value="m_hair_08" /> </p> <p> <img src="avatars/blank.png" alt="" /><input name="avatar[hair 2]" type="radio" value="blank" checked="checked" /> <img src="avatars/f_hair_01.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_01" /> <img src="avatars/f_hair_02.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_02" /> <img src="avatars/f_hair_03.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_03" /> <img src="avatars/f_hair_04.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_04" /> <img src="avatars/f_hair_05.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_05" /> <img src="avatars/f_hair_06.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_06" /> <img src="avatars/f_hair_07.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_07" /> <img src="avatars/f_hair_08.png" alt="" /><input name="avatar[hair 2]" type="radio" value="f_hair_08" /> </p> </div> </div> <p> </p> <p id="submit" > <input type="submit" value="Click here to save your personalised Avatar" /> </p> </form> <div id="hidden_spacer"> <p> </p> </div> </div> </div> </div> <div class="footer"> <div class="footer_content"> <div id="footer_democratise"> © Democratise Ltd </div> <div class="footer_link_single_line"> About us </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Contact </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Blog </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Help </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> </div> <div class="footer_link_spacer"> <img src="images/header_link_spacer.png" width="5" height="55" alt="Digital Democracy - Link Spacer image" /> </div> <div class="footer_link_single_line"> Privacy </div> </div> </div> </body> </html> And the file that runs the php and creates the images is <?php # form inputs in the correct stacking order from bottom to top $form_fields = array('background', 'body', 'head', 'eyes', 'mouth', 'moustache', 'glasses', 'hair 1', 'hair 2'); ob_start(); if(!isset($_GET['avatar'])) die; validate_inputs($form_fields); $filename = create_avatar($form_fields); //ob_end_clean(); //echo "hello"; //$image = output_image(ob_get_clean()); $image_output = ob_get_contents(); //ob_end_clean(); //echo $image; //$image = ob_get_contents(); //$image="data:image/png;base64, base64_encode($image)"; $image = 'test.digitaldemocracy.org.uk' . $_SERVER['REQUEST_URI']; //$image = $_SERVER['REQUEST_URI']; //echo $image; function validate_inputs($inputs) { foreach($inputs as $item) { if((preg_match('@(\.|/)@', $_GET['avatar'][$item])) or (!is_file('avatars/'.$_GET['avatar'][$item].'.png'))) { die(); } } } function create_avatar($inputs) { while($inputs) { $layer = @imagecreatefrompng('avatars/'. ($file = $_GET['avatar'][array_shift($inputs)]). '.png') or die('I could not open the avatars/'.$file); $layerWidth = imageSX($layer); $layerHeight = imageSY($layer); if(!isset($slate)) { $slate = @imagecreatetruecolor($layerWidth, $layerHeight); } @imagecopy($slate, $layer, 0, 0, 0, 0, $layerWidth, $layerHeight); @imagedestroy($layer); } imagetruecolortopalette ($slate, false, 256); //header('Content-Type: image/png'); $filename = 'temp'. rand(1,50) . '.png'; imagepng($slate, $filename); //imagepng($slate); imagedestroy($slate); return $filename; } function output_image($image) { $hash = md5($image); if(isset($_SERVER['HTTP_IF_NONE_MATCH'])){ if($hash == trim($_SERVER['HTTP_IF_NONE_MATCH'], '"')){ header("HTTP/1.x 304 Not Modified"); header('Etag: "'.$hash.'"'); die(); } } //header('Etag: "'.$hash.'"'); //header('Content-Type: image/png'); //imagepng($image); //echo $image; //return $image; } //header ("Location:test_avatar.php?image=$image"); include 'test_avatar.php'; ?> If anybody can help us it would be very appreciated Thanks John Munro Democratise.org Okay, so I'm kind of a PHP noob.
But out of context, for this site that I'm designing, it's easiest if I make a directory in the temporary folder PHP uses. In my case, /tmp/ because I am on Linux.
I want to use rand() to generate a random name for the page. But I then realized something, rand() could produce duplicates. How do I prevent PHP from trying to make the same directory at the same time? I know there are functions that will check if a file exists but I'm assuming it'll fail if that directory is currently being created, right?
How do I assure thread safety?
I willing to change my idea and not use rand(). Is there a way to get a unique key for each anonymous user on my site?
I have a table in my database for users. On the registration page I want to create another table with the id of the user as the table name. $sql = "CREATE TABLE IF NOT EXISTS `id_prod` ( ) how do i modify this line so that it takes the id from the user table and creates a new table with id as name followed by prod. For the life of me I can not figure out why this is not creating the table in the database. Second set of eyes would be great.
function install_kudos() { global $wpdb; $table_name = $wpdb->prefix . 'acikudosnew'; if ($wpdb->get_var('SHOW TABLES LIKE ' .$table_name) != $table_name) { $sql = "CREATE TABLE $table_name ( kudoid int(9) NOT NULL AUTO_INCREMENT, kudomsg text NOT NULL, kudoagent text NON NULL, kudocust text NOT NULL, kudoacct int(16) NOT NULL, kudoclient varchar(100) NOT NULL, kudoloc text NOT NULL, kudoentry TIMESTAMP DEFAULT CURRENT_TIMESTAMP, kudoadmin text NOT NULL, kudopic varchar(55) DEFAULT '' NOT NULL, PRIMARY KEY (kudoid) )"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } } register_activation_hook(__FILE__, 'install_kudos');
I want to show a table with a max of three columns. I am using an if statement to count the rows and then start a new row (after 3 cols), I cant see my error. The output just gice one col with all the data in it. Any help appreciated. Code: [Select] <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" id="cover" enctype="multipart/form-data"> <table width="700"><?php /* display picture and radio button */ //add counter for more than 3 images $i=0; $size=3; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $coverID=$row['coverID']; echo"<tr>"; echo "<td>"; echo"<img src=\"/wordpress_3/wp-content/plugins/Authors2/jackets/{$row['pix']}\" />"; echo "<input type = 'radio' name ='cover' value= '$coverID'/>"; ?> <br /> <input type="submit" value="submit"> <?php echo"</td>"; $i++; if($i==$size) { echo "</tr><tr>"; $i=0; } } ?></table> </form><?php Im messing around with functions and arrays but cant seem to get this to work. It basically creates a simple table with the parameters you specify. The array however doesnt go into the table properly. function asf_create_table($rows, $cols, $border=1, $padding=5, $td_border=1, $contents) { $table = "<table style=\"border: {$border}px solid; padding:{$padding}px;\">"; for ($t_rows=0; $t_rows<$rows; $t_rows++) { $table .= "<tr>"; } for ($t_cols=0; $t_cols<$cols; $t_cols++) { for ($i=0; $i<$cols; $i++) { $table .= "<td style=\"border: {$td_border}px solid;\">"; $table .= $contents[$i]; $table .= "</td>"; } } for ($t_rows=0; $t_rows<$rows; $t_rows++) { $table .= "</tr>"; } $table .= "</table>"; echo $table; } $t_contents = array("Cell 1", "Cell 2", "Cell 3", "Cell 4"); asf_create_table("4", "4", "1", "5", "1", $t_contents); instead of 4 cells each with Cell # in them i get 16 cells with the cell #. the 4 displayed 4 times. Hello, please let me know how to write xml file, i read somewhere we can use psql.....anyone knows please help! Thanks Had some great help yesterday, but I'm stuck using <?php ?> on every line, thanks to Joomla Anyway, I'm trying to create a table, and it doesn't seem to be working, to create it, what is the correct format? <?php <table width='400px' border ='1'>; ?> ?? output will be put out on a per line within a if statement, which works, just the framing of the table and tr and td seem to be eluding me. Thanks Code: [Select] <? $link = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Could not connect: ' . mysql_error()); mysql_select_db($dbname) or die ('Error connecting to database'); $sql = "SELECT * FROM papers WHERE ctitle='May 2012'"; $result = mysql_query($sql); $num = mysql_num_rows($result); //number of entry $data = mysql_query("select * from papers where ctitle='May 2012' ORDER BY id ASC"); $Wrd = new COM("Word.Application"); $Wrd->Application->Visible = False; $DocName = "MyDoc/MyWord.doc"; $WrdDoc = $Wrd->Documents->Add(); $WTable = $WrdDoc->Tables->Add($Wrd->Selection->Range, 2, $num); // Colums, Rows while($info=mysql_fetch_array($data)) { $i=1; $WTable->Cell($i,1)->Range->Text = $info['title']; $WTable->Cell($i,2)->Range->Text = $info['name'] $info['surname'] $info['institution'] $info['country']; $i++; } $Wrd->ActiveDocument->SaveAs(realpath($DocName)); $Wrd->Application->Quit; $Wrd = null; ?> Word Created <a href="<?=$DocName?>">Click here</a> to Download. php script is not working. Can someone please help me to detect the errors? i want create a table in ms word file for all entry in my database... "2 columns, number of rows" Cell(1,1) Cell(1,2) Cell(2,1) Cell(2,2) etc... Cell(3,1) Cell(3,2) i'm trying to achive this results layout: example: catagory comment comment comment catagory catagory catagory comment what is being pulled now is if their is 2 comments two 1 catagory then 2 catagorys are being returned with the same id. what i want is to return one cataogry with many comments. thanks in advance for your help. Code: [Select] <?php require_once('Connections/Del_Comments.php'); ?> <?php $all_ids = array(); $str_ids = ""; // first parent query $maxRows_sourceType = 10; $pageNum_sourceType = 0; if (isset($_GET['pageNum_sourceType'])) { $pageNum_sourceType = $_GET['pageNum_sourceType']; } $startRow_sourceType = $pageNum_sourceType * $maxRows_sourceType; mysql_select_db($database_Del_Comments, $Del_Comments); $query_sourceType = "SELECT a.Id, a.Type, a.Dates, a.UIdFk, b.Id as Did, b.comment, b.dates as Day, b.sfk as Sfk , c.sfk as sfk1, d.Memo as memo FROM asstatusupdate as a left join asstatusdata as b on a.id = b.sfk left join asmanystatusupdate as c on b.sfk = c.sfk left join ascomments as d on d.id = c.cfk where a.uidfk='1' order by Dates asc"; $query_limit_sourceType = sprintf("%s LIMIT %d, %d", $query_sourceType, $startRow_sourceType, $maxRows_sourceType); $sourceType = mysql_query($query_limit_sourceType, $Del_Comments) or die(mysql_error()); $row_sourceType = mysql_fetch_assoc($sourceType); if (isset($_GET['totalRows_sourceType'])) { $totalRows_sourceType = $_GET['totalRows_sourceType']; } else { $all_sourceType = mysql_query($query_sourceType); $totalRows_sourceType = mysql_num_rows($all_sourceType); } $totalPages_sourceType = ceil($totalRows_sourceType/$maxRows_sourceType)-1; // add the array while ($row_source = mysql_fetch_assoc($sourceType)) { $all_ids[] = $row_source['Sfk']; $str_ids .= $row_source['Sfk'].','; } // remove the array $str_ids = (substr($str_ids,-1) == ',') ? substr($str_ids, 0, -1) : $str_ids; echo $str_ids; //echo $all_ids; //second child query $maxRows_sourceComments = 10; $pageNum_sourceComments = 0; if (isset($_GET['pageNum_sourceComments'])) { $pageNum_sourceComments = $_GET['pageNum_sourceComments']; } $startRow_sourceComments = $pageNum_sourceComments * $maxRows_sourceComments; mysql_select_db($database_Del_Comments, $Del_Comments); $query_sourceComments = "SELECT c.sfk as sfk1, d.Memo as memo FROM asmanystatusupdate as c left join ascomments as d on d.id = c.cfk where c.uidfk0='1' and c.sfk in ($str_ids)"; $query_limit_sourceComments = sprintf("%s LIMIT %d, %d", $query_sourceComments, $startRow_sourceComments, $maxRows_sourceComments); $sourceComments = mysql_query($query_limit_sourceComments, $Del_Comments) or die(mysql_error()); $row_sourceComments = mysql_fetch_assoc($sourceComments); if (isset($_GET['totalRows_sourceComments'])) { $totalRows_sourceComments = $_GET['totalRows_sourceComments']; } else { $all_sourceComments = mysql_query($query_sourceComments); $totalRows_sourceComments = mysql_num_rows($all_sourceComments); } $totalPages_sourceComments = ceil($totalRows_sourceComments/$maxRows_sourceComments)-1; $resultComments = @mysql_query($query_sourceComments, $Del_Comments); $numComments = @mysql_num_rows($resultComments); $result = @mysql_query($query_sourceType, $Del_Comments); $num = @mysql_num_rows($result); // column count for parent $thumbcols = 1; // column count for parent query $thumbrows = 1+ round($num / $thumbcols); // column count for child query $thumbrowsComments = 1+ round($numComments/$thumbcols); // header print '<br />'; print '<table align="center" width="500" border="3" cellpadding="0" cellspacing="0">'; if (!empty($num)) { print '<tr><td colspan="3" align="center"><strong>Returned Num of Record Sets: ' .$num. ' and comments count' .$numComments. '</strong></td></tr>'; } // table layout for parent query function display_table() { // global variables global $num, $result, $thumbrows, $thumbcols, $resultComments, $numComments, $thumbrowsComments ; // row count for parent for ($r=1; $r<=$thumbrows; $r++) { // print table row print '<tr>'; //format the columns for ($c=1; $c<=$thumbcols; $c++) { print '<td align="center" valign="top">'; $row = @mysql_fetch_array($result); $row1 = @mysql_fetch_array($resultComments); $Id = $row['Id']; $Type = $row['Type']; $Dates = $row['Dates']; $Comment = $row['Comment']; $Sfk1 = $row['sfk1']; $Memo = $row['memo']; // test if not empty show record sets if (!empty($Id)) { // print output from parent query // grab type dates comment and format for there column echo '<td valign="top" align="center">'; echo "$Type"; echo ' '; echo "$Dates"; echo '<br />';echo '<br />';echo '<br />'; echo "$Comment"; echo '</td>'; echo '<td>'; echo "$Id"; echo '</td>'; echo '<td>'; echo "$str_ids"; echo '</td>'; echo '<tr>'; echo '<td>'; echo "$Sfk1"; echo '</td>'; echo '<td>'; echo "$Memo"; echo '</td>'; echo '</tr>'; } // closing the $id loop else { print ' '; } print '</td>'; //closing the table data } //closing the rows print '</tr>'; } // closing the outter loop //} //closing fk id loop print '</td>'; //closing the table data } //closing the rows print '</tr>'; //} // closing the main loop // call the main table display_table() ; print '</table>'; ?> <?php var_dump(substr('a', 1)); // bool(false) ?> |