PHP - Json Error If Table Field Has Dash
Hello Everyone, I have a PHP code that reads data from db table. Then it converts it into JSON and show it. However if data table field has - or so then it gives json error. For e.g. if($num > 0){ while($res = mysqli_fetch_array($query)){ $NDate = $res['NDate']; $Summary = substr($res['Summary'],0,256); /* CREATE ARRAY FOR SHORT TERM NEWSLETTER */ $newsletters[]=array('newsletter'=>array("RecID"=>$SNo,"Summary"=>$Summary)); } /* JSON OUTPUT*/ $json = array("AuthOK" => 'True',"newsletters"=>$newsletters); header('Content-type: application/json'); echo json_encode($json); How to solve the issue ?
Regards, Similar TutorialsThis is my first real jump into PHP, I created a small script a few years ago but have not touched it since (or any other programming for that matter), so I'm not sure how to start this. I need a script that I can run once a day through cron and take the date from one table/filed and insert it into a different table/field, converting the human readable date to a Unix date. Table Name: Ads Field: endtime_value (human readable date) to Table Name: Node Field: auto_expire (Converted to Unix time) Both use a field named "nid" as the key field, so the fields should match each nid field from one table to the next. Following a tutorial I have been able to insert into a field certain data, but I don't know how to do it so the nid's match and how to convert the human readable date to Unix time. Thanks in advance!. I want to add a note field and a checkbox to my list/grid page and save this information to a json file using uomptrucknumber as the key. The note information will be information for the whole truck not by order. The check box will let them know that the truck is ready to have paper work printed. I have not add the note field or checkbox because I did not want to start off wrong. echo "<table>"; echo "<tr style='background:#82fbfd'>"; echo "<th>ShipDate</th>"; echo "<th>ShipMeth</th>"; echo "<th>Name</th>"; echo "<th>LoadID</th>"; echo "<th>Drop</th>"; echo "<th>OrderID</th>"; echo "<th>Status</th>"; echo "<th>FGI</th>"; echo "<th>FGM</th>"; echo "<th>TotalBox</th>"; echo "<th>Cubes</th>"; echo "<th>Total</th>"; echo "<th>Notes \n</th>"; //echo "<table>"; echo "<tr style='background:#82fbfd'>"; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } function ShowDetail($row){ if($row['ompclosed']==-1){ $theColor="#AAF0D2"; }else{ $theColor="#FFFFFF"; } if($row['ompclosed']==0 && $row['date'] < date("m/d/Y")) { $theColor="#FF0000"; } echo "<tr style='background-color :$theColor'><td>" .$row['date'] ."</td>"; echo "<td>" .$row['ompshippingmethodid'] ."</td>"; echo "<td style='text-align:left'>" .$row['cmoname'] ."</td>"; echo "<td>" .$row['uomptrucknumber'] ."</td>"; echo "<td>" .$row['uompdropsequence'] ."</td>"; echo "<td>" .$row['ompsalesorderid'] ."</td>"; echo "<td>" .$row['ompclosed'] ."</td>"; echo "<td>" .round($row['FGIqty'],0) ."</td>"; echo "<td>" .round($row['FGMqty'],0) ."</td>"; echo "<td>" .round($row['uomptotalboxcount'],0) ."</td>"; echo "<td>" . number_format($row['uompvolumetotal'],2) ."</td>"; echo "<td>" . number_format($row['ompordertotalbase'],2) ."</td>"; echo "<td style='text-align:left'>" .$row['ompordercommentstext'] ."</td></tr>" ; } //**************************************************************** while ($row = odbc_fetch_array($result)) { if($row['ompclosed']==-1){ $theColor="#AAF0D2"; }else{ $theColor="#FFFFFF"; } if($row['ompclosed']==0 && $row['date'] < $today) { $theColor="#FF0000"; } if($row['uomptrucknumber'] != $loadid) { if ($loadid !== 0) { echo "<tr style='background:#eee'> <td colspan='7'>TOTAL</td> <td>$TotalFGI</td> <td>$TotalFGM</td> <td> </td> <td> </td> <td>$loadTotal</td> </tr>"; } $TotalFGI=0; $TotalFGM=0; $loadTotal=0; } ShowDetail($row); $loadid = $row['uomptrucknumber']; $TotalFGI+=round($row['FGIqty'],0); $TotalFGM+=round($row['FGMqty'],0); $loadTotal +=$row['ompordertotalbase']; } echo "<tr style='background:#eee'> <td colspan='7'>TOTAL</td> <td>$TotalFGI</td> <td>$TotalFGM</td> <td> </td> <td> </td> <td>$loadTotal</td> </tr> </table>"; odbc_close($connect); ?>
Hi, I'm developing an app using flash AS2 as the front end via PHP and a mySQL database at the backend on my server. what i'm looking to do is update/insert into a table called 'cards' and at the same time update/insert into another table called 'jingle'. There is a field called 'cardID' in jingle that should be the same as the ID number created in 'cards' thus creating a link between entries in the different tables that can be called up as i choose. hope i've been clear i just wouldn't know where to start any help would be appreciated. MySQL client version: 5.0.91 PHPmyAdmin Version information: 3.2.4 thanks in advance I'm trying to remove a dash at the end of a title, for the times when a dash appears there (which isn't always). Since my titles are always different lengths, I don't think substr will work. How can I code the following... If $title ends with '-', replace with '' Thanks! I know this one is probably super easy for you programmer types.. but I just need to know.. If a string ends with a dash (and not all of them will), how do I remove it? Thanks! Hi, I dont know if many of you have heard of bitcoins? its just a virtual currency with real value... I have got the daemon running for it, and have connected it to PHP. The code i am using to return all transactions is: Code: (php) [Select] print_r($bitcoin->listtransactions("")); echo "\n"; This will return: Quote Array ( => Array ( [account] => [address] => 1ALtJaqGiShyGMVNRNn77E67PuBKc9FLyo [category] => receive [amount] => 0.001 [confirmations] => 13 [txid] => 0f36872c60da25b29ff3a8efa91d931e26fe1a4354da280f3 d69234c8b521c8c [time] => 1314115260 ) [1] => Array ( [account] => [category] => move [time] => 1314115550 [amount] => -0.001 [otheraccount] => 4 [comment] => ) ) How could i output this info into a table instead of the above? Thanks Dear All, As I would like to create json as below format { "data": [ { "title": "After getting a COVID-19 Vaccine", "content": [ { "list": "You may have some side effects, which are normal signs that your body is building protection." }, { "list": "Following symptoms can take place, and it usually resolves within 2 to 3 days." }, { "list": "Common Side Effects pain, redness, swelling, warmth, nausea, muscle pain, tiredness, headache" } ] }, { "title": "After getting a COVID-19 Vaccine", "content": [ { "list": "You may have some side effects, which are normal signs that your body is building protection." }, { "list": "Following symptoms can take place, and it usually resolves within 2 to 3 days." }, { "list": "Common Side Effects pain, redness, swelling, warmth, nausea, muscle pain, tiredness, headache" } ] } ] } The information is from mysql select command: SELECT (tb_helpinfo.title_eng) as title,(tb_helpdetail.content_eng) as content FROM tb_helpinfo INNER JOIN tb_helpdetail ON tb_helpinfo.id = tb_helpdetail.helpinfo_id
I am using the Stripe API. Been at it for a day and still no luck. I keep getting this error. POST http://localhost/pay 404 (Not Found) Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position // this error is because of this line .then(handleServerResponse); It has specifically to do with this function. function handlePaymentMethodResult(result) { if (result.error) { // An error happened when collecting card details, show it in the payment form resultContainer.textContent = result.error.message; } else { // Otherwise send paymentMethod.id to your server (see Step 3) fetch('/pay', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ payment_method_id: result.paymentMethod.id }) }).then(function(result) { return result.json(); }).then(handleServerResponse); } } What is "/pay" suppose to be exactly? I assumed it was a page where i run my server process code. But it keeps giving me that error no matter what I try it.
Here is my full mode. INDEX.php <?php require_once 'library/stripe/init.php'; ?> <!DOCTYPE HTML> <head> <meta charset="UTF-8"> <title>Title</title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content="---"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <link rel="shortcut icon" href="/images/favicon.png" /> <link href="css/screen.css?v=1.1" media="screen, projection" rel="stylesheet" /> <script src="javascripts/jquery-3.2.0.min.js"></script> <script src="https://js.stripe.com/v3/"></script> <script src="javascripts/client.js" defer></script> </head> <body> <?php $total_amount = 20; ?> <div id="payment-box"> <div id="p-box-heading"> Total Amount: <span>$<?php if(empty($total_amount)){echo '0.00';}else{echo $total_amount;} ?> CAD</span> </div> <div id="p-box-body"> <form id="payment-form"> <div id="card-element"><!-- placeholder for Elements --></div> <button id="card-button">Submit Payment</button> <p id="payment-result"><!-- we'll pass the response from the server here --></p> </form> </div> </div> </body>
CLIENT.js var stripe = Stripe("pk_test_ROlyXpDaTbqIvSpndWp7IdxW"); var elements = stripe.elements(); var cardElement = elements.create('card'); cardElement.mount('#card-element'); var form = document.getElementById('payment-form'); var resultContainer = document.getElementById('payment-result'); cardElement.on('change', function(event) { if (event.error) { resultContainer.textContent = event.error.message; } else { resultContainer.textContent = ''; } }); form.addEventListener('submit', function(event) { event.preventDefault(); resultContainer.textContent = ""; stripe.createPaymentMethod({ type: 'card', card: cardElement, }).then(handlePaymentMethodResult); }); function handlePaymentMethodResult(result) { if (result.error) { // An error happened when collecting card details, show it in the payment form resultContainer.textContent = result.error.message; } else { // Otherwise send paymentMethod.id to your server (see Step 3) fetch('/pay', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ payment_method_id: result.paymentMethod.id }) }).then(function(result) { return result.json(); }).then(handleServerResponse); } } function handleServerResponse(responseJson) { if (responseJson.error) { // An error happened when charging the card, show it in the payment form resultContainer.textContent = responseJson.error; } else { // Show a success message resultContainer.textContent = 'Success!'; } }
SERVER.php \Stripe\Stripe::setApiKey('sk_test_GPxllXVIfWnuczEjLAGh7BaX'); header('Content-Type: application/json'); # retrieve JSON from POST body $json_str = file_get_contents('php://input'); $json_obj = json_decode($json_str); try { // Create the PaymentIntent $intent = \Stripe\PaymentIntent::create([ 'amount' => 1099, 'currency' => 'usd', 'payment_method' => $json_obj->payment_method_id, # A PaymentIntent can be confirmed some time after creation, # but here we want to confirm (collect payment) immediately. 'confirm' => true, # If the payment requires any follow-up actions from the # customer, like two-factor authentication, Stripe will error # and you will need to prompt them for a new payment method. 'error_on_requires_action' => true, ]); generateResponse($intent); } catch (\Stripe\Exception\ApiErrorException $e) { // Display error on client echo json_encode(['error' => $e->getMessage()]); } function generateResponse($intent) { if ($intent->status == 'succeeded') { // Handle post-payment fulfillment echo json_encode(['success' => true]); } else { // Any other status would be unexpected, so error echo json_encode(['error' => 'Invalid PaymentIntent status']); } }
Hi
I have another problem with my code
I have records in my database and i want to put them in Jgrid but no records are show.
This is my php
<?php error_reporting(0); require_once 'database_connection.php'; $page = $_GET['page']; // get the requested page $limit = $_GET['rows']; // get how many rows we want to have into the grid $sidx = $_GET['sidx']; // get index row - i.e. user click to sort $sord = $_GET['sord']; // get the direction if(!$sidx) $sidx =1; // connect to the database $result = mysql_query("SELECT COUNT(*) AS count FROM utilizador"); $row = mysql_fetch_array($result,MYSQL_ASSOC); $count = $row['count']; if( $count >0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } if ($page > $total_pages) $page=$total_pages; $start = $limit*$page - $limit; // do not put $limit*($page - 1) $SQL = "SELECT * FROM utilizador ORDER BY $sidx $sord LIMIT $start , $limit"; $result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error()); $responce->page = $page; $responce->total = $total_pages; $responce->records = $count; $i=0; while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $responce->rows[$i]['id']=$row[idutilizador]; $responce->rows[$i]['cell']=array($row[idutilizador],$row[nome],$row[utilizador],$row[telefone],$row[email]); $i++; } echo json_encode($responce); ?>And this is the Jgrid <html> <head> <title>jQGrid example</title> <!-- Load CSS--><br /> <link rel="stylesheet" href="css/ui.jqgrid.css" type="text/css" media="all" /> <!-- For this theme, download your own from link above, and place it at css folder --> <link rel="stylesheet" href="css/jquery-ui-1.9.2.custom.css" type="text/css" media="all" /> <!-- Load Javascript --> <script src="js/jquery_1.5.2.js" type="text/javascript"></script> <script src="js/jquery-ui-1.8.1.custom.min.js" type="text/javascript"></script> <script src="js/i18n/grid.locale-pt.js" type="text/javascript"></script> <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script> </head> <body> <table id="datagrid"></table> <div id="navGrid"></div> <p><script language="javascript"> jQuery("#datagrid").jqGrid({ url:'example.php', datatype: "json", colNames:['Idutilizador','Nome', 'Utilizador', 'Telefone','Email'], colModel:[ {name:'idutilizador',index:'idutilizador', width:55,editable:false,editoptions:{readonly:true,size:10}}, {name:'nome',index:'nome', width:80,editable:true,editoptions:{size:10}}, {name:'idutilizador',index:'idutilizador', width:90,editable:true,editoptions:{size:25}}, {name:'telefone',index:'telefone', width:60, align:"right",editable:true,editoptions:{size:10}}, {name:'email',index:'email', width:60, align:"right",editable:true,editoptions:{size:10}} ], rowNum:10, rowList:[10,15,20,25,30,35,40], pager: '#navGrid', sortname: 'idutilizador', sortorder: "asc", height: 500, width:900, viewrecords: true, caption:"Atividades Registadas" }); jQuery("#datagrid").jqGrid('navGrid','#navGrid',{edit:true,add:true,del:true}); </script> </body> </html>Anything wrong with the code? Regards Hello everyone.
please I have problem with printing out a value from inside an array of a nested json. ive tried several ways its always returns "index not define". $valr= "https://ice3.com/api/v1/orderbook/ticker"; ////////////////////////////source $valrGet = file_get_contents($valr); $valrD = json_decode($valrGet, true); $valrSell = ["ask"] ["price"]; Here is the structure of the json from the source : {"errors":false,"response":{"entities":[{"pair_id":3,"pair_name":"BTC\/ZAR","ask":{"price":"179382.54","amount":"0.05357142"},"bid":{"price":"177229.4286563","amount":"0.0011"}},{"pair_id":4,"pair_name":"BTC\/NGN","ask":{"price":"8890000.00","amount":"0.10"},"bid": my target is to output the value of ("price") from "pair_name" BTC\/ZAR please help. Thanks in advance Hi All,
I have a form with a jquery autocomplete input field. Once the user has entered 2 characters, there is a list of values (people names) containing this string that appears. This works good.
The values come from a database table with two fields (names and ids). The query that extracts the names also retreives the values in the id field.
What would be the syntax to set the "value" attribut of the input tag to the id of a name when the user clicks on that name in the list?
The PHP part that builds the json is :
$data[] = array( 'label' => $row['name'], 'value' => $row['name'], 'id' => $row['id'] ); echo json_encode($data);The JS begins as follows : jQuery(document).ready(function(){ $('#input_id').autocomplete({source:'my_jquery_suggest.php', select: function(event, ui) { $(event.target).val(ui.item.value); $('#form_id').submit(); return false; }, minLength:2,delay: 1000}).focus(function () { window.pageIndex = 0; $(this).autocomplete("search"); }); ...Thanks for your help. Hi
I am very new to PHP & Mysql.
I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion.
Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself.
Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows).
Ripon.
Below is my Code:
<?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?>Output is attached. Hi, I have a connection set up to an API using a PHP script - the API sends back data in JSON format, and if I capture it and echo it, it displays in extremely unfriendly format on the screen. I've tried to find a way to convert this data into readable format, ideally in a HTML table, but although there are articles on converting manually inputted JSON data into a HTML table using Javascript, I can't find a way to do it from a PHP variable. This is what I have so far: if ($_POST['getcompany']) { $companyname = $_POST['_Name']; $ch = curl_init(); $data_array2 = array( 'token' => $token ); $make_call2 = json_encode($data_array2); //echo 'Token is '.$token; $token2 = substr($token, 14); $token3 = substr($token2, 0, -3); //echo 'Token 2 is '.$token3; //echo 'Company Name is '.$companyname; //curl_setopt($ch, CURLOPT_GET, 1); //curl_setopt($ch, CURLOPT_POSTFIELDS, $make_call2); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Authorization: '.$token3.'')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, 'https://connectionurl?countries=GB&name='.$companyname); //Execute the request $result = curl_exec($ch); echo 'Companies: '.$result; //This displays the data provided by the search, but is in JSON format
So I need a way to get the data held in $result, into a HTML table. Any idea how I can do this? hello, if i have an appostraphy in a text box while sumitting, it returns an error. any ideas? Lets say I want to get the name of the first field in a table (or the second) and assign it to a variable. i.e., if the first fieldname in a table is called "record_number", I would want: $first = "record_number"; Here's what I was able to come up with so far but not sure what to do next: $sql = "SELECT * FROM $tbl "; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); $line = mysql_fetch_array($result, MYSQL_ASSOC); I have a form to search through apartments but if one field (rent) is not filled the php script cannot process the search. Is there a way that I can have the script just search the minimum rent or maximum rent if those fields are not filled in? In other words could I make it say if blank put in 0 for minimum rent? The HTML Form: Code: [Select] <form method="post" action="searchapts.php"> <table width="372" border="0" class="apttable"> <tr> <td width="66" style="color: #000">Borough:</td> <td colspan="2"><select name="county" id="county"> <option selected="selected">Bronx</option> <option>Brooklyn</option> <option>Manhattan</option> <option>Queens</option> <option>Staten Island</option> <option>---------------</option> <option>Nassau</option> <option>Suffolk</option> </select></td> </tr> <tr> <td style="color: #000">Beds:</td> <td colspan="2"><select name="type" id="type"> <option>0 Bed</option> <option>1 Bed</option> <option>2 Bed</option> <option>3 Bed</option> <option>4 Bed</option> <option>5 Bed</option> </select></td> </tr> <tr> <td style="color: #000">Rent:</td> <td width="151" style="color: #000"><span id="AptRentMin"> <span id="sprytextfield3"> <input name="min_price" type="text" id="min_price" value="" size="7" maxlength="7" /> <span class="textfieldRequiredMsg">Required.</span></span>(Min)</td> <td width="141" style="color: #000"><span id="AptRentMax"> <span id="sprytextfield4"> <input name="max_price" type="text" id="max_price" value="" size="7" maxlength="7" /> <span class="textfieldRequiredMsg">Required.</span></span>(Max)</td> </tr> <tr> <td style="color: #000"><input name="Search" id="Search" value="Search" type="submit" /></td> <td> </td> <td> </td> </tr> </table> </form> The PHP Script: Code: [Select] <?php if ($_POST){ $county = $_POST['county']; $rooms = $_POST['type']; $rentmin = $_POST['rent_min']; $rentmax = $_POST['rent_max']; } $dbase = mysql_connect ( 'localhost', '', '' ); mysql_select_db ( '', $dbase ); if($county){ $sql = "SELECT * FROM `apartments`, `county` = '".mysql_real_escape_string($county)."', `rooms` = '".mysql_real_escape_string($rooms)."', `MIN(rent)` '".mysql_real_escape_string($rentmin)."', `MAX(rent)` '".mysql_real_escape_string($rentmax)."' order by `date_created` DESC"; }else{ $sql = "SELECT * FROM `apartments`"; } $res = mysql_query($sql, $dbase); if ( mysql_num_rows($res) > 0 ) { echo "<strong>Click Headers to Sort</strong>"; echo "<table border='0' align='center' bgcolor='#999969' cellpadding='3' bordercolor='#000000' table class='sortable' table id='results'> <tr> <th> Title </th> <th> Borough </th> <th> Town </th> <th> Phone </th> <th> Rooms </th> <th> Bath </th> <th> Fees </th> <th> Rent </th> </tr>"; while($row = mysql_fetch_assoc($res)) { echo "<tr> <td bgcolor='#FFFFFF' style='color: #000' align='center'> <a href='classified/searchapts/index.php?id=".$row['id']."'>" . $row['title'] . "</a></td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['county'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['town'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['phone'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['rooms'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['bath'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['feeornofee'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['rent'] . "</td> </tr>"; } echo "</table>"; print_r($apts); } else { echo "<p> </p><p> </p> No Results <br /><p> </p><FORM><INPUT TYPE='button' VALUE='Go Back' onClick='history.go(-1);return true;'></FORM> and Refine Your Search <p> </p><p> </p>"; } ?> Hi, when I submit a form I want to update a field in the "daterange" table. In the form the id field (RID) from "daterange" is selected prior to submit. Basically, I want to change the STATUS field to B (from A). The structure of daterange table is as follows: RID (key field) DEND MONTH DATE SITE PRICE STATUS What is the easiest way to accomplish this? Here is the code from the form (if it will help)... Code: [Select] <?php //************************************** // Page load dropdown results // //************************************** function getTierOne() { $result = mysql_query("SELECT DISTINCT MONTH FROM daterange") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '<option value="'.$tier['MONTH'].'">'.$tier['MONTH'].'</option>'; } } //************************************** // First selection results // //************************************** if($_GET['func'] == "drop_1" && isset($_GET['func'])) { drop_1($_GET['drop_var']); } function drop_1($drop_var) { include_once('db.php'); $result = mysql_query("SELECT * FROM daterange WHERE DEND > DATE(NOW()) AND STATUS='A' AND MONTH='$drop_var' ORDER BY DATE, SITE") or die(mysql_error()); echo '<select name="RID"> <option value=" " disabled="disabled" selected="selected">Choose a Reservation</option>'; while($drop_2 = mysql_fetch_array( $result )) { echo '<option value="'.$drop_2['RID'].'">'.$drop_2 ['DATE']. ', '.$drop_2 ['SITE']. ', '.$drop_2 ['PRICE'].'</option>'; } echo '</select> '; echo "<br />"; echo "</select><p align=left><label><font size=\"2\" face=\"Arial\">First Name: <input type=\"text\" name=\"FNAME\" size=\"50\" maxlength=\"50\" tabindex=\"1\"<br />"; echo "<p align=left><label>Last Name: <input type=\"text\" name=\"LNAME\" size=\"50\" maxlength=\"50\" tabindex=\"2\"<br />"; echo "<p align=left><label>Address Line 1: <input type=\"text\" name=\"ADDR1\" size=\"50\" maxlength=\"50\" tabindex=\"3\"<br />"; echo "<p align=left><label>Address Line 2: <input type=\"text\" name=\"ADDR2\" size=\"50\" maxlength=\"50\" tabindex=\"4\"<br />"; echo "<p align=left><label>City: <input type=\"text\" name=\"CITY\" size=\"50\" maxlength=\"50\" tabindex=\"5\"<br />"; echo "<p align=left><label>State (abbrev.): <input type=\"text\" name=\"STATE\" size=\"2\" maxlength=\"2\" tabindex=\"6\"<br />"; echo "<p align=left><label>Zip Code: <input type=\"text\" name=\"ZIP\" size=\"5\" maxlength=\"5\" tabindex=\"7\"<br />"; echo "<p align=left><label>Contact Phone Number: (<input type=\"text\" name=\"PHONE1\" size=\"3\" maxlength=\"3\" tabindex=\"8\""; echo "<label>)<input type=\"text\" name=\"PHONE2\" size=\"3\" maxlength=\"3\" tabindex=\"9\""; echo "<label>-<input type=\"text\" name=\"PHONE3\" size=\"4\" maxlength=\"4\" tabindex=\"10\"<br />"; echo "<p align=left><label>Email: <input type=\"text\" name=\"EMAIL\" size=\"50\" maxlength=\"50\" tabindex=\"11\"<br />"; echo '<input type="submit" name="submit" value="Book Now!" /><br />'; echo '<input type="reset" name="submit" value="Reset" /><br />'; } ?> I would like to echo field names in my table on webpage one by one. I know mySQL has "describe" function which will list the complete table, I am looking for a way to display each field name one by one with other stuff in between them like input field or description. Is there a way to duplicate all rows in a table AND change one field's value for each new row?
For example...
TABLE: comments
FIELDS:
commentid
userid
comment
weeknumber
Say there are only 5 comments in there like this (I have MANY rows, but keeping sample size small for example's sake)...
1-17-hello-3
2-41-hey-3
3-18-yo-3
4-67-sup-3
5-12-hola-3
I would like to duplicate them AND make the "weeknumber" = 4, so the table ultimately has 10 rows like this...
1-17-hello-3
2-41-hey-3
3-18-yo-3
4-67-sup-3
5-12-hola-3
1-17-hello-4
2-41-hey-4
3-18-yo-4
4-67-sup-4
5-12-hola-4
Is this doable?
Thanks...
Hi everyone, I'm trying to create a site where teachers can upload educational animations (swfs) and source files (.fla's) to a site as a shared resource for others to use in their classrooms. I've concatinated a random number to both the source file and animation file to circumvent the problem of files with same names being uploaded. However, I have one small problem. The source file is not a mandatory upload, so sometimes the $source_file is null. However, with the random number concatinated, $source_fileX is not null. I tried to write some code saying that if $source_file is null, then $source_fileX should be null, else $source_fileX should be random_number concatinated with $source_file , but it doesn't seem to be working. The animation files are uploading fine. It's just the source files that are not. Nor is $source_fileX being inserted into the source_file field in the database. Code below. Thanks in advance. Code: [Select] <?php $keywords = $_POST["keywords"]; $subject = $_POST["subject"]; $description = $_POST["description"]; $website = $_POST["website"]; $firstname = $_POST["firstname"]; $lastname = $_POST["lastname"]; $school = $_POST["school"]; $animation_file = $_POST["animation_file"]; $source_file = $_POST["source_file"]; $random_digit=rand(00000, 9999); $animation_fileX=$random_digit . $_FILES['animation_file']['name']; if($animation_fileX!="") { if (!copy($_FILES['animation_file']['tmp_name'], "uploads/$animation_fileX")) { echo "failed to copy \n"; } } if ($source_file!="") { $source_fileX=$random_digit . $_FILES['source_file']['name']; } else { $source_fileX=""; } if($source_fileX!="") { if (!copy($_FILES['source_file']['tmp_name'], "source_file_uploads/$source_fileX")) { echo "failed to copy \n"; } } //**********************SEND TO DATABASE**************************** include 'mysql_connect.php'; $query = "INSERT INTO animation_uploads (date, animation_file, source_file, keywords, subject, description, firstname, lastname, school, website)" . "VALUES (NOW(), '$animation_fileX', '$source_fileX', '$keywords', '$subject' , '$description', '$firstname', '$lastname', '$school' , '$website')"; //if($query){echo 'data has been placed'} mysql_query($query) or die(mysql_error()); //***********************END OF DATABASE CODE*********************** |