PHP - Inserting Ids
when i insert a new topic into the database its id is generated by the auto incrememnt field tid.
but what i do next is insert the post for that new topic in the post table which has p_pid(post id) and p_tid(the topic id it is for). so how do i generate that p_tid when the topic has just been inserted. i used to do it by inserting the topic then running a query to pull the newest topic if from the database which would mean the post belonged to that topic. but what happens when people are posting several topics at the same time? Similar TutorialsHow can I insert a url in the body of an mail such that when the user clicks on it return the url string I am still having issues with getting the second part of this function to work right. It inserts fine into the first table but after that it's not performing the second insert. Code: [Select] function sendMessage($recipients, $bcc, $subject, $message, $sender) { $data = array( 'subject' => $subject, 'senderID' => $sender, 'message' => $message ); $this->db->insert('usersPersonalMessages', $data); $insertID = $this->db->insert_id(); foreach ($recipients AS $recipient) { $recipientData = array( 'usersPersonalMessagesID' => $insertID, 'userID' => $recipient ); } if ($bcc) { foreach ($bcc AS $userID) { $recipientData['userID'] = $userID; $recipientData['bcc'] = 1; } } $this->db->insert('usersPersonalMessagesRecipients', $recipientData); } Hey, Basically the script runs fine except for the fact its just inserting one user instead of multiple users, anyone have a clue as to why? would be a huge hand, Cheers Code: [Select] <?php if (isset($_POST["submit"]) && $_POST["submit"] == "Recall Selected Informants") { //Force POST values to be INTs $addIDs_ary = array_map('intval', $_POST['chkInv']); //Remove any 'false' value $addIDs_ary = array_filter($addIDs_ary); //Check that there was at least one valid value if(count($addIDs_ary)) { //Create comma separated string of the IDs $addIDs_str = implode(',', $addIDs_ary); //Create and run one query to perform all the adds (of the user) $query = "INSERT INTO hitlist SET hit_id = '($addIDs_str)' AND player_id = '$playerID'"; $sql = "UPDATE players SET Informants = Informants - 1 WHERE id = '$playerID'"; mysql_query($sql) or die(mysql_error()); if(mysql_query($query)) { $selectedCount = count($addIDs_ary); $adddCount = mysql_affected_rows(); echo "{$adddCount} of {$selectedCount} Investigated player(s) were successfully added."; }else{ echo "There was a problem running the query.<br>" . mysql_error(); } }else{ echo "Invalid ID data passed."; } } Code: [Select] elseif($_GET['rma']=="issue"){ session_start(); $rma_id=$_GET['id']; $_SESSION['rma_id']=$rma_id; $rma_issued=$_POST['rma_issued']; if($rma_issued=="y"){ $length = 2; $characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $string= microtime(true); for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } for ($p = 0; $p < $length; $p++) { $string2 .= $characters[mt_rand(0, strlen($characters))]; } $string="".$string2."".$string; $string=explode(".",$string); $string=$string[0].$string[1]; $rma_number=$string; date_default_timezone_set('US/Eastern'); $rma_date_issued = date("F j, Y, g:i A T"); $rma_month_issued = date("m"); $rma_year_issued = date("Y"); $sql2000000="UPDATE $tbl_name4 SET rma_number='$rma_number', rma_issued='$rma_issued', rma_date_issued='$rma_date_issued', rma_month_issued='$rma_month_issued', rma_year_issued='$rma_year_issued', returned='n' WHERE rma_id = $rma_id"; mysql_query($sql2000000); header("Location: ./acp_admincp.php?rma=issued"); } The above isn't inserting anything into the DB... not even the Date information. Hello guys, im wonder if ca i syntax the insert so i can insert some fields with alphabeticly shorting by name field Thanks hi i'm trying to insert this text just "we're pleased to announce etc........ect" but I can only insert "We" i believe its because single quotation mark. I've tried using addslashes, mysqli_real_escape_string and htmlspecialchars, strp_tags and applied it to my variable $s. But what ever i seem to try and insert still results in "we" being inserted. Cant see for the life of me why??? appreciate any help if (isset($_POST['submitted'])) { $errors = array(); if (empty($_POST['title'])) { $errors[] = '<p class="error">Either you haven\'t filled in the title or story for this news</p>'; } else { $t = mysqli_real_escape_string($dbc, $_POST['title']); } if (empty($_POST['story'])) { $errors[] = '<p class="error">Either you haven\'t filled in the title or story for this news</p>'; } else { $s = $_POST['story']; } echo $s; if(empty($errors)) { // No errors $q = "INSERT INTO news (title, story, date_added) values ('$t', '$s', NOW() )"; $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows == !1) { // It didnt run ok $errors[] = '<p class="error">An error occured with your upload<a href="loggedin.php"> Admin</a></p>'; } else { echo 'Your news story has been added, visit <a href="news.php">News</a>'; } //if mysqli_affected rows } else { echo '<p class="error">The following errors occured<br />'; foreach ($errors as $msg) { echo " - $msg<br>"; } echo 'Please try again'; } // end of $errors } // End of submitted This is my code i'm using :-) as you an see i'm posting the variable $s which is ($_POST['story'] with no functions and it still only inserts "we" nothing more????? All the variables are set for sure, anyone have any clue why the following isnt inserting anything into the db? Code: [Select] //### Query to insert new item into the database table "items" $query = "INSERT INTO `items`(`name`,`image`,`description`,`description2`,`description3`,`ItemType`,`cash_price `,`credit_price `,`GrowAmount`,`SellAmount`,`MaxOff`,`MaxDef`,`MaxHoes`,`Attack`,`Defense`,`Prestige`,`SafeLimit`,`ProductionQuality`,`ProductionWeight`,`HoDrugUsage`,`HoIncome`,`PurchaseDiscount`,`Informants`,`Pimpness`,`SalesPrice`,`SalesWeight`,`TroopDiscount`,`NotoReq`,`SCReq`,`PRReq`,`Buyable`,`ClassSpecific`,`Sellable`,`Multiple`) VALUES('{$name}','{$image}','{$description}','{$description2}','{$description3}','{$ItemType}','{$price}','{$creditprice}','{$GrowAmount}','{$SellAmount}','{$MaxOff}','{$MaxDef}','{$MaxHoes}','{$Attack}','{$Defense}','{$Prestige}','{$SafeLimit}','{$ProductionQuality}','{$ProductionWeight}','{$HoDrugUsage}','{$HoIncome}','{$PurchaseDiscount}','{$Informants}','{$Pimpness}','{$SalesPrice}','{$TroopDiscount}','{$NotoReq}','{$SCReq}','{$PRReq}','{$Buyable}','{$ClassSpecific}','{$Sellable}','{$Multiple}'"; //### Execute the above query mysql_query($query); Hi All, When inserting data into a DB I get a current timestamp using GETDATE() - however, I would like to insert a date that is say 3 working day's from the time the record was inserted. Is this possible? If so, how would I go about it? Thanks Matt Hi there reader(s) I've been searching everywhere, and I'm not one to post my issue unless I've searched as hard as I could, I'm not new to PHP, but I am new to MySQL (so go easy on me) and I've got variables all set up, and I've successfully established connection to my Database and my Database's table, but now I cannot find a way to insert the data (variable) into a column of the table. Willing to provide more information! Hi. Am trying to make an install script but have run into a problem. ---- variables.php - holds the variables that I need install.php - connects to the database and inserts all the values. Now I have a problem. When I execute the install.php it outputs: Creating tables... Connected to database server Database webleague is selected Players table Games table News table Rules table Games table Vars table Inserting default values Inserting news Inserting rules Inserting themes Inserting vars Done. but doesnt insert ANYTHING into the database. Can anyone help? Variables.php: <?php //start //configure database info $databaseserver = "localhost"; //usually localhost $databasename = "xxxxxxxxx"; //the name of your database $databaseuser = "xxxxxxxxx"; //the name of the database user $databasepass = "xxxxxxxxx"; // the password to your database $directory ="http://xxxxxxxxxxxxxxxxxx" ; //the location of your WebLeague directory (no trailing slash) //configure the tables in the database $playerstable = "webl_players"; //the name of the table that contains information about the players $gamestable = "webl_games"; //the name of the table that stores the played games $newstable = "webl_news"; // the name of the table that stores the news $themestable = "webl_themes"; //the name of the table that stores the themes $varstable = "webl_vars"; //the name of the table that stores various information $rulestable = "webl_rules"; //the name of the table the stores the rules //set some general information on your league $leaguename = "IRC League"; //the name of your league $title = ".: IRC League :."; //the title of your pages $favicon = "$directory/WebLeaguefavicon.ico" ; //the location of the shortcut icon $report = "winner"; //who reports? winner/loser $pointswin = "3"; //the number of points awarded for a win $pointsloss = "-1"; //the number of points awarded for a loss //set the username and password for the admin panel $LOGIN = "xxxxxxxxxx"; //the username to access the admin panel $PASSWORD = "xxxxxxxxx"; //the passoword to access the admin panel // finish ?> And this is install.php: Creating tables...<br><br> <?php include "variables.php"; $db = mysql_connect($databaseserver, $databaseuser, $databasepass) or die("Connection Failure to Database Server"); echo "Connected to database server<br>"; mysql_select_db($databasename, $db) or die ($databasename . " Database not found." . $databaseuser); echo "Database " . $databasename . " is selected<br><br>"; if ($db==false) die("Failed to connect to MySQL server<br>\n"); $sql = "CREATE TABLE $playerstable (player_id int(10) DEFAULT '0' NOT NULL auto_increment, name varchar(40) DEFAULT '' NOT NULL, passworddb varchar(10), mail varchar(50), icq varchar(15), aim varchar (40), country varchar(40), games int(10) DEFAULT '0', wins int(10) DEFAULT '0', losses int(10) DEFAULT '0', points int(10) DEFAULT '0', totalwins int(10) DEFAULT '0', totallosses int(10) DEFAULT '0', totalpoints int(10) DEFAULT '0', totalgames int(10) DEFAULT '0', penalties int(10) DEFAULT '0', staff varchar(10), streakwins int(10) DEFAULT '0', streaklosses int(10) DEFAULT '0', PRIMARY KEY (player_id))"; mysql_query($sql,$db); $sql = "ALTER TABLE $playerstable ADD UNIQUE(name) "; mysql_query($sql,$db); echo"Players table<br>"; $sql = "CREATE TABLE $gamestable (game_id int(10) DEFAULT '0' NOT NULL auto_increment, winner varchar(40), loser varchar(40), date varchar(40), PRIMARY KEY (game_id))"; mysql_query($sql,$db); echo"Games table<br>"; $sql = "CREATE TABLE $newstable (news_id int(10) DEFAULT '0' NOT NULL auto_increment, news text, PRIMARY KEY (news_id))"; mysql_query($sql,$db); echo"News table<br>"; $sql = "CREATE TABLE $rulestable (rules_id int(10) DEFAULT '0' NOT NULL auto_increment, rules text, PRIMARY KEY (rules_id))"; mysql_query($sql,$db); echo"Rules table<br>"; $sql = "CREATE TABLE $themestable (theme_id int(10) DEFAULT '0' NOT NULL auto_increment, name varchar(40), color1 varchar(40), color2 varchar(40), color3 varchar(40), color4 varchar(40), aimthemepic varchar(80), bottomleftpic varchar(80), bottommiddlepic varchar(80), bottomrightpic varchar(80), headerbgpic varchar(80), headermenuleftpic varchar(80), headermenurightpic varchar(80), sideleftpic varchar(80), siderightpic varchar(80), topleftpic varchar(80), topmiddlepic varchar(80), toprightpic varchar(80), PRIMARY KEY (theme_id))"; mysql_query($sql,$db); echo"Games table<br>"; $sql = "CREATE TABLE $varstable (vars_id int(10) DEFAULT '0' NOT NULL auto_increment, theme varchar(20), font varchar(80), fontcolor varchar(40), headerfont varchar(80), numgamespage int(10), numplayerspage int (10), statsview varchar(10), stats1view varchar(10), stats2view varchar(10), stats3view varchar(10), stats4view varchar(10), stats5view varchar(10), stats6view varchar(10), stats7view varchar(10), statsnum int(10), rulesview varchar(10), standingsnogames varchar(10), pctnum varchar(10), hotcoldnum varchar(10), gamesmaxday int(10), PRIMARY KEY (vars_id))"; mysql_query($sql,$db); echo"Vars table<br><br>"; echo"Inserting default values<br>"; $sql = "INSERT INTO $newstable (news) VALUES ('Welcome to WebLeague<br><br>WebLeague is an automated league system, that makes organizing an online league a piece of cake.<br><br>To put your own news here, go to the news section in your admin panel<br><br>Have fun using WebLeague')"; mysql_query($sql,$db); echo"Inserting news<br>"; $sql = "INSERT INTO $rulestable (rules) VALUES ('Insert your rules by going to the rules section in the admin panel')"; mysql_query($sql,$db); echo"Inserting rules<br>"; $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('blue','#0080FF','#000066', '#FFFFFF', '#000099', '/themes/blue/aim.jpg', '/themes/blue/bottomleft.jpg', '/themes/blue/bottommiddle.jpg', '/themes/blue/bottomright.jpg', '/themes/blue/headerbg.jpg', '/themes/blue/headermenuleft.jpg', '/themes/blue/headermenuright.jpg', '/themes/blue/sideleft.jpg', '/themes/blue/sideright.jpg', '/themes/blue/topleft.jpg', '/themes/blue/topmiddle.jpg', '/themes/blue/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('blue2','#66809A','#29293D', '#FFFFFF', '#444466', '/themes/blue2/aim.jpg', '/themes/blue2/bottomleft.jpg', '/themes/blue2/bottommiddle.jpg', '/themes/blue2/bottomright.jpg', '/themes/blue2/headerbg.jpg', '/themes/blue2/headermenuleft.jpg', '/themes/blue2/headermenuright.jpg', '/themes/blue2/sideleft.jpg', '/themes/blue2/sideright.jpg', '/themes/blue2/topleft.jpg', '/themes/blue2/topmiddle.jpg', '/themes/blue2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('red','#FF0000','#660000', '#FFFFFF', '#990000', '/themes/red/aim.jpg', '/themes/red/bottomleft.jpg', '/themes/red/bottommiddle.jpg', '/themes/red/bottomright.jpg', '/themes/red/headerbg.jpg', '/themes/red/headermenuleft.jpg', '/themes/red/headermenuright.jpg', '/themes/red/sideleft.jpg', '/themes/red/sideright.jpg', '/themes/red/topleft.jpg', '/themes/red/topmiddle.jpg', '/themes/red/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('red2','#9A666C','#3D2929', '#FFFFFF', '#664444', '/themes/red2/aim.jpg', '/themes/red2/bottomleft.jpg', '/themes/red2/bottommiddle.jpg', '/themes/red2/bottomright.jpg', '/themes/red2/headerbg.jpg', '/themes/red2/headermenuleft.jpg', '/themes/red2/headermenuright.jpg', '/themes/red2/sideleft.jpg', '/themes/red2/sideright.jpg', '/themes/red2/topleft.jpg', '/themes/red2/topmiddle.jpg', '/themes/red2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('green','#00FF00','#006600', '#FFFFFF', '#009900', '/themes/green/aim.jpg', '/themes/green/bottomleft.jpg', '/themes/green/bottommiddle.jpg', '/themes/green/bottomright.jpg', '/themes/green/headerbg.jpg', '/themes/green/headermenuleft.jpg', '/themes/green/headermenuright.jpg', '/themes/green/sideleft.jpg', '/themes/green/sideright.jpg', '/themes/green/topleft.jpg', '/themes/green/topmiddle.jpg', '/themes/green/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('green2','#6C9A66','#2D3D29', '#FFFFFF', '#446644', '/themes/green2/aim.jpg', '/themes/green2/bottomleft.jpg', '/themes/green2/bottommiddle.jpg', '/themes/green2/bottomright.jpg', '/themes/green2/headerbg.jpg', '/themes/green2/headermenuleft.jpg', '/themes/green2/headermenuright.jpg', '/themes/green2/sideleft.jpg', '/themes/green2/sideright.jpg', '/themes/green2/topleft.jpg', '/themes/green2/topmiddle.jpg', '/themes/green2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('orange','#FF8000','#662200', '#FFFFFF', '#994000', '/themes/orange/aim.jpg', '/themes/orange/bottomleft.jpg', '/themes/orange/bottommiddle.jpg', '/themes/orange/bottomright.jpg', '/themes/orange/headerbg.jpg', '/themes/orange/headermenuleft.jpg', '/themes/orange/headermenuright.jpg', '/themes/orange/sideleft.jpg', '/themes/orange/sideright.jpg', '/themes/orange/topleft.jpg', '/themes/orange/topmiddle.jpg', '/themes/orange/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('orange2','#9A7E66','#3D3129', '#FFFFFF', '#664444', '/themes/orange2/aim.jpg', '/themes/orange2/bottomleft.jpg', '/themes/orange2/bottommiddle.jpg', '/themes/orange2/bottomright.jpg', '/themes/orange2/headerbg.jpg', '/themes/orange2/headermenuleft.jpg', '/themes/orange2/headermenuright.jpg', '/themes/orange2/sideleft.jpg', '/themes/orange2/sideright.jpg', '/themes/orange2/topleft.jpg', '/themes/orange2/topmiddle.jpg', '/themes/orange2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('purple','#9900FF','#330066', '#FFFFFF', '#660099', '/themes/purple/aim.jpg', '/themes/purple/bottomleft.jpg', '/themes/purple/bottommiddle.jpg', '/themes/purple/bottomright.jpg', '/themes/purple/headerbg.jpg', '/themes/purple/headermenuleft.jpg', '/themes/purple/headermenuright.jpg', '/themes/purple/sideleft.jpg', '/themes/purple/sideright.jpg', '/themes/purple/topleft.jpg', '/themes/purple/topmiddle.jpg', '/themes/purple/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('purple2','#83669A','#32293D', '#FFFFFF', '#664466', '/themes/purple2/aim.jpg', '/themes/purple2/bottomleft.jpg', '/themes/purple2/bottommiddle.jpg', '/themes/purple2/bottomright.jpg', '/themes/purple2/headerbg.jpg', '/themes/purple2/headermenuleft.jpg', '/themes/purple2/headermenuright.jpg', '/themes/purple2/sideleft.jpg', '/themes/purple2/sideright.jpg', '/themes/purple2/topleft.jpg', '/themes/purple2/topmiddle.jpg', '/themes/purple2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('black','#666666','#000000', '#FFFFFF', '#999999', '/themes/black/aim.jpg', '/themes/black/bottomleft.jpg', '/themes/black/bottommiddle.jpg', '/themes/black/bottomright.jpg', '/themes/black/headerbg.jpg', '/themes/black/headermenuleft.jpg', '/themes/black/headermenuright.jpg', '/themes/black/sideleft.jpg', '/themes/black/sideright.jpg', '/themes/black/topleft.jpg', '/themes/black/topmiddle.jpg', '/themes/black/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('yellow','#FFEF00','#635200', '#FFFFFF', '#999900', '/themes/yellow/aim.jpg', '/themes/yellow/bottomleft.jpg', '/themes/yellow/bottommiddle.jpg', '/themes/yellow/bottomright.jpg', '/themes/yellow/headerbg.jpg', '/themes/yellow/headermenuleft.jpg', '/themes/yellow/headermenuright.jpg', '/themes/yellow/sideleft.jpg', '/themes/yellow/sideright.jpg', '/themes/yellow/topleft.jpg', '/themes/yellow/topmiddle.jpg', '/themes/yellow/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('yellow2','#9A9666','#3D3A29', '#FFFFFF', '#666644', '/themes/yellow2/aim.jpg', '/themes/yellow2/bottomleft.jpg', '/themes/yellow2/bottommiddle.jpg', '/themes/yellow2/bottomright.jpg', '/themes/yellow2/headerbg.jpg', '/themes/yellow2/headermenuleft.jpg', '/themes/yellow2/headermenuright.jpg', '/themes/yellow2/sideleft.jpg', '/themes/yellow2/sideright.jpg', '/themes/yellow2/topleft.jpg', '/themes/yellow2/topmiddle.jpg', '/themes/yellow2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('pink','#FF00EF','#660066', '#FFFFFF', '#990099', '/themes/pink/aim.jpg', '/themes/pink/bottomleft.jpg', '/themes/pink/bottommiddle.jpg', '/themes/pink/bottomright.jpg', '/themes/pink/headerbg.jpg', '/themes/pink/headermenuleft.jpg', '/themes/pink/headermenuright.jpg', '/themes/pink/sideleft.jpg', '/themes/pink/sideright.jpg', '/themes/pink/topleft.jpg', '/themes/pink/topmiddle.jpg', '/themes/pink/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('pink2','#9A6696','#3C293D', '#FFFFFF', '#664466', '/themes/pink2/aim.jpg', '/themes/pink2/bottomleft.jpg', '/themes/pink2/bottommiddle.jpg', '/themes/pink2/bottomright.jpg', '/themes/pink2/headerbg.jpg', '/themes/pink2/headermenuleft.jpg', '/themes/pink2/headermenuright.jpg', '/themes/pink2/sideleft.jpg', '/themes/pink2/sideright.jpg', '/themes/pink2/topleft.jpg', '/themes/pink2/topmiddle.jpg', '/themes/pink2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('greenblue','#00FFEA','#006654', '#FFFFFF', '#009999', '/themes/greenblue/aim.jpg', '/themes/greenblue/bottomleft.jpg', '/themes/greenblue/bottommiddle.jpg', '/themes/greenblue/bottomright.jpg', '/themes/greenblue/headerbg.jpg', '/themes/greenblue/headermenuleft.jpg', '/themes/greenblue/headermenuright.jpg', '/themes/greenblue/sideleft.jpg', '/themes/greenblue/sideright.jpg', '/themes/greenblue/topleft.jpg', '/themes/greenblue/topmiddle.jpg', '/themes/greenblue/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('greenblue2','#679B97','#293D39', '#FFFFFF', '#446666', '/themes/greenblue2/aim.jpg', '/themes/greenblue2/bottomleft.jpg', '/themes/greenblue2/bottommiddle.jpg', '/themes/greenblue2/bottomright.jpg', '/themes/greenblue2/headerbg.jpg', '/themes/greenblue2/headermenuleft.jpg', '/themes/greenblue2/headermenuright.jpg', '/themes/greenblue2/sideleft.jpg', '/themes/greenblue2/sideright.jpg', '/themes/greenblue2/topleft.jpg', '/themes/greenblue2/topmiddle.jpg', '/themes/greenblue2/topright.jpg')"; mysql_query($sql,$db); echo"Inserting themes<br>"; $sql = "INSERT INTO $varstable (theme, font, fontcolor, headerfont, numgamespage, numplayerspage, statsview, stats1view, stats2view, stats3view, stats4view, stats5view, stats6view, stats7view, statsnum, rulesview, standingsnogames, pctnum, hotcoldnum, gamesmaxday) VALUES ('blue','Arial', '#FFFFFF', 'Arial Black', '20', '30', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', '10', 'yes', 'no', '10', '5', '2')"; mysql_query($sql,$db); echo"Inserting vars<br><br>"; echo"Done."; ?> Once again... it says its done when i execute the code in the browser but is not inserting anything into my database. Weird... Hi, I have a MySQL table with a timestamp field. I want this field to be automatically updated with the current date and time when a record is updated. How do I do that? This is my update query. Thanks: Code: [Select] $Sql="UPDATE MyTable SET client_alias='$client_alias',testimonial_date='$testimonial_date',order_ontime='$order_ontime',how_deal='$how_deal',order_condition='$order_condition',happy_colour='$happy_colour',colour_chosen='$colur_chosen',easy_use='$easy_use',effectiveness='$effectiveness',client_comments_eng='$client_comments_eng',client_comments_esp='$client_comments_esp',testimonial_updated_by='$testimonial_updated_by', _time_stamp='?????????' WHERE id_testimonial='$colname_testimonials_update_RS'"; mysql_query($Sql) or die('Error, query failed : ' . mysql_error()); Hi guys..... I'm having a problem that I've been tearing my hair out over for way too long. I'm hoping that some of you may be able to help me or at least point me in the right direction. I'm using MySQL 5.0.91 (via PHPmyAdmin from GoDaddy). This query should basically grab the data from the Facebook API and insert it into the database. It's not doing that. After inserting the data, it queries the database, and redirects the user to their profile page (USERNAME.php). Because there is no data in the database for that user, it has no idea what their username is, so it redirects them to ".php"....yes, that is "[dot]php". I'm not entirely sure how to debug this either. I've tried a few var_dump()'s with not much luck. Is there a specific order in which this stuff needs to be in? Maybe that's the problem, so I'm also including a screenshot from PHPmyAdmin of the database table. Here's the code: // user not in db, insert details if(!empty($user)){ $apiGet = array( 'method' => 'users.getinfo', 'uids' => $uid, 'fields' => 'uid, name, first_name, last_name, pic_square, pic_big, sex, email, birthday_date, activities, interests, status, about_me' //theses are the fields it pulls from the Facebook API ); // create array to hold returned values $fbi = $facebook->api($apiGet); // insert details $iString = "oauth_provider, oauth_uid, username, name, first_name, last_name, sex, pic_big, email, joined, lastLogon, birthday_date, user_activities, user_interests, user_status, user_about_me"; $iArray = array(); //the following are the values of the fields array_push($iArray,'facebook'); array_push($iArray,$user['id']); array_push($iArray,$user['name']); array_push($iArray,$fbi[0]['name']); array_push($iArray,$fbi[0]['first_name']); array_push($iArray,$fbi[0]['last_name']); array_push($iArray,$fbi[0]['sex']); array_push($iArray,$fbi[0]['pic_big']); array_push($iArray,$fbi[0]['email']); array_push($iArray,time()); array_push($iArray,time()); array_push($iArray,$fbi[0]['birthday_date']); array_push($iArray,$fbi[0]['user_activities']); array_push($iArray,$fbi[0]['user_interests']); array_push($iArray,$fbi[0]['user_status']); array_push($iArray,$fbi[0]['user_about_me']); var_dump($email); $db->insert('users',$iArray,$iString); $where = "oauth_uid = '{$uid}'"; $db->select('*','users',$where); $result = $db->getResult(); // the next line creates a profile page. After that, there are lines that point the user to that page. createProfile($result['username']); I've added some comments to it to articulate what is going on. Thanks in advance! Alex if (($update_avatar1 == 'http://images.toxicpets.co.cc/vPets/Acara11.gif') OR ($update_avatar1 == 'http://images.toxicpets.co.cc/vPets/Aisha5.gif')) { mysql_query("UPDATE avatar SET avatar = '$update_avatar1' WHERE username = '$username' AND game = '$game'") or die ("Database error: ".mysql_error()); mysql_query("INSERT INTO avatar ($update_avatar1 WHERE id = '$userid')"); This is an avatar System But It Is Not Inserting Into The Database Can someone please help me figure out how to insert "image" from table users, that contains the .jpg data associated with "screen_name", into table friends "friendimg" Here are the tables: friends: id, member, friendwith, friendimg users: id, screen_name, image $_GET["id"] only contains "screen_name" and"image" is not included add.php Code: [Select] <?php if(isset($_GET["id"])) { echo "<br/><a href=\"member?add=".$_GET["id"]."\">Add ".$_GET["id"]." to your list of friends</a>"; } ?>member.php Code: [Select] <?php if(isset($_GET["add"])) { $username = $_SESSION["screen_name"]; $friend = $_GET["add"]; $query = "SELECT * FROM friends WHERE member='$username' AND friendwith='$friend'"; $result = mysql_query($query); $exist = mysql_num_rows($result); if($exist=='0') { $query = "INSERT INTO friends(member,friendwith) VALUES('$username','$friend')"; mysql_query($query); echo "<br/>You are now friends with $friend"; } else { echo "<br/>$friend is already in your list of friends!"; } } ?> I don't know DOM very well. I can split html code into an array by paragraph and insert new lines, just not at the beginning. When I do $p_nodes->item(0)->insertBefore, it inserts the line after item(0). Here's an overview: Code: [Select] <I want to insert a line here> <p> line one </p> <I can insert a line here> <p> line two</p> etc Here's the php code: $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadHTML($html); $dom->encoding = 'UTF-8'; $content_xpath = new DOMXPath($dom); //Find paragraphs $p_nodes = $content_xpath->evaluate('//p'); //Add the new element $insertLine = $dom->createdocumentFragment(); $insertLine->appendXML('<div>hello</div>'); //$p_nodes->item(0)->appendChild($insertLine); //this inserts the new line after line 1 $p_nodes->item(0)->insertBefore($insertLine); //this inserts after, same as appendchild $html = $dom->saveHTML(); Note: this code is greatly simplified- I would love to just concatenate the new line, but trust me- its not possible, it needs to be done with DOM. Im trying to choose what I want the id to be set to when I create a row on another table using this code below it tells me "unknown column "id" in 'field list' making me think it has to asign a random id first Code: [Select] <?php $d1 = "SELECT id FROM game WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; $b1 = mysql_query($d1) or die(mysql_error()); $c1 = mysql_fetch_array($b1); if (empty($c1['id'])) { $a1 = "INSERT INTO game SET id = '".$_SESSION['user_id']."'"; mysql_query($a1) or die(mysql_error()); ?> how do i insert two same values bearing variable into the same row though different column into a database? Insertion was successful but at the end I always end up getin an error for which I was not allowed a redirection...thanx error: Code: [Select] 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 ') VALUES('spaceman12', 'ja')' at line 1 Hi, I have this code to retrieve currency exchange rates from the ECB: Code: [Select] <?php $XMLContent=file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"); //the file is updated daily between 2.15 p.m. and 3.00 p.m. CET foreach($XMLContent as $line){ if(preg_match("/currency='([[:alpha:]]+)'/",$line,$currencyCode)){ if(preg_match("/rate='([[:graph:]]+)'/",$line,$rate)){ //Output the value of 1EUR for a currency code echo'1€='.$rate[1].' '.$currencyCode[1].'<br/>'; //-------------------------------------------------- //Here you can add your code for inserting //$rate[1] and $currencyCode[1] into your database //-------------------------------------------------- } } } ?> I have a DB with 2 fields, one is for the exchange rate (rate) and the other for thecurrency name (currencyCode). My problem is that I don't know how to insert the $rate[1] and $currencyCode[1] in my DB. Thanks for your help. This code will not insert OR update. But on the other ones it will.. but for this one, I'm doing an extra step to say that they can claim the item or not. From adding that extra step, it won't insert or update. Code: [Select] $rand = rand(1,3); if ($rand == 1) { $rand = rand(1,3); if($rand == 1) { $sql = "SELECT * FROM randomevents WHERE rarity = '1'"; $result = mysqli_query($cxn, $sql); while ($row = mysqli_fetch_assoc($result)) { $event[] = $row['phrase']; } //This will pick a random event and show it $renum = rand(0,count($event)-1); $display = $event[$renum]; if ($display == "") { $eventdisplay = ""; } else { $sql = "SELECT * FROM randomevents WHERE phrase='".mysqli_real_escape_string($cxn,$display)."'"; $result = mysqli_query($cxn, $sql) or die("Query died: select everything from randomevent table"); $row = mysqli_fetch_array($result); $itemid = $row['itemid']; $image = $row['image']; if ($row['type'] == "itemgain") { $sql2 = "SELECT name, image FROM items WHERE itemid='".$itemid."'"; $result2 = mysqli_query($cxn, $sql2) or die(mysqli_error($cxn)); $row2 = mysqli_fetch_assoc($result2); $itemname = $row2['name']; $itemimage = $row2['image']; $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"> <tr> <td width=\"350px\"><center><b><h1>Random Event</h1></b></center></td> </tr> <tr> <td><img src=\"http://www.elvonica.com/".$image."\" style=\"position:relative;float:left;\"> <p><center>".$display."</center></p> <p> <form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"post\"> <input type=\"submit\" name=\"claimitem\" value=\"Claim Egg!\" /> </form> </p> </td> </table><br>"; if (isset($_POST['claimitem'])) { $sql = "SELECT * FROM useritems WHERE itemid='".$itemid."' AND userid='".$_SESSION['userid']."'"; $result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn)); $num = mysqli_num_rows($result); if ($num == 0) { $sql = "INSERT INTO useritems (userid, itemid, name, image, quantity) VALUES ('".$_SESSION['userid']."', '".$itemid."', '".$itemname."', '".$itemimage."', '1')"; mysqli_query($cxn, $sql) or die("Query died: insert for itemgain"); } else { $sql = "UPDATE useritems SET quantity = quantity+1 WHERE itemid='".$itemid."' AND userid='".$_SESSION['userid']."'"; mysqli_query($cxn, $sql) or die("Query died: update for itemgain"); $eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"> <tr> <td width=\"350px\"><center><b><h1>Random Event</h1></b></center></td> </tr> <tr> <td><img src=\"http://www.elvonica.com/".$image."\" style=\"position:relative;float:left;\"> <p><center>".$display."</center></p> </td> </table><br>"; } } } } } } |