PHP - Form Not Updating
I can't get my form to update the database with user personal information. Any help greatly appreciated. Upon submitting the form, it just reloads the page, no information added to the DB. I used the update statement because I want the users to be able to update the info at a later date. Not sure if that was the right thing to do. thank you.
Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); include('bouncer.php'); $host = ""; $database = ""; $username = ""; $password = ""; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); } else { echo "failed to select database"; } $currentUser = $_SESSION['myusername']; // get user from login and make it current user to use for update statement echo "Login success!<br/>"; echo "Please fill out the form below to add your personal information to the database<br/>"; ////////////////////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['submit'])) { $firstname = mysql_real_escape_string( $_POST['first']); $lastname = mysql_real_escape_string( $_POST['last']); $dob = mysql_real_escape_string( $_POST['dob']); $gender = mysql_real_escape_string( $_POST['gender']); $result= mysql_query ( "UPDATE users SET firstname = '$firstname', lastname = '$lastname', dob = '$dob', gender='$gender' WHERE username='$currentUser'") or die(mysql_error()); if($result) { echo "your information was updated in the database and is as follows <br/>"; //put the results on the screen echo "<br/> $firstname <br/>"; echo "<br/>$lastname <br/>"; echo "<br>$dob <br/> "; echo ">$gender <br>"; } else { echo "error, could not update your info to the database </br>";//end if result } }//end if sumbit post statement at top ?> <html> <body> <p> </p> <p> </p> <p> <form action="login_successERROR.php" method="post"> <p> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="text" name="gender" size="20" id="gender" /> Gender <br /> <input type="submit" value="Add personal information to database" /> <input type="reset" value="Reset fields" /> </p> </p> </form> <p><a href="index.php">HOME</a></p> <p> </p> </body> </html> Similar TutorialsHi there im going a little bit mad now.... i spent a while trying to work out why my form didnt update or redirect... After head scratching i remade a test form... That also doesnt update or redirect?? I must be missing something here?? So basically when the user clicks submit nothing happens, why?? Code: [Select] <?php require_once('Connections/swb.php'); ?> <?php session_start(); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $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; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE player SET `Day`=%s WHERE PlayerName=%s", GetSQLValueString($_POST['days'], "int"), GetSQLValueString($_POST['playername'], "text")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($updateSQL, $swb) or die(mysql_error()); $updateGoTo = "logout.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST"> <input type="button" value="End Turn" /> <input name="days" type="hidden" id="days" value="1"/> <input name="playername" type="hidden" id="playername" value="<?php echo $_SESSION['MM_Username']; ?>"> <input type="hidden" name="MM_update" value="form1"> </form> </body> </html> Thanks I want to write a guessing game that gives a user four tries to guess a number between 1 and 10. The problem is that every time the user hits submit, count is reset to zero and 1 is added. Please help. Here is my code: <html> <head> <title>Guessing Game </title> </head> <h1>Guessing Game </h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="hidden" name="count" value="<?php $count++; ?>" /> <p><input type="text" name="guess" /></p> <p><input type="submit" value="Guess" /></p> </form> </body> </html> <?php $random = rand(1,10); $guess = $_POST['guess']; if ($guess >= 10) { echo"Guess has to be lower than 10"; } elseif (isset($guess) && ($guess <= 1)) { echo "Guess has to be higher than 1"; } else { if ($guess == $random) { echo "Congratulations. You Win!!!!"; $count = 4; } elseif (isset($guess) && ($guess != $random)) { echo "Try again"; $count++; } elseif (($count == 4) && ($guess != $random)) { echo "Game Over. You Lose!!!"; } } ?> Code: [Select] <?php $host="xxxx"; // Host name $username="xxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="xxxx"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $model_id=$_GET['model_id']; // Retrieve data from database $sql="SELECT model_id, model_name, location, email_1 FROM $tbl_name WHERE model_id='$model_id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="updated.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>Location</strong></td> <td align="center"><strong>Email</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['model_name']; ?>"></td> <td align="center"><input name="location" type="text" id="location" value="<? echo $rows['location']; ?>"></td> <td><input name="email" type="text" id="email" value="<? echo $rows['email_1']; ?>"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['model_id']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <? // close connection mysql_close(); ?> This is the part that isn't working Code: [Select] <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['model_name']; ?>"></td> <td align="center"><input name="location" type="text" id="location" value="<? echo $rows['location']; ?>"></td> <td><input name="email" type="text" id="email" value="<? echo $rows['email_1']; ?>"></td> The echo values aren't being fetched and left blank when I run the script. Any ideas? Hi, when someone logs in to my page, i have a form displayed with names, address, etc...what i need to do is when i hit the update button for that information to go into the MYSQL table I have created and over write that information if a user updates...so how do i do that? hi, I've looked around and not seen an answer that fits my situation, so here goes. I've got a database and I have a script that displays the values from that database in editable fields and has an update button this is that script: <?php session_start(); include("dbinfo.inc.php"); mysql_connect($servname,$dbusername,$dbpassword); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM ($newdbname) "; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $username=mysql_result($result,$i,"username"); $password=mysql_result($result,$i,"password"); //$real_name=mysql_result($result,$i,"real_name"); echo "$username, $password, $real_name"; ?> <form action="updated.php"> <input type="hidden" name="ud_id" value="<? echo "$id"; ?>"> Username: <input type="text" name="username" value="<? echo "$username"?>"><br> Password: <input type="text" name="password" value="<? echo "$password"?>"><br> <input type="Submit" value="Update"> </form> <?php ++$i; } ?> it passes the "updated" values to this script: <?php session_start(); include("dbinfo.inc.php"); mysql_connect($servname,$dbusername,$dbpassword); $query="INSERT $newdbname SET username (user_id, username, password)='$ud_username', password= PASSWORD('$ud_password') WHERE id='$ud_id'"; @mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); echo "Record Updated"; mysql_close(); ?> I get no errors, and everything runs just fine. except it doesn't update any thing. I'm sure it's a simple thing I'm missing, stupid lack of experience hindering me. any help would be greatly appreciated! Hey guys, I have made an admin page for a game Im working on to quickly allow me to update many aspects of the game. My form is sending the correct data because i can echo the $_post but for some reason it isnt updating my database. I just get a blank white page. Could anyone see what i have done wrong. Thanks Code: [Select] <?php require($DOCUMENT_ROOT . "/game/includes/connection.php"); require($DOCUMENT_ROOT . "/game/includes/settings.php"); ?> <?php $name = $_POST['admin_name']; $img = $_POST['admin_img']; $current_hp = $_POST['admin_current_hp']; $max_hp = $_POST['admin_max_hp']; $current_energy = $_POST['admin_current_energy']; $max_energy = $_POST['admin_max_energy']; $level = $_POST['admin_level']; $exp_total = $_POST['admin_exp_total']; $exp = $_POST['admin_exp']; $exp_level = $_POST['admin_exp_level']; $pos_x = $_POST['admin_pos_x']; $pos_y = $_POST['admin_pos_y']; $potion = $_POST['admin_potion']; $ether = $_POST['admin_ether']; $elixir = $_POST['admin_elixir']; $zenni = $_POST['admin_zenni']; $sector = $_POST['admin_sector']; $battle = $_POST['admin_battle']; ?> <?php $sql_1 = "UPDATE game_character SET name='$name', img='$img', current_hp='$current_hp', max_hp='$max_hp', current energy='$current_energy', max_energy='$max_energy', level='$level', exp_total='$exp_total', exp='$exp', exp_level='$exp_level', pos_x='$pos_x', pos_y='$pos_y', potion='$potion', ether='$ether', elixir='$elixir', zenni='$zenni' WHERE id=1"; $sql_2 = "UPDATE game_status SET sector='$sector', battle='$battle' WHERE id=1"; $statement_1 = $dbh->prepare($sql_1); $statement_2 = $dbh->prepare($sql_2); $statement_1->execute(); $statement_2->execute(); ?> <SCRIPT LANGUAGE="JavaScript"> redirTime = "1"; redirURL = "<?php echo $r_admin ?>"; function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); } </script> <BODY onLoad="redirTimer()"> Hi I making some forms that write to mysql database, Im now in the process of making the update form so the user can update there details on the form, I want it to populate the form with existing data but its not doing it at all. Thanks in advance
Attached Files
delete.php 210bytes
2 downloads
modify.php 4.03KB
4 downloads
index.php 473bytes
3 downloads Here goes.
I am trying to retrieve info. from mySql database and update 3 textfields.
I also have 4 selects on the form that need populating during the running of the program. My problem is using console I can see the info - Customer name - but it does not appear in the text field. The onchange request in the DIV container seems to be where it fails. Here are the files I am using:
1. add_an_order.php
<html> <head> <title>Add an Order</title> <link href = "css/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="include/jquery-1.11.1.min.js"></script> </head> <body> <div id="header"><img src="images/logo.png" /></div> <div id="nav"> <div id="nav_wrapper"> <ul> <li><a href="index.php">Orders</a></li><li> <a href="customers.php">Customers</a></li><li> <a href="contacts.php">Contacts</a></li><li> <a href="batteries.php">Batteries</a></li><li> <a href="#">Queries</a> </li> </ul> </div> </div> <div id="main"> <?php echo '<h3 id="menOpt">Add an Order</h3><hr>'; // Check for a form submission. /* if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); $required_fields = array('customer_name', 'customer_address', 'city', 'telephone'); foreach ($required_fields as $fieldname) { if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { $errors[] = strtoupper($fieldname); } } if (empty($errors)) { include ('include/dbconnect.php'); $name = mysqli_real_escape_string($con, trim(strip_tags($_POST['customer_name']))); $contact = mysqli_real_escape_string($con, trim(strip_tags($_POST['contact']))); $address = mysqli_real_escape_string($con, trim(strip_tags($_POST['customer_address']))); $city = mysqli_real_escape_string($con, trim(strip_tags($_POST['city']))); $telephone = mysqli_real_escape_string($con, trim(strip_tags($_POST['telephone']))); $telephone = preg_replace('/[^0-9]/', '', $telephone); if (isset($_POST['deepc'])) { $deepc = 1; } else { $deepc = 0; } if (isset($_POST['problemc'])) { $problemc = 1; } else { $problemc = 0; } $problem = mysqli_real_escape_string($con, trim(strip_tags($_POST['problem']))); if (isset($_POST['blacklist'])) { $blacklist = 1; } else { $blacklist = 0; } if (isset($_POST['pickup'])) { $pickup = 1; } else { $pickup = 0; } $query = "INSERT INTO customers ( customer_name, contact, customer_address, city, telephone, deep_cycle, problem_customer, problem, blacklist, pickup) VALUES ('$name', '$contact', '$address', '$city', '$telephone', $deepc, $problemc, '$problem', $blacklist, $pickup)"; $r = mysqli_query($con, $query); if (mysqli_affected_rows($con) == 1) { echo '<p class="success">Customer has been successfully added.</p>'; } else { $message = "Could not add customer."; $message .= "<br />" . mysqli_error($con); } mysqli_close($con); } else { // We have errors. $message = count($errors) . " error(s) on the form."; } } // End: if ($_SERVER['REQUEST_METHOD'] == 'POST'). */ // Leave PHP and display the form. ?> <?php if (!empty($message)) { echo '<p class="error">' . $message . '</p>'; } ?> <?php // Output list of fields that have errors. if (!empty($errors)) { echo '<p class="error">'; foreach ($errors as $error) { echo $error . '<br />'; } echo '</p>'; } ?> <div class="container"> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <label>Business: <span class="important"> *</span><select name="customer_name" id="customer_name" onchange="request_fill(this.value)" value="<?php if (isset($_POST['customer_name'])) echo $_POST['customer_name']; ?>" ></select></label> <label>Address: <input type="text" name="address" id="add_a" value="<?php if (isset($_POST['customer_address'])) echo $_POST['customer_address']; ?>" /></label> <label>City: <input type="text" name="city" id="city" value="<?php if (isset($_POST['city'])) echo $_POST['city']; ?>" /></label> <label>Phone: <input type="text" name="telephone" value="<?php if (isset($_POST['telephone'])) echo $_POST['telephone']; ?>" /></label> <label>Manufacturer: <span class="important"> *</span><select name="manufacturer" id="manufacturer" onchange="request_mod(this.value)" value="<?php if (isset($_POST['manufacturer'])) echo $_POST['manufacturer']; ?>" ></select></label> <label>Model: <span class="important"> *</span><select name="model" id="model" onchange="form_yr(this.value)" value="<?php if (isset($_POST['model'])) echo $_POST['model']; ?>" ></select></label> <label>Year: <span class="important"> *</span><select name="battery" id="bat_disp" value="<?php if (isset($_POST['battery'])) echo $_POST['year'] ?>" ></select></label> <label>Quantity: <span class="important"> *</span><input type="text" name="quantity" id="quantity" value="<?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>" /></label> <label>Warranty ? <input type="checkbox" name="warranty" <?php if ($_POST['warranty']) echo " checked"; ?> /></label> <label>Exchange ? <input type="checkbox" name="exchange" <?php if ($_POST['exchange']) echo " checked"; ?> /></label> <input type="submit" name="submit" value="Add Order" /> or <a href="index.php">Cancel</a> </fieldset> </form> </div> <script type="text/javascript" src="include/functions.js"></script> <script> $(document).ready(function() { $('.container').hide(); $('.container').fadeIn(1000); request_cust(); request_man(); }); </script> <?php include ('include/footer.php'); 2. request_fill function request_fill() { var cust2 = 'customer'; var ad = document.getElementById("add_a"); var hr = new XMLHttpRequest(); hr.open("POST", "battery_parser.php", true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var dataArray = hr.responseText; ad.innerHTML = dataArray[1]; } } hr.send("&cust2="+cust2); } 3. battery_parser.php <?php include_once("include/dbconnect.php"); if (isset($_POST['cust2'])) { $cust2 = $_POST['cust2']; $sql = "SELECT customer_address FROM customers WHERE customer_id = 2"; $query = mysqli_query($con, $sql); $dataString = ''; while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $add = $row["customer_address"]; $dataString = $add; } mysqli_close($con); echo $dataString; exit(); } else { exit(); } ?> Hi I have a single page submission update page which incorporates 7 drop down menus and 2 text input fields, everything works fine with the data updating back to the database, the only thing is that when the page is updated all the drop down menus are updated which includes ones that I don't want updated? I need to only update the drop down menus that have been selected? but am unsure how I do it? This is the code from the page, sorry if its a mess but I am not that experienced at the moment. This is a snippet of one of the drop down menus Code: [Select] <tr> <td class="heading">Current Status</td> <td><?php echo $statusdescrip ['status_description']; ?> <select name="status_id" > <?php $status_set = findstatus(); $statuslist = mysql_fetch_assoc ($status_set); ?> <?php do { ?> <option value="<?php echo $statuslist ['status_id']; ?>" ><?php echo $statuslist ['status_description']; ?></option> <?php } while ($statuslist = mysql_fetch_assoc ($status_set)); ?></select> <span class="compuls">*</span></td> </tr> Hi All, I've searched long and hard accross the web for an answer to this and finnally given in and requesting help. Here's what i have, i have a database setup and working fine. What i would like to do is for an administrator to be able to update my users details. It may sound odd, why don't you let your users update their own details? Well the administrators are dispatchers if you like, and my users are the 'dispatchees', for want of a better word. So i would like my administrators to be able to dispatch my users with routes and my users be able to see the routes that have been dispatched to them. I've setup a login area and a page that pulls there routes off the database, depending on their login details, i.e. jack will see his routes and jill will see her's independantly. This works by me editing the appropriate columns/rows of my database using phpmyadmin. What i'd like now is for administrators (who are directed to a seperate page, with more controls) to be able to do the same as me (updating the database) but by using a php form/script. I'd like to be able to select the routes from a second table on the same database if possible, to try and keep everything tidy. So my dispatcher would select Route001 from a drop down list, this would fill in the text fields next to the route field with From To, so my dispatcher would know what route001 actually is from/ too, choose a username (now being driven from my other table) and hit dispatch. My user would login to their area, hit view dispatched routes and it would display Route 001 with the correct information. The login area was a downloaded script i modified to suit and is called Login-Redirect_v1.31_FULL Many thanks in advance, hope you can sort of understand what i want Josh PHP/MySQL ability:Novice $sqld = "SELECT * FROM orders WHERE `id`='$delete' AND `name`='$inf2[name]' AND `email`='$inf2[email]' LIMIT 1"; $csql = $db->query($sqld); $ccheck = $csql->fetch(PDO::FETCH_NUM); $cinf = $csql->fetch(PDO::FETCH_ASSOC); $quantity = $cinf[quantity]; $code = $cinf[code]; $stmt11 = $db->prepare('UPDATE feeds SET quantity=quantity-:quantity WHERE code=:code'); $stmt11->bindValue(':quantity', $quantity, PDO::PARAM_STR); $stmt11->bindValue(':code', $code, PDO::PARAM_STR); $stmt11->execute(); $id = $delete; $name = $inf2[name]; $stmt2 = $db->prepare("DELETE FROM orders WHERE id=:id AND name=:name"); $stmt2->bindValue(':id', $id, PDO::PARAM_STR); $stmt2->bindValue(':name', $name, PDO::PARAM_STR); $stmt2->execute();OK, i have just been told i should start using PDO instead of mysql to update my tables. This code works to delete the order but doesn't update the feeds section. All this is new to me so far and i think i am getting the hang of it. Should i still be using the quantity=quantity-:quantity or is there another way to do it with PDO? Sorry, i posted this in the wrong forum. Hope someone here can help until it's moved Edited by Self_Taught_Still_Learning, 30 May 2014 - 03:30 PM. $query1 = "select * from movies where title = '".$title."' ;"; $result1 = mysql_query($query1) or die('Could Not Execute The Query'); while ($row = mysql_fetch_assoc($result1) ) { for($f=0; $f<$parts[$current_k]; $f++ ) { touch("$base_folder/{$hos}/".$linking[$sum].".php"); $old_part_href = $row['href_parts']; $updated_part = $old_part_href.$new; $query_href = 'update movies set href_parts = \''.$updated_part.'\''; mysql_query($query_href) or die('COULD NOT EXECUTE THE QUERY FOR PARTS HREF'); $new = "{$base_folder}/{$hos}/".$linking[$sum].".php"; $sum++; } } what i am trying to do is take the value of href_parts and add the new href of the page to the existing value on the href_parts and update the href_parts field in my db.. but i am not getting the desired results.. all i am getting in the db is the last value that is passed in the loop in the db.. i want to save the values which are exisiting in the db and add the newly created values to itt.. can anyone help please.. Hi, I'm using php to access the mysql database using mysqli and I have a field on my table called "timestamp" and it's set as a timestamp and has current_time (I think in phpmyadmin it was a tick option so I clicked it) and when I update that row in my table the field "timestamp" doesn't update with the timestamp from when it was last updated/modified. I thought the field option timestamp automatically did that? I'm guessing not.. is there a way I can update the timestamp with the current time in my query? I'm back, I have a code that based on my understanding should work, but needless to say doesn't <?php $sql ="select * from `piprice`"; $result = mysql_query($sql); $count = mysql_num_rows($result); echo "<table border=1><tr><td>Product Name</td><td>Item ID</td><td>Price</td><td>Enabled</td>"; echo "<form action=main.php?id=test1.php method=post>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['product name']."</td>"; echo "<td>".$id[] = $row['item id'];$row['item id']."</td>"; echo "<td>".$row['price']."</td>"; $enabled[] = $row['enabled']; echo"<td><select name=".$enabled.">< <option Value=".$row['enabled'].">".$row['enabled']."</option> <option Value=Yes>Yes</option> <option Value=No>No</option> /select></td</tr>"; } echo "<input name=submit type=submit value=Update>"; echo "</form></table>"; if(isset($_POST['submit'])) { for($i=0;$i<$count;$i++){ $sql1="UPDATE `piprice` SET `enabled` = '$enabled[$i]' WHERE `item id` ='$id[$i]'"; $result1=mysql_query($sql1) or die (mysql_error()); } } ?> Basically I want to be able to pick yes/no and have it update in the database. One a side note is there a good site for me to learn php on (I just know the basics) besides asking 101 questions here So, I am making a CMS for my school and I am having some trouble. It's a magazine sort of CMS and what I want is that when you click on a certain thing it continues onto the next page. Through the CMS you can create pages - when you do this each page gets a unique PID. To access the pages you have to enter the PID on the end of the URL, e.g. : http://www.myschool.com/magazine/index.php?pid=x. What I need is a code that when an image gets clicked the PID number in the URL goes up by one. Thanks well here my page i tryed and tryed to get it working but it shows the data but it dont update it Code: [Select] [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><?php include "../config.php"; $id = $_GET['id']; $con = database_connect(); $sql = "SELECT * FROM anime1 WHERE animeid ='$id'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $title = $row['title']; $type = $row['type']; $episode = $row['episode']; $year = $row['year']; $genre = $row['genre']; $status = $row['status']; $summary = $row['summary']; $pictures = $row['pictures']; }mysql_query($sql) or exit(mysql_error()); mysql_close($con); ?> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".flip").click(function(){ $(".panel").slideToggle("slow"); }); }); </script> <style type="text/css"> </style> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Transdmin Light</title> <!-- CSS --> <link href="style/css/transdmin.css" rel="stylesheet" type="text/css" media="screen" /> <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie6.css" /><![endif]--> <!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie7.css" /><![endif]--> <!-- JavaScripts--> <script type="text/javascript" src="style/js/jquery.js"></script> <script type="text/javascript" src="style/js/jNice.js"></script> </head> <body> <div id="wrapper"> <!-- h1 tag stays for the logo, you can use the a tag for linking the index page --> <h1><a href="#"><span>Transdmin Light</span></a></h1> <!-- You can name the links with lowercase, they will be transformed to uppercase by CSS, we prefered to name them with uppercase to have the same effect with disabled stylesheet --> <ul id="mainNav"> <li><a href="#">DASHBOARD</a></li> <!-- Use the "active" class for the active menu item --> <li><a href="./anime.php" class="active">Anime</a></li> <li><a href="#">DESIGN</a></li> <li><a href="#">OPTION</a></li> <li class="logout"><a href="#">LOGOUT</a></li> </ul> <!-- // #end mainNav --> <div id="containerHolder"> <div id="container"> <div id="sidebar"> <ul class="sideNav"> <li><?php echo $lbox1 ?></li> <li><?php echo $lbox2 ?></li> <li><?php echo $lbox3 ?></li> <li><?php echo $lbox4 ?></li> <li> <?php echo $lbox5 ?></li> <li><?php echo $lbox6 ?></li> </ul> <!-- // .sideNav --> </div> <!-- // #sidebar --> <!-- h2 stays for breadcrumbs --> <h2><a href="#">Anime</a> » edit » <?php echo "$title"; ?></h2> <div id="main"> <form action="<?php echo $_SERVER['PHP_SELF']."?id=$id" ; ?>" method="post" class="jNice"> <h3>Editing <?php echo "$title"; ?>, when finished click submit</h3> <fieldset> <p> <label>Series Title -- (Put the Title of the Series you are adding into here)</label> <input name="title" type="text" class="text-long" id="title" value="<?php echo $title ?>" /> </p> <p> <label>Type -- (Put what type of anime is it?)</label> <select name="type" id="type"> <option selected="selected">Select one</option> <option>TV Series</option> <option>OVA</option> <option>TV Special</option> <option>Movie</option> <option>Web</option> <option>DVD Special</option> <option>Other</option> </select> </p> <p> <label>Episodes -- (How many Episode are there?)</label> <input name="episode" type="text" class="text-long" id="episode" value="<?php echo $episode ?>" /> </p> <p> <label>Year -- (What year was the anime release in?)</label> <input name="year" type="text" class="text-long" id="year" value="<?php echo $year ?>" /> </p> <p> <label>genre <a href="./genre">(click this for the list and FAQ for adding in genre)</a></label> <input name="genre" type="text" class="text-long" id="genre" value="<?php echo $genre ?>" /> </p> <p> <label>status -- (What Is the status of the anime, Completed, Ongoing or Stalled)</label> <select name="status" id="status"> <option selected="selected">Select one</option> <option>Complete</option> <option>Ongoing</option> <option>Stalled</option> </select> </p> <p> <label>Summary -- (Put in the Summary for the anime)</label> <textarea name="summary" cols="1" rows="1" id="summary"><?php echo $summary ?></textarea> </p> <p> <label>Pictures -- (link to the Anime Pictures you upladed)</label> <input name="pictures" type="text" class="text-long" id="pictures" value="<?php echo $pictures ?>" /> </p> <?php $con = database_connect(); $sql="UPDATE anime1 SET title='$title', type='$type', episode='$episode', year='$year', genre='$genre', status='$status', summary='$summary', pictures='$pictures' WHERE animeid = '$id'"; $con = database_connect(); $title = $_POST['title']; $type = $_POST['type']; $episode = $_POST['episode']; $year = $_POST['year']; $genre = $_POST['genre']; $status = $_POST['status']; $summary = $_POST['summary']; $pictures = $_POST['pictures']; $title = mysql_real_escape_string($title); $type = mysql_real_escape_string($type); $episode = mysql_real_escape_string($episode); $year = mysql_real_escape_string($year); $genre = mysql_real_escape_string($genre); $status = mysql_real_escape_string($status); $summary = mysql_real_escape_string($summary); $pictures = mysql_real_escape_string($pictures); error_reporting(-1); if (!mysql_query($sql,$con)) { die('Error adding anime database: ' . mysql_error()); } ?> <h3> </h3> <?php $con = database_connect(); $sql1 = "SELECT * FROM episodea WHERE animeid = '$id' UNION ALL SELECT * FROM episodeb WHERE animeid = '$id'"; $result1 = mysql_query($sql1); while ($row = mysql_fetch_assoc($result1)) { $ep = $row['ep']; $epname = $row['epname']; $animeid = $row['animeid']; $video = $row['video']; $video2 = $row['video2']; $video3 = $row['video3']; mysql_query($sql) or exit(mysql_error()); echo " <div class=\"panel\">\n"; echo "<p>\n"; echo " <label>Episodes -- (When this box says Anime episode finished, you have added in all the episodes)</label>\n"; echo " <input name=\"ep\" type=\"text\" class=\"text-long\" id=\"ep\" value=\" $ep\" readonly=\"readonly\" />\n"; echo " </p>\n"; echo " <p>\n"; echo " <label>Episodes Name-- (What is the name of the episode you are adding? --- If the episodes has no name enter episode number)</label>\n"; echo " <input name=\"epname\" type=\"text\" class=\"text-long\" id=\"epname\" value=\" $epname\" />\n"; echo " </p>\n"; echo " <p>\n"; echo " <label>Viewable -- (Is the episode your are adding in SUBBED or DUBBED or RAW?)</label>\n"; echo " <select name=\"viewable\" id=\"viewable\">\n"; echo " <option selected=\"selected\">Select one</option>\n"; echo " <option>SUBBED</option>\n"; echo " <option>DUBBED</option>\n"; echo " <option>RAW</option>\n"; echo " </select>\n"; echo " </p>\n"; echo " <p>\n"; echo " <label>Video 1 -- (enter the embed code for the episode you are adding in)</label>\n"; echo " <textarea name=\"video\" cols=\"1\" rows=\"1\" id=\"video\"> $video</textarea></p>\n"; echo " <p>\n"; echo " <label>Video 2 -- ( If you have a 2ed embed code </label>\n"; echo " <textarea name=\"video1\" cols=\"1\" rows=\"1\" id=\"video1\"> $video2</textarea>\n"; echo " </p>\n"; echo " <p>\n"; echo " <label>Video 3 --( If you have a 3ed embed code </label>\n"; echo " <textarea name=\"video4\" cols=\"1\" rows=\"1\" id=\"video4\"> $video3</textarea>\n"; echo "<h3>\n"; echo "<a href=\"#submit\">IF you finished editing ep, click me to go to submit button</a></h3>\n"; echo " </p>\n"; echo "</div>\n"; echo " \n"; echo " <br />"; echo "<br />"; echo "<p class=\"flip\">Click here to edit all Episodes For $title </p>\n"; echo " <br />"; echo "<br />"; } ?> <h3> remember to click submit before changing the page</h3> <h3> </h3> <h3> <a name="submit" id="submit"></a> <input type="submit" value="Submit Query" /> </h3> </fieldset> </form> </div> <!-- // #main --> <div class="clear"></div> </div> <!-- // #container --> </div> <!-- // #containerHolder --> <p id="footer">Feel free to use and customize it. <a href="http://www.perspectived.com">Credit is appreciated.</a></p> </div> <!-- // #wrapper --> </body> </html> [/php] Hi, Does anyone have any experience of using PHP to transfer data from an XML file to a MySQL database? For the last 5 weeks I have been trying to get the following code to work but I am still unable to do it. The code does copy the file from my root folder into another (I eventually plan to use external download onto my server). However, it comes up with the following error: "Cannot instantiate non-existent class: xmlreader in" which refers to this: $xmlReader = new XMLReader(); Does anyone have any experience of transferring data from an XML file to a database? I am using PHP 5 so I dont know why this doesn't work. <?php ini_set('display_errors', 1); error_reporting(-1); $host="hostname"; // $username="username"; // $password="password"; // $db_name="db"; // $tbl_name="productfeed"; // // Connect to server and select database. mysql_connect("$host", "$username", "$password")or ("no connection"); mysql_select_db("$db_name")or die("Database Connection Error"); $xmlReader = new XMLReader(); $filename = "datafeed_98057.xml"; $url = "[url=http://www.ukhomefurniture.co.uk/datafeed.xml]http://www.ukhomefurniture.co.uk/datafeed.xml[/url]"; file_put_contents($filename, file_get_contents($url)); $xmlReader->open($filename); while ($xmlReader->read()) { switch ($xmlReader->name) { case'prod': $dom = new DOMDocument(); $domNode = $xmlReader->expand(); $element = $dom->appendChild($domNode); $domString = utf8_encode($dom->saveXML($element)); $product = new SimpleXMLElement($domString); $product_code = $product->prod['id']; $image = $product->awImage; //insert query if(strlen($product) > 0) { $query = mysql_query("REPLACE INTO productfeed (image) VALUES ('$awImage')"); echo $awImage . "has been inserted </br>"; die('yes it works'); error_reporting(E_ALL); if (ini_get('display_errors')) { ini_set('display_errors', 1); } } break; } } ?> MOD EDIT: DB credentials removed. Okay lets say after the form submission I have this inside the post parameters. answersList Undisputed Title2:::5,Outlaw Title3:::6,Tag Team Titles4:::7 If you see I have it exploding the list at the "," character. Then what I want to happen is for it to take out the ":::" characters and create a variable called $answerID for the number after the ":::" and then have it be able to run through the UPDATE query so that it UPDATES the old value with the new value. Code: [Select] $answer = explode(',', $_POST['answersList']); foreach ($answer as $answer) { $answer = htmlspecialchars($answer); echo $answer; $query = "UPDATE `pollAnswers` SET `answer` = '".$answer."' WHERE `ID` = '".$answerID."'"; mysqli_query($dbc, $query); echo $query; } Hi, Apologies to keep going on about this but I have hit a brick wall over updating my database with XML. I have spent around 100 hours on this and so far I can only copy the file, I am unable so far to update my database with the information from the XML file. I would be very grateful for any help you can offer to fix this. Code: [Select] ----Code so far----> $xmlReader = new XMLReader(); $filename = "datafeed_98057.xml"; $url = "http://www.domain.co.uk/datafeed.xml"; file_put_contents($filename, file_get_contents($url)); $xmlReader->open($filename); while ($xmlReader->read()) { switch ($xmlReader->name) { case'prod': $dom = new DOMDocument(); $domNode = $xmlReader->expand(); $element = $dom->appendChild($domNode); $domString = utf8_encode($dom->saveXML($element)); $prod = new SimpleXMLElement($domString); $id = $prod->prod['id']; $description = $prod->name; $image = $prod->awImage; $fulldescription = $prod->desc; //insert query if(strlen($prod) > 0) { $query = mysql_query("REPLACE INTO productfeed (id, description, fulldescription, image) VALUES ('$id','$description','$image','$fulldescription') "); echo $id . "has been inserted </br>"; } else{echo ("This does not work </br>");} } This is an outline of the XML feed I am using, it only includes one item which I am using as a test: Code: [Select] - <merchant id="1829" name="Pinesolutions.co.uk"> - <prod id="39920873" pre_order="no" web_offer="no" in_stock="yes" hotPick="no" adult="no"> - <text lang="EN"> <name>Oakleigh Wall Mirror 60x90</name> <desc>Mirrors are useful anywhere in the house. Not only are they functional allowing you to see your reflection in order to look your best, they also add elegance to any room theyre placed in. We offer a variety of mirrors to fit your decorating tastes as well as wall space. The Oakleigh Wall Mirror radiates an elegant simplistic style, while offering a generous size glass. The Oakleigh Wall Mirror s frame is crafted from solid hardwood and is lacquered with a protective finish to guard against dust and unexpected stains. The Oakleigh Wall Mirror is versatile and can be hung portrait style at the top of a staircase or landscape. The Oakleigh Wall Mirrors light colour means it also complements all of the furniture in our Camden Painted Range because the range has ash tops. The Oakleigh Wall Mirror has fewer knots than traditional oak wood, but is built just as sturdy so you can be certain it will last you through the generations to come.</desc> </text> - <uri lang="EN"> <awTrack>http://www.awin1.com/pclick.php?p=39920873&a=98057&m=1829</awTrack> <awImage>http://images.productserve.com/preview/1829/39920873.jpg</awImage> <mLink>http://www.pinesolutions.co.uk/bedroom-furniture/mirrors/wall-mirrors/oakleigh-wall-mirror-60x90/</mLink> <mImage>http://media.pinesolutions.co.uk/images/products/903.333.3.4.jpg</mImage> </uri> - <price curr="GBP"> <buynow>40.00</buynow> </price> - <cat> <awCatId>424</awCatId> </cat> <brand /> </prod> </merchant> |