PHP - Mysql Update
I have made this, although i can not seem to the status...
changeapp.php Code: [Select] <form method="post" name="memberadd" action="change_app_complete.php"> <label>Name:</label> <select name="member"> <?php $con = mysql_connect("host","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); $sqlquery="SELECT * FROM `application` Order By Name"; $result=mysql_query($sqlquery,$con); while($row=mysql_fetch_array($result)) { echo "<option value='".$row['ID']."'>".$row['Name']." (".$row['Status'].")</option>"; } ?> </select> <br> <label>Status:</label> <select name="Status"> <option value="PENDING">PENDING</option> <option value="ACCEPTED">ACCEPTED</option> <option value="DENIED">DENIED</option> <br> <input type="submit" value="submit" /> </form> change_app_complete.php Code: [Select] <?php $status=$_POST['Status']; $con = mysql_connect("host","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); $sql="UPDATE application SET Status = '$status' WHERE Name= '$member'"; if(mysql_query($sql,$con)) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } else { die('Could not submit: ' . mysql_error()); } mysql_close($con); ?> What is wrong? Similar TutorialsCan anyone post a generic update function to update mysql table. The manual approach: update $tablename set $column1='a', $column2='b' where $id=$value; Please help me with this: been doing this for 2 days and still cannot solve it. it won't update... I have attached my file: <?php include('connect-database.php'); if (isset($_POST['submit']) AND $_POST['submit'] == 'update') { $error = false; extract($_POST); if (empty($full_name)) $error = true; if (!$error) { $update = "UPDATE users SET full_name = '$full_name', WHERE id=$id "; mysql_query($update) or die(mysql_error() . "<br><br>" . $update); $full_name = ''; $message = "Record successfully updated."; } else { $message = "There is an error in your entry"; } } else { $id = intval(isset($_GET['id']) ? $_GET['id'] : 0); } if ($id == 0) { echo "<div style='margin-bottom:10px'>Invalid ID.</div>"; exit; } $query = "SELECT * FROM users WHERE id=$id"; $result = mysql_query($query) or die(mysql_error() . "<br><br>" . $query); if (mysql_num_rows($result) == 0) { echo "<div style='margin-bottom:10px'>Record Not Found in Database!</div>"; exit; } $row = mysql_fetch_array($result); extract($row); ?> <div id="mainContent" class="tab_container"> <div id="tab1" class="tab_content"> <h1>Edit Personal Data</h1> <div style="color:red;font-weight:bold"><? echo $message; ?></div> <form name="submit" action="" method="post"> <ul> <li><b>ID # :</b> <?php echo $id?></li> <li><b>Name :</b> <input type="text" name="full_name" id="" size="30" value="<?php echo $full_name ?>" /></li> <li><b>Address :</b> <input type="text" name="address" id="" size="55" maxlength="100" value="<?php echo $address ?>" /></li> <li><b>Contact Number :</b> <input type="text" name="contact_number" id="" size="11" value="<?php echo $contact_number ?>" /></li> <li><b>Email Address :</b> <input type="text" name="user_email" id="" size="30" value="<?php echo $user_email ?>" /></li> <li><b>Status :</b> <input type="text" name="status" id="" size="10" value="<?php echo $status ?>" /></li> <li><b>Nationality :</b> <input type="text" name="nationality" id="" size="20" value="<?php echo $nationality ?>" /></li> <li><b>Religion :</b> <input type="text" name="religion" id="" size="20" value="<?php echo $religion ?>" /></li> </ul> <h2>Self Description</h2> <p><textarea rows="9" cols="40" name="self_description" ><?php echo $self_description ?></textarea></p> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input type="submit" name="submit" value="update" /> </form> </div> Code: [Select] <?php $querySelect = mysql_query("SELECT * FROM `G4V_Videos` WHERE `counter`"); $row = mysql_fetch_assoc($querySelect); $counter = $row['counter']; if (empty($counter)) { $counter = 1; $insert = mysql_query ("INSERT INTO counter VALUES ('counter')"); $printid = (print $data['id']); $printlink = (print $data['link']); } $add = $counter+1; $insertNew = mysql_query("UPDATE G4V_Videos SET counter=('$add') WHERE id = ('$printid') AND link = ('$printlink')") or die (mysql_error()); echo "Video Views"; echo ":"; echo" "; echo"<br />"; echo "$counter"; ?> It shows the same amount of hits on everyvideo instead of just the one video with the id www.game4vids.com I have this query: Code: [Select] $sql3 = "UPDATE users SET hours = '$newHours', pay = '$newPay', virtualLocation = '$arrival', expDate = '$expDate' WHERE pilotID = '$pilotid'"; I've echoed it out and all the variables put out the correct values. The query works except for the pay section of it. It will update the hours, virtual location, and expiration date but it will not update the pay. It inputs 1.00 when the value echoed in the query is not 1.00. I'm not sure if, because it is a decimal, it changes how the query works. Any help? Thanks. this is what i have so far but i cant get it to update the data update page <?php $host="localhost"; // Host name $username="**"; // Mysql username $password="*****"; // Mysql password $db_name="manews"; // Database name $tbl_name="Shows"; // 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 $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id='$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="update_ac.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>Day</strong></td> <td align="center"><strong>Month</strong></td> <td align="center"><strong>Year</strong></td> <td align="center"><strong>Song</strong></td> <td align="center"><strong>Data</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="Day" type="text" id="Day" value="<? echo $rows['Day']; ?>"></td> <td align="center"><input name="Month" type="text" id="Month" value="<? echo $rows['Month']; ?>"></td> <td align="center"><input name="Year" type="text" id="Year" value="<? echo $rows['Year']; ?>" size="15"></td> <td align="center"><input name="Song" type="text" id="Song" value="<? echo $rows['Song']; ?>"></td> <td align="center"><input name="Data" type="text" id="Data" value="<? echo $rows['Data']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['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(); ?> update script <?php $host="localhost"; // Host name $username="**"; // Mysql username $password="**"; // Mysql password $db_name="manews"; // Database name $tbl_name="Shows"; // 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"); // update data in mysql database $sql="UPDATE $tbl_name SET Day='$Day', Month='$Month', Year='$Year', Year='$Song', Year='$Data' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='list_records.php'>View result</a>"; } else { echo "ERROR"; } ?> I am trying to update the content of my website which is all stored in a MySQL database. Currently on the page I am displaying all the data stored in the database using MySQL SELECT and a while loop. Using JavaScript when the text is clicked the element changes into a text box allowing the text to be edited. What I want to do is be able to change the data in the text box and then store it into the database updating the current data. Code: [Select] <form method="post" action="editindex.php"> <?php $sql = "SELECT * FROM home ORDER BY id ASC"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo "<span id=\"itm1\" onclick=\"exchange(this);\">" . $row['title'] . "</span><input ondblclick=\"exchange(this);\" id=\"itm1b\" class=\"replace\" type=\"text\ name=\"title\">";?> <input type="submit" value="Save" name="submit"> <input type="hidden" name="id" value="<?php $row['id'] ?>" </form> <?php if (isset ($_POST['submit'])) { $update = "UPDATE home SET title=".$_POST['title']." WHERE id=".$_POST['id'].""; mysql_query($update); } ?> I have more text being output from the while loop below but I just want to get it working on the title first. Any ideas of why the update is not working? I have the following code that when used seperately work. How would I write an if..else statement that will make them work together? The following code give me an Parse Error, syntax error unexpected T_string. The following if my code I have tried, Code: [Select] if (SELECT tournament FROM weekly_picks WHERE tournament = '$tournament') mysql_query("UPDATE weekly_picks SET player = '$golfer' WHERE tournament = '$tournament' AND user = '$usr'"); else mysql_query("INSERT INTO weekly_picks (t_id, tournament, user, player, backup, timestamp) VALUES ('$t_id', '$tournament', '$usr', '$golfer', '$backup', '$time')",$link) or die('Error, insert query failed'); I also know that values are being stored in the variables. I have lost my record when I run the code below, all fields are empty... Code: [Select] <a href='edit.php?id={$info['person_id']}'><font color='#00AE0A'>Edit User</font> </a> Code: [Select] $sql = "SELECT * FROM person WHERE person_id='{$_REQUEST['id']}' "; $result = mysql_query($sql); if (!$result) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } if ($row = @mysql_fetch_array($result, MYSQL_ASSOC)) { print " <form action='<?php echo $PHP_SELF;?>' method=\"post\"> <table> <tr> <td><strong>Name</strong></td> <td><input type=\"text\" name=\"fname\" size=\"60\" value=\"$row[fname]\"></td> </tr> <tr> <td><strong>Surname</strong></td> <td><input type=\"text\" name=\"lname\" size=\"60\" value=\"$row[lname]\"></td> </tr> <tr> <td><strong>Email</strong></td> <td><input type=\"text\" name=\"email\" size=\"60\" value=\"$row[email]\"></td> </tr> <tr> <td><strong>Committee</strong></td> <td><input type=\"text\" name=\"committee_no\" size=\"60\" value=\"$row[committee_no]\"></td> </tr> <tr> <td><INPUT type=\"submit\" value=\"Send\"> </td> </tr> </table></form> "; } else { echo("There has been an error" . mysql_error()); } /* closes connection */ ?> <?php $control = mysql_query(" UPDATE person SET fname='{$_REQUEST['fname']}' , lname='{$_REQUEST['lname']}' , email='{$_REQUEST['email']}', committee_no='{$_REQUEST['committee_no']}' WHERE person_id='{$_REQUEST['id']}'"); if($control) { header("Location:".$_SERVER["HTTP_REFERER"].""); } ?> Code: [Select] if(isset($_POST['npassword']) and ($_POST['cpassword'])){ $npassword = $_POST['npassword']; $cpassword = $_POST['cpassword']; $username = $_SESSION['SESS_login']; if($npassword==$cpassword){ $password = md5($npassword); $lol = mysql_query("UPDATE `members` SET `passwd` = '$password' WHERE `login`= '$username';"); echo"Password Changed!"; } } It echos password changed, but its not updating the password. If I run it in phpmyadmin it works fine... So i'm really stuck. Is there something seriously wrong with this code that im missing ? I have written it at least 10-12 different ways and it will NOT update my db.. Code: [Select] <?php mysql_connect('localhost','root',''); mysql_select_db('myDB'); $dates = $_POST['date']; $store = $_POST['store']; // these actually display the correct information mysql_query = ("UPDATE Agency Stores - Table 1 SET date = '".$date."' WHERE F3 = '".$store."' "); ?> there are several other columns in the table. I have tried to put them in as the value they already have and it still didnt work... any ideas ? So there is this code I have here : http://pastebin.com/rwcN7FeJ and I need to find a way to incorporate this code that user Barand gave me Code: [Select] $referName = mysql_real_escape_string($gateway_data['refer']); $query = "UPDATE users a INNER JOIN users b ON a.refer = b.nick SET a.refer = '', b.balance = b.balance + 5 WHERE b.refer = '$referName'"; mysql_query($query); But I havent the damnedest how to do that. If anyone could help me at all, it would be appreciated. Hey, I have this code, and it's ment to change the name / content of a page that is being put onto a page. Both of the include files are fine as it works for other actions, but this one just returns the error. <?php include "../includes/mysql_connect.php"; include "../includes/info_files.php"; if(isset($_POST['submitted'])) { mysql_query("UPDATE `pages` SET name='$_POST[name]' AND SET content='$_POST[content]' AND SET catt='$_POST[catt]' AND SET page='$_POST[page]' WHERE id='$_POST[id]'") or die('Edit failed'); echo "Page made.<br /><br />"; }else{ $result = mysql_query("SELECT * FROM pages WHERE id='$_GET[page]'"); while($row = mysql_fetch_array($result)) { echo '<form action="" method="post">'; echo '<input type="hidden" name="id" value="' . $row['id'] . '" /><br />'; echo '<strong>Edit: ' . $row['name'] . '</strong><br />'; echo 'Name: <input type="text" name="name" value="' . $row['name'] . '" /><br />'; echo 'Category: <input type="text" name="catt" value="' . $row['catt'] . '" /><br />'; echo 'Page: <input type="text" name="page" value="' . $row['page'] . '" /><br />'; echo '<textarea rows="25" cols="60" name="content">' . $row['content'] . '</textarea><br />'; echo '<input type="submit" name="submitted" value="Edit" />'; echo '</form>'; } } ?> Any help would be great. So i have this following code that doesn't work Hi,
Im having a problem and I can't seem to figure it out or find anything on the net.
If I use the following code the script successfully updates every row in the table:
mysqli_query($con,"UPDATE Ads SET Ads_LocalArea='Stroud'");However if I try updating the table using the WHERE clause in any of the combinations below nothing happens. mysqli_query($con,"UPDATE Ads SET Ads_LocalArea='Stroud' WHERE Ads_ID=$DBROWID");---------------------------------------------------------------------- My Script: mysqli_query($con,"INSERT INTO Ads (Ads_ID, Ads_AID, Ads_Title) VALUES ('', '$Polished_AdRef', '$Polished_AdTitle')"); $DBROWID = mysqli_insert_id($con); mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID=$DBROWID"); // TRIED THESE TOO // mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID='$DBROWID'"); // mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID='5'");Does any one know where I am going wrong? how can i make this code to insert a single, multiple and update rows in the database. The code only insert new rows in the database. Code: [Select] if (($handle = fopen('inventorylist.csv', "r")) !== FALSE) { while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { $num = count($data); $sql="INSERT into inventory(itemNumber,itemDesc,quantityHand,category,Whse) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')"; mysql_query($sql) or die(mysql_error()); } fclose($handle); } I have an edit profile page: <?php include ('header.php'); ?> </center> <div class="content"> <?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { $nameuser = $_GET['username']; $checkinfo = mysql_query("SELECT * FROM users WHERE Username = '$nameuser'"); while($results = mysql_fetch_array($checkinfo,MYSQL_ASSOC)) { $id = $results['UserID']; $username = $results['Username']; $email = $results['EmailAddress']; $location = $results['Location']; $website = $results['Website']; $about = $results['About']; $level = $results['Level']; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $editEMAIL=$_POST['email']; $editLOCATION=$_POST['location']; $editWEBSITE=$_POST['website']; $editABOUT=$_POST['about']; $editID=$_POST['id']; $editLEVEL=$_POST['level']; $editquery = mysql_query("UPDATE users SET EmailAddress='$editEMAIL' , Level='$editLEVEL' , Location='$editLOCATION', Website='$editWEBSITE', About='$editABOUT' WHERE UserID='$editID'"); if($editquery) { echo "<b>Success!</b><br>"; echo "Your profile was successfully updated. Please click<span class=\"class1\"><a href=\"index.php\"> here </a></span>to return to the index.<br><br>"; $display_form = FALSE; } else { echo "<b>Error</b>"; echo "<p>Sorry, your profile update failed. Please go back and try again.</p>"; $display_form = TRUE; } } } if ($display_form === TRUE || $_SERVER['REQUEST_METHOD'] != 'POST') { ?> <b>Editing <? echo $username ?>'s Profile</b><br><br> <b>Current user level:</b> <? echo $level ?> <br><br> Please enter your details below to update your profile. <br><br> <form method="post" action="editprofile.php" name="editform" id="editform"> <table width="700px" border="0" cellspacing="10"><tr><td valign="top"><table border="0"> <b>Required Information:</b><br><br> <tr><td> <b>Username:</b> </td><td> <?php echo $username; ?> </td></tr><tr><td> <b>Email Address:</b> </td><td> <input type="text" name="email" id="email" value="<?php echo $email; ?>"> <input type="hidden" name="id" value="<?php echo $id; ?>"> </td></tr> <tr><td> <b>Change Users Level:</b> </td><td> <select name="level" id="level"> <option value="Registered User">Registered User</option> <option value="Eventsec Employee">EventSec Emplyee</option> <option value="Admin">Admin</option> </select> </td></tr> </table></td><td valign="top"> <table border="0"> <b>Optional Information:</b><br><br> <tr><td> <b>Location:</b> </td><td> <input type="text" name="location" id="location" value="<?php echo $location; ?>"> </td></tr><tr><td> <b>Your Website:</b> </td><td> <input type="text" name="website" id="website" value="<?php echo $website; ?>"> </tr></td><tr><td valign=top> <b>Short About:</b> </td><td> <textarea name="about" id="about" rows="10" cols="20" ><?php echo $about; ?></textarea> </td></tr></td> </table> </td></tr> </table> <input type="submit" name="register" id="register" value="Update" class="btn"> </form> </div> <?php } include ('footer.php'); ?> However the dropdown menu in the form doesn't work? It returns an update success message but the value of 'level' was not changed in the database. Am I missing something? I will provide the code. Im working on my script which updates a row of data in a mysql DB, the update command doesnt have all of the fields.(I don't know if this is failing it or not?) The code for the form is. <?php include("../scripts/dbconnect.php"); mysql_select_db("rdb")or die("cannot select DB"); $sql="SELECT * FROM wo WHERE won='1'"; $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="updatewo1.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"> </td> <td align="center"><strong>WON</strong></td> <td align="center"><strong>CName</strong></td> <td align="center"><strong>CEmail</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<?php echo $rows['won']; ?>"></td> <td align="center"><input name="lastname" type="text" id="lastname" value="<?php echo $rows['cname']; ?>" size="15"></td> <td><input name="email" type="text" id="email" value="<?php echo $rows['cemail']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<?php echo $rows['won']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <?php mysql_close(); ?> The page the action goes to is below. <?php include("../scripts/dbconnect.php"); mysql_select_db("rdb")or die("cannot select DB"); $sql="UPDATE wo SET won='$_POST[won]', cname='$_POST[cname]', cemail='$_POST[cemail]' WHERE won = '$_POST[won]'"; $result = mysql_query($sql); if($result){ echo "Successful"; } else { echo "ERROR"; } ?> I am fairly new to PHP, any help would be greatly appreciated. I will list all of the Mysql table's fields below. won,wopword,status,dws,problem,dfin,cost,service,coupon,lmao1,lmao2,cname,caddy,cemail,cphone,compinfo,techname,comments,storeloc,clerk,solution Hi I have the file "pback.php" which displays a mysql table. One row allows me to update the data. If I press "update it leads me to update.php, but there I just get white fields instead of the data from the id requested. If I type anything in the field and press confirm it opens update_ac but just says error. What do I do wrong? Thanks! Quote pback.php Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name $tbl_name="sp_users"; // 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"); //$sql="SELECT * FROM $tbl_name ORDER BY user_id"; $sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id ORDER BY school_name"; $result=mysql_query($sql); $num_rows=mysql_num_rows($result); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } #Layer1 { position:absolute; left:803px; top:36px; width:65px; height:28px; z-index:1; } #Layer2 { position:absolute; left:707px; top:19px; width:143px; height:39px; z-index:1; } --> </style> <title>User overview</title> </html> <div id="Layer2"> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <input type="hidden" name="foo" value="<?= $foo ?>" /> <input type="submit" name="submit" value="Refresh" /> </form></div> <table width="779" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="777"> <div align="left"> <table width="779" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="6" align="center"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users / Total: <?php echo $num_rows ?></strong></div></td> </tr> <tr> <td width="342" align="center"><span class="style2">school</span></td> <td width="62" align="center"><span class="style2">Name</span></td> <td width="104" align="center"><span class="style2">Lastname</span></td> <td width="130" align="center"><span class="style2">Email</span></td> <td width="64" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['school_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="left"> <p> </p> <p> </p> <p> </p> <p> <?php mysql_close(); ?> </p> </div> Quote update.php Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name //$tbl_name="sp_users"; // 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 $id=$_GET['user_id']; ?> <?php $sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id"; $result=mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_query()); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><div align="center" class="style1">Update data in mysql </div></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"><span class="style7">Name</span></td> <td align="center"><span class="style7">Lastname</span></td> <td align="center"><span class="style7">Email</span></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['user_first_name']; ?>"></td> <td align="center"><input name="lastname" type="text" id="lastname" value="<? echo $rows['user_surname']; ?>" size="15"></td> <td><input name="email" type="text" id="email" value="<? echo $rows['user_login']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['user_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(); ?> </body> </html> Quote update_ac.php Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name $tbl_name="sp_users"; // 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"); // update data in mysql database $sql="UPDATE $tbl_name SET name='$user_name', lastname='$user_lastname', email='$email' WHERE id='$user_id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='pback.php'>View result</a>"; } else { echo "ERROR"; } ?> Good Day
Please could someone be so gracious as to help me with the following problem.
I am wanting to update a MYSQL database from a Firebird database.
I have tested connecting to both databases individually which works fine, it is just when I put the code together it does not work.
Below is the code
//Firstly I connect to the MYSQL database to see what needs to updated mysql_connect("localhost", "database", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $check = "SELECT * FROM table WHERE blah != ''"; $result = mysql_query($check) or die ("Error in query: $check. " . mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_object($result)) { $blah = $row->blah; // Then I connect to the Firebird database to get the info $dsndb = 'host'; $userdb = 'user'; $passdb = 'password'; try { $dbh = new PDO($dsndb, $userdb, $passdb); $sth = ("SELECT * from table WHERE blah = '$blah'"); foreach ($dbh->query($sth) as $row) { //Then I update the MYSQL database from the Firebird database info $sql = "UPDATE table SET field1 = 'field1', field2 = 'field2', field3 = 'field3' WHERE blah = '$blah'"; $update=mysql_query($sql) or die(mysql_error()); } } } }Your assistance will be greatly appreciated. I am trying to create a script that takes information from a form and puts in a database. In the action page, I decided to post a URL that shows the user there story that they posted. This is where I ran into the problem. . I realized that for the optional fields I could not just use a seperate insert statement, because this creates a new row. So I desided to use update statments, but this STILL does not work, they values or simply not getting inserted. Here is the code: Code: [Select] <?php if(isset($_POST['hidden'])) { die('SPAM BOT!'); } if ( !isset($_POST['title']) && !isset($_POST['summary']) && !isset($_POST['story']) && !isset($_POST['rating']) && !isset($_POST['cat']) ) { die("<div id='impor'>You forgot to enter one(or more) of the following fields <br /> 1. Title <br /> 2. Summary <br /> 3. Story<br /> </div> "); } mysqlConnect(); //take data from form an\ put them in variable $title_form = bb(mysql_real_escape_string($_POST['title'])); //required $summ_form = bb(mysql_real_escape_string($_POST['summary']));// required $story_form = bb(mysql_real_escape_string($_POST['story'])); $cat_form = $_POST['cat']; $rating_form = $_POST['rating']; $username = $_SESSION['user']; // Make the other var into a list of links mysql_query(" INSERT INTO story_info (title, sum, story, user, cat, rating) VALUES('$title_form','$summ_form', '$story_form,', '$username', '$cat_form','$rating_form') "); if(isset($_POST['notes'])) { $notes_form = mysql_real_escape_string($_POST['notes']); $notes_final = bb($notes_form); mysql_query(" UPDATE story_info SET notes = '$notes_final' WHERE story = '$story_form' AND user = '$username' AND sum = '$summ_form' AND title = '$title_form' "); } //put other in array. Use while loop to put link code. Then but it back into one non array variable if(isset($_POST['u_id'])) { $uid = mysql_real_escape_string($_POST['u_id']); $uid_db = str_replace(' ','_', $uid); $blerg = " UPDATE story_info SET series_id = '$uid_db' WHERE story = '$story_form' AND user = '$username' AND sum = '$summ_form' AND title = '$title_form' "; mysql_query($blerg); } echo "<h1> Your Story Has Been Posted! Thanks for posting $username . </h1>"; echo "Please review the post below <br />"; echo "<h2> $title_form </h2>"; echo "<strong> <h2> Summary: </h2> </strong> $summ_form"; echo "<h4> Story: </h4>"; echo "$story_form"; if(isset($notes)) { echo "<h4> Author's Notes: </h4> "; echo "$notes_final"; } if (isset($uid_db)) { echo '<h3> Unique Series ID </h3>'; echo '<p> Make sure to write down this! <br />' .$uid_db .'</p> '; } $db = mysql_query(" SELECT story_id FROM story_info WHERE story='$story_form' AND user='$username' ")or die(mysql_error()); $rows = mysql_fetch_assoc($db); $id = $rows['story_id']; echo "Catagory: $cat_form <br /> Rating: $rating_form <br /> "; echo "<a href='?p=page&id=$id'> Click here to view your story! </a>'"; ?> Please help! |