Jump to content

bcraig

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bcraig's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. bcraig

    date query

    Im using PHP and i want to select records from my database where the month within a date datatype field is equal to a set variable. I dont know if this is possible? I have this now $dateFormat = date('m'); $monthNo = 10; $sql_month = sprintf("SELECT * FROM gigs WHERE '%s' = '%s'", $dateFormat, $monthNo); But that shows all records dated with all different months in the database
  2. Cool thanks! I might try using session sometime but for now I think ill use <input type='hidden' name='email' value="<?php echo $_POST['email']?>" /><p><?php echo $_POST['email']?></p>
  3. Ahhh silly little typo Thanks a lot!
  4. but if the input is disabled it wont post again and the only way i know how to post is with a form
  5. Ive got a form for creating a record and it posts to a confirmation page. I want the confirmation page to echo all the POST data into another form which on submit will POST to a mysql INSERT query. Is this possible without having input fields on the confirmation page? or are there ways to set the input boxes to be invisable and only show the data and be non-editable?? PHP version:5.2.5
  6. How do you POST data depending on the setting of check boxes and radio buttons? I want to post only one of the inputs where radio checked... <radio><input text>your location(checked by default) <radio><input text>or specify And post any of these if checked... [ ]<input>email [ ]<input>phone [ ]<input>mobile Im using: PHP 5.2.5
  7. Thanks for trying to help but i worked around it. Insted of trying to put all the updates all together i seperated them and it worked. Result: if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "createAuction")) { $updateSQLa = sprintf("UPDATE categories SET sub_counter=%s WHERE cat_id=%s", GetSQLValueString($_POST['sub_counter'], "int"), GetSQLValueString($_POST['sub_cat'], "int")); mysql_select_db($database_jobsnz_conn, $jobsnz_conn); $Resulta = mysql_query($updateSQL, $jobsnz_conn) or die(mysql_error()); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "createAuction")) { $updateSQLb = sprintf("UPDATE categories SET counter=%s WHERE cat_id=%s", GetSQLValueString($_POST['counter'], "int"), GetSQLValueString($_POST['main_cat'], "int")); mysql_select_db($database_jobsnz_conn, $jobsnz_conn); $Result1b = mysql_query($updateSQLb, $jobsnz_conn) or die(mysql_error()); }
  8. Can anyone tell me why im getting this error Im using: PHP 5.2.5 MySql 5.0.45 Apache 2.2.6 Windows XP localhost This is my code <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["update"])) && ($_POST["update"] == "updateAuction")) { $updateSQL = sprintf("UPDATE auctions SET title=%s, current_price=%s, description=%s, quals=%s, refs=%s, materials=%s, deadline=%s, day=%s, location=%s, payment=%s, WHERE id=%s", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['current_price'], "int"), GetSQLValueString($_POST['description'], "text"), GetSQLValueString($_POST['quals'], "text"), GetSQLValueString($_POST['refs'], "int"), GetSQLValueString($_POST['materials'], "text"), GetSQLValueString($_POST['deadline'], "date"), GetSQLValueString($_POST['day'], "text"), GetSQLValueString($_POST['location'], "text"), GetSQLValueString($_POST['payment'], "text"), GetSQLValueString($_POST['id'], "int")); mysql_select_db($database_jobsnz_conn, $jobsnz_conn); $Result1 = mysql_query($updateSQL, $jobsnz_conn) or die(mysql_error()); $updateGoTo = "success.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?>
  9. I want to update two different fields on two different rows on submit I have a table called 'categories' and inside it has main categories and sub categories... categories cat_id parent_id cat_name counter sub_counter 1 0 MainOne 2 0 2 0 MainTwo 2 0 3 0 MainThree 1 0 4 0 MainFour 0 0 5 1 subOneA 0 1 6 1 subOneB 0 1 7 2 subTwoA 0 2 8 2 subTwoB 0 0 9 3 subThreeA 0 1 10 3 subThreeB 0 0 11 4 subFourA 0 0 12 4 subFourB 0 0 And i have a table 'auctions' auctions id title category parent_category 1 title1 5 1 2 title2 6 1 3 title3 7 2 4 title4 7 2 5 title5 9 3 When i insert a new record into 'auctions' i also want to update the counters in 'categories' so sub_counter increases by 1 on the row that matches the sub category selected by the user. And counter increases by 1 on the row that matches the main category selceted by the user example: If the user wants to insert a record with the main category as MainOne and in the sub category as subOneA the categories table will update so that the row that has cat_id of "1" will add 1 to the allready existing number in the field 'counter'. Then upadate the row that has cat_if of "5" by adding 1 to the existing number in the field sub_counter. So on the browse categories page i can echo the main category names and sub category names with the 'counter' number next to the main category names and 'sub_counter' number next to the sub category names to show how many records listed in each category. haha hope that makes sense Vesions in using: MySQL 5.0.45 PHP 5.2.5 APACHE 2.2.6
  10. what are you talking about?? At the moment i just want to know how to update 2 seperate fields on seperate rows at once from post data ill work out the increment later i want the inputs("counter" and "sub_counter" which equal 1) to post into the update query so my table will end up looking like this example.... cat_id parent_id name counter subcounter 1 0 one 1 0 2 1 sub 0 1 after ill change it so it will be like... UPDATE categories SET counter=counter+1(however itsdone) instead of using post at the moment my code only doing this... cat_id parent_id name counter subcounter 1 0 one 0 0 2 1 sub 1 1
  11. I know... i dont know how to do that. So what does that mean i have to do?
  12. Can anyone help me by looking at this code and telling me why it will only update one row. The fields im trying to update are sub_counter and counter but on seperate rows. I have a table 'categories' which has sub categoriges connected to main categories thru 'parent_id' When i insert a new record into 'auctions' i want the counter fields in 'categories' to update by adding 1 to their existing number where cat_id equals $_POST['sub_cat'] and parent_id equals $_POST['main_cat'] but its adding "1" to 'counter' and 'sub_counter' on the same row and only where cat_id equals $_POST['sub_cat'] this is example of table 'categories' cat_id | parent_id | cat_name | counter | sub_counter 1 0 MAINONE 0 0 2 0 MAINTWO 0 0 3 0 MAINTHREE 0 0 4 0 MAINFOUR 0 0 5 1 subOneA 0 0 6 1 subOneB 0 0 7 2 subTwoA 0 0 8 2 subTwoB 0 0 9 3 subThreeA 0 0 10 3 subThreeB 0 0 11 4 subFourA 0 0 12 4 subFourB 0 0 <?php require_once('Connections/jobsnz_conn.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "createAuction")) { $insertSQL = sprintf("INSERT INTO auctions (`user`, title, description, pict_url, category, parent_category, duration, start_price, location, payment, required_qual, required_ref, supply_material, deadline, preffered_day) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['user'], "text"), GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['description'], "text"), GetSQLValueString($_POST['image'], "text"), GetSQLValueString($_POST['sub_cat'], "int"), GetSQLValueString($_POST['main_cat'], "int"), GetSQLValueString($_POST['duration'], "int"), GetSQLValueString($_POST['startprice'], "double"), GetSQLValueString($_POST['check_location'], "text"), GetSQLValueString($_POST['payment'], "text"), GetSQLValueString($_POST['quals'], "text"), GetSQLValueString($_POST['refs'], "text"), GetSQLValueString($_POST['materials'], "text"), GetSQLValueString($_POST['deadline'], "date"), GetSQLValueString($_POST['day'], "text")); $updateSQL = sprintf("UPDATE categories SET sub_counter=%s WHERE cat_id=%s", GetSQLValueString($_POST['sub_counter'], "int"), GetSQLValueString($_POST['sub_cat'], "int")); $updateSQL2 = sprintf("UPDATE categories SET counter=%s WHERE parent_id=%s", GetSQLValueString($_POST['counter'], "int"), GetSQLValueString($_POST['main_cat'], "int")); mysql_select_db($database_jobsnz_conn, $jobsnz_conn); $Result1 = mysql_query($insertSQL, $jobsnz_conn) or die(mysql_error()); $Result2 = mysql_query($updateSQL, $jobsnz_conn) or die(mysql_error()); $Result2 = mysql_query($updateSQL2, $jobsnz_conn) or die(mysql_error()); } ?> <form action="<?php echo $editFormAction; ?>" method="POST" name="createAuction"> <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#0099FF"> <tr> <td><input name="counter" type="text" id="counter" value="1"> <input name="sub_counter" type="text" id="sub_counter" value="1"></td> <td><?php $main_cat = $_POST['category']; echo "<input name=\"main_cat\" type=\"text\" id=\"main_cat\" value=\"".$main_cat."\">" ?></td> </tr> <tr> <td> </td> <td><?php $user = $_SESSION['web_user']; echo "<input name=\"user\" type=\"text\" id=\"user\" value=\"".$user."\">" ?></td> </tr> <tr> <td>Sub Category </td> <td> <select name="sub_cat" id="sub_cat"> <?php $colname_rs_user = $_SESSION[ "web_user" ]; $sql_subcat = sprintf("SELECT cat_name, cat_id FROM categories WHERE parent_id = %s", $colname_rs_catid); $res_subcat = mysqli_query($mysqli, $sql_subcat); $sql_location = sprintf("SELECT city FROM a_users WHERE username = '$colname_rs_user'"); $res_location = mysqli_query($mysqli, $sql_location); if ($res_subcat) { while ($newArray = mysqli_fetch_array($res_subcat, MYSQLI_ASSOC)) { $name = $newArray['cat_name']; $id = $newArray['cat_id']; echo "<option value=\"".$id."\">".$name."</option>"; } mysqli_free_result($res_subcat); } else { printf("Could not retrieve records: %s\n", mysqli_error($mysqli)); } ?> </select> </td> </tr> <tr> <td>Title</td> <td><input name="title" type="text" id="title"></td> </tr> <tr> <td>Description</td> <td><textarea name="description" cols="50" id="description"></textarea></td> </tr> <tr> <td>Image</td> <td><input name="image" type="text" id="image"> <input type="submit" name="browse" value="Browse"></td> </tr> <tr> <td>Duration</td> <td> <select name="duration"> <option>7 Days</option> <option>14 Days</option> <option>28 Days</option> </select></td> </tr> <tr> <td>Start Price </td> <td><input name="startprice" type="text" id="startprice"></td> </tr> <tr> <td>Your Location</td> <td> <?php if ($res_location) { while ($newArray = mysqli_fetch_array($res_location, MYSQLI_ASSOC)) { $location = $newArray['city']; echo "<input name=\"check_location\" id=\"check_location\" type=\"radio\" value=\"".$location."\" checked>".$location."<br />"; } } ?> </td> </tr> <tr> <td>Specify Location</td> <td> <input name="check_specify_location" id="check_specify_location" type="radio" value="specify_location"><input name="specify_location" type="text"> </td> </tr> <tr> <td>Required Quals </td> <td><input name="quals" type="text" id="quals"></td> </tr> <tr> <td>Required Refs</td> <td><input name="refs" type="text" id="refs"></td> </tr> <tr> <td>Materials</td> <td><input name="materials" type="text" id="materials"></td> </tr> <tr> <td>Payment Method </td> <td><input name="payment" type="text" id="materials"></td> </tr> <tr> <td>Deadline</td> <td> <input name="deadline" type="text" id="deadline"> </td> </tr> <tr> <td>Preffered Day </td> <td><select name="day" id="day"> <option>Anytime</option> <option>Weekend</option> <option>Mon - Fri</option> </select></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit"></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> <input type="hidden" name="MM_insert" value="createAuction"> </form>
  13. this only brings the sub categories up after i post with a submit button. Is it possible for the main categories list to update the sub list instantly when a main category is selected? or is that beyond php?
  14. How do i get a list/menu to display records form DB depending on the selection on a previous list/menu? The first list has main categories and the second list has sub categories conected to the main Heres a small example of my db table: categoies cat_id | parent_id | cat_name 1 0 MainOne 2 0 MainTwo 3 1 SubOneA 4 1 SubOneB 5 2 SubTwoA 6 2 SubTwoB this is what i have for the first list <?php $mysqli = mysqli_connect("localhost", "root", "", "jobsnz"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $sqlcat_drop = "SELECT cat_name FROM categories WHERE parent_id = 0"; $rescat_drop = mysqli_query($mysqli, $sqlcat_drop); ?> <select name="categories"> <?php if ($rescat_drop) { while ($newArray = mysqli_fetch_array($rescat_drop, MYSQLI_ASSOC)) { $catname = $newArray['cat_name']; echo "<option>".$catname."</option>"; } } else { printf("Could not retrieve records: %s\n", mysqli_error($mysqli)); } ?> </select>
  15. bcraig

    sessions

    [!--quoteo(post=370832:date=May 3 2006, 06:11 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ May 3 2006, 06:11 AM) [snapback]370832[/snapback][/div][div class=\'quotemain\'][!--quotec--] Take out any instances of session_register as it is not needed. Doing $_SESSION[['username'] = $username would be sufficient. To create a session variable. [/quote] Yea didnt orginally have that in there but that dosent make a difference anyway.
×
×
  • 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.