PHP - Drop Down And Insert Into Mysql
I'm a newbie on php. I'm really a system administrator and I was just task to do this simple task. For me its hard but I'm sure for a programmer this is very simple. My agenda is to pull out data on one of my column in mysql, select it and dump it on mysql. Here is the php for retrieving mysql data
Code: [Select] <?php function database_connect($users) { $resource_link = mysql_connect("localhost", "root", "root"); if (mysql_select_db($users, $resource_link)) { return $resource_link; } else { echo "Cannot connect to DB"; return false; } } function print_dropdown($query, $link){ $queried = mysql_query($query, $link); $menu = '<select username="username">'; while ($result = mysql_fetch_array($queried)) { $menu .= ' <option value="' . $result['id'] . '">' . $result['username'] . '</option>'; } $menu .= '</select>'; return $menu; } //Some other form elements, or just start a form. echo '<form method="post" action="create2.php">'; //The important bit echo print_dropdown("SELECT username FROM mailbox;", database_connect("users")); //Some other form elements, or just end the form. echo '<input type="submit" name="submit" value="submit"/></form>'; Here is the content of my create2.php. This is the php page who do the insert on my mysql. Code: [Select] <?php // open the connection $conn = mysql_connect("localhost", "root", "root"); // pick the database to use mysql_select_db("users",$conn); // create the SQL statement $sql2 = "INSERT INTO mailbox values ('','locked','','$_POST[username]','',NOW(),'','locked','')"; // for troubleshooting $result = mysql_query($sql2, $conn) or die(mysql_error()); // execute the SQL statement //if (mysql_query($sql2, $conn)) { // echo "Success"; //} else { // echo "Fail"; //} } ?> When I click the submit button, I don't see any record being inserted on my table. I'm using the create2.php on my other page though it is only an insert/fill up form not like this one that I need to pull up the date, select and insert to mysql. Similar TutorialsI am trying to insert a date into a mySQL table from html drop downs with php. Right now when I enter the date it goes into the database as 0000-00-00. Can anybody see why it might be doing this? My html: Code: [Select] <label for='birthdate' >Birthdate (Optional):</label><br/> <select name='month' id='month' value='<?php echo $fgmembersite->SafeDisplay('month') ?>'> <option value="01" selected="January">January</option> <option value="02">February</option> <option value="03">March</option> etc... </select> <select name='day' id='day' value='<?php echo $fgmembersite->SafeDisplay('day') ?>'> <option value="01" selected="1">1</option> <option value="02">2</option> <option value="03">3</option> etc... </select> <select name='year' id='year' value='<?php echo $fgmembersite->SafeDisplay('year') ?>'> <option value="2010" selected="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> etc... </select> And my php to collect info: Code: [Select] $formvars['birthdate'] = $this->Sanitize($_POST['year'], $_POST['month'], $_POST['day']); php where I make table: Code: [Select] "birthdate DATE NOT NULL ,". php to insert into mysql: Code: [Select] $insert_query = 'insert into '.$this->tablename.'( name, address, birthdate, sex, program, guide, email, username, password, confirmcode ) values ( "' . $this->SanitizeForSQL($formvars['name']) . '", "' . $this->SanitizeForSQL($formvars['address']) . '", "' . $this->SanitizeForSQL($formvars['birthdate']) . '", "' . $this->SanitizeForSQL($formvars['sex']) . '", "' . $this->SanitizeForSQL($formvars['program']) . '", "' . $this->SanitizeForSQL($formvars['guide']) . '", "' . $this->SanitizeForSQL($formvars['email']) . '", "' . $this->SanitizeForSQL($formvars['username']) . '", "' . md5($formvars['password']) . '", "' . $confirmcode . '" )'; Thank you! I am simply trying to insert a value generated from an array in a while loop, but it seems the value is not global and I can't pass it as I like. I did some research on this, but could not find an answer that solved my issue... Here is my select box code which is working perfect: <select name="city"> <?php $sql = "SELECT id, city_name FROM cities ". "ORDER BY city_name"; $results_set = (mysqli_query($cxn, $sql)) or die("Was not able to produce the result set!"); while($row = mysqli_fetch_array($results_set)) { echo "<option value=$row[id]>$row[city_name]</option>"; } ?> </select> Are any variables defined in a while loop global to the while loop only? Here is my SQL which you can see my $row[id] being passed thru field city_id... The value is being generated as supposed to based on value like: value="1", value="2" etc.. for the select options for each city name. So the values are there... But I CANNOT get that numerical id to pass to the database when submitting my form. Any ideas for a workaround to get this value passing as normal? if (isset($_POST['addPosting'])) { $query = "INSERT INTO Postings (id, city_id, title, description) VALUES ('','$row[id]','$_POST[title]','$_POST[description]')"; Can anyone tell me why this is not INSERTing? My array data is coming out just fine.. I've tried everything I can think of and cannot get anything to insert.. Ahhhh! <?php $query = "SELECT RegionID, City FROM geo_cities WHERE RegionID='135'"; $results = mysqli_query($cxn, $query); $row_cnt = mysqli_num_rows($results); echo $row_cnt . " Total Records in Query.<br /><br />"; if (mysqli_num_rows($results)) { while ($row = mysqli_fetch_array($results)) { $insert_city_query = "INSERT INTO all_illinois SET state_id=$row[RegionID], city_name=$row[City] WHERE id = null" or mysqli_error(); $insert = mysqli_query($cxn, $insert_city_query); if (!$insert) { echo "INSERT is NOT working!"; exit(); } echo $row['City'] . "<br />"; echo "<pre>"; echo print_r($row); echo "</pre>"; } //while ($rows = mysqli_fetch_array($results)) } //if (mysqli_num_rows($results)) else { echo "No results to get!"; } ?> Here is my all_illinois INSERT table structu CREATE TABLE IF NOT EXISTS `all_illinois` ( `state_id` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Here is my source table geo_cities structu CREATE TABLE IF NOT EXISTS `1` ( `CityId` varchar(255) NOT NULL, `CountryID` varchar(255) NOT NULL, `RegionID` varchar(255) NOT NULL, `City` varchar(255) NOT NULL, `Latitude` varchar(255) NOT NULL, `Longitude` varchar(255) NOT NULL, `TimeZone` varchar(255) NOT NULL, `DmaId` varchar(255) NOT NULL, `Code` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Created a dynamic drop down box which pulls values from three columns from the database. However my insert function is not injecting the values in and i get an undefined index error. html> <div id = "form" align="center"> <h1> Create a repair Ticket </h1> <?php // Connects to Database mysql_connect("localhost", "bla", "bla") or die(mysql_error()); mysql_select_db("bla bla") or die(mysql_error()); ?> <form> <p> Choose the machine to be repaired: </p> <select> <?php // This query selects the machine_id and name from the machine table and stores in the "result" variable. $sql="SELECT machine_id,description FROM machine"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)) { echo ("<option value=".$data['machine_id'].">". $data['description']."</option>"); ?> <?php } ?> </select> <p> Choose the engineer to be allocated: </p> <select> <?php // This query selects engineer_id and name $sql="SELECT engineer_id,engineer_name FROM engineer"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)) { echo ("<option value=".$data['engineer_id'].">". $data['engineer_name']."</option>"); ?> <?php } ?> </select> <p> Choose the part to be allocated: </p> <select> <?php // This query selects the part_number and description $sql="SELECT part_number,description FROM parts"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)) { echo ("<option value=".$data['part_number'].">". $data['description']."</option>"); ?> <?php } ?> </select> <p> Reported By: <input type="text" name="reported_by" /> </p> <p><b>Fault Description</b> </p> <textarea cols="50" rows="4" name="fault_description" align="right" wrap="virtual"></textarea> </form> <form action="insert.php" method="post"> <input type="Submit"> </div> <?php ini_set("display_errors", "1"); error_reporting(E_ALL); $con = mysql_connect("localhost","bla","bla"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("bla", $con); $machine_id= $_POST['machine_id']; $reportedby= $_POST['reported_by']; $Date = date("d/m/y"); $fault_description =$_POST['fault_description']; $repaired_by = $_POST['engineer_name']; $part_used = $_POST['description']; $sql="INSERT INTO repairs (machine_number,reported_by,repair_start_date,fault description,repaired_by,part_used) VALUES ('".$machine_id."', '".$reportedby."','".$Date."','".$fault_description."','".$repairedby."','".$part_used."')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); echo "You records have been updated"; ?> Sorry got it! my apologizes Hello, I'm having a bit of a problem here, all help to this issues would be much appreciated I am trying to use text boxes to insert numbers into the database based on what is inputed. If I have a string, like this for example: $variable = 09385493; And I want to insert it into the database like this: mysql_query("INSERT INTO integers(number) VALUES ('$variable')"); When checking the integers table in my database, looking at the number field, the $variable that was inserted is outputted as 9385493 Notice the number zero was taken out of the front of the number. If the number is double 0's (009385493), both of those zero's would disappear, too. Thanks Hi guys I have a registration form working fine, my database is as below: userid username password repeatpassword I have added another column which is "name", users can update their profile once they have logged in so I have created updateprofile.php and when I login-->go to update profile and insert my name nothing adds to mysql name column this is my code below: <?php include ("global.php"); //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; //welcome messaage echo "Welcome, " .$_SESSION['username']."!<p>"; if ($_POST['register']) { //get form data $name = addslashes(strip_tags($_POST['name'])); $update = mysql_query("INSERT INTO users (name) VALUES ('$_POST[name]') WHERE username='$username'"); } ?> <form action='updateprofile.php' method='POST'> Company Name:<br /> <input type='text' name='name'><p /> <input type='submit' name='register' value='Register'> </form> can you please tell me where in this code is wrong? Im new in php so please excuse me if I have silly mistakes. thanks in advance I need help badly! What I want to do is insert into database the value from the selected radio group buttons.. All of them. There are 10 radio groups total (they can be less, but not more). Thanks! Code: [Select] <?php require_once('Connections/strana.php'); mysql_select_db($database_strana, $strana); ?> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <table width="100%" height="100%" style="margin-left:auto;margin-right:auto;" border="0"> <tr> <td align="center"> <form action="" method="post" enctype="multipart/form-data" name="form1"> <table> <?php $tema = mysql_query("SELECT * from prasanja where tip=2")or die(mysql_error()); function odgovor1($string) { $string1 = explode("/", $string); echo $string1[0]; } function odgovor2($string) { $string1 = explode("/", $string); echo $string1[1]; } while ($row=mysql_fetch_array($tema)) { $id=$row['prasanje_id']; $prasanje=$row['prasanje_tekst']; $tekst=$row['odgovor']; ?> <tr> <td> </td> </tr> <tr> <td class="formaP"> <?php echo $prasanje?> </td> </tr> <tr> <td class="formaO"> <p> <label> <input type="radio" name="Group<?php echo $id?>" value="<?php odgovor1($tekst) ?>" /> <?php odgovor1($tekst) ?></label> <br /> <label> <input type="radio" name="Group<?php echo $id?>" value="<?php odgovor2($tekst) ?>" /> <?php odgovor2($tekst) ?></label> <br /> </p></td> </tr> <tr> <td> <br /> </td> </tr> <?php } ?> </table> <input align="left"type="submit" name="submit" value="Внеси" > </form> </td> </tr> </table> prasanje = question tekst/odgovor = answer The answer table: id - primary question_id - the questions ID whose answer is selected in the radio group user_id - cookie takes care of this answer - the value from radio group date - automatic I have this code: <?php $con = mysql_connect("localhost","hhh","hhh"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("hhh", $con); // -------------------- // Avatar insert check // -------------------- session_start(); $name = $_POST[name]; $group = $_POST[group]; $age = $_POST[age]; $usernameid = $_SESSION[id]; $result = mysql_query("SELECT * FROM avatars WHERE name='$_POST[name]'"); $num = mysql_numrows($result); if ($num == 0) { mysql_query("INSERT INTO avatars (id, usernameid, name, group, age, xp) VALUES ('', '$usernameid', '$name', '$group', '$age', '0')"); header( 'Location: me/' ) ; } else echo 'Sorry, please pick a new name'; ?> And it does everything but put the data into the datebase. If I add a session befor and after '$request' they both run, but the sql doesn't. No error returns, if just redirects to the other page. Any help? well this is truely embarrising...i have a insert statement which works within phpmyadmin but when using mysqli_query it returns a error.
INSERT INTO users (username, timestamp) VALUES ('test', UTC_TIMESTAMP())Unknown column 'timestamp' in 'field list' i've been playing about with this for a few hours now ...tried changing the column name (timestamp), adding ` around column names as well as table name. the column exists which is the strangest part, and ive even checked there is no space after the column name in the db. whats going on please? I don't understand where the empty value is. I've substituted the variables for text and still have the same problem. Code: Code: [Select] $sql = "INSERT INTO courses (course#, name, subject, semester, ap)VALUES('$courseNum', '$courseName', '$subject', '$semester', '$ap')"; Error: 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 '' at line 1 hello can anyone help me how to insert GET variable into mysql <?php $page_title = 'Personal Wellness'; include ('template/header.inc'); include_once('config.php'); $id = $_GET['id']; if(isset($_POST['submit'])) //if submit was pressed { if(strlen($_POST['height'])<1) //if there was no height { print "You did not enter a height."; } else if(strlen($_POST['weight'])<1) //no weight { print "You did not enter a weight."; } else if(strlen($_POST['bodyfat'])<1) //no bodyfat { print "You did not enter a Body Fat Range"; } else if (strlen ($_POST['bodywater'])<1) //no bodywater { print "You did not enter a Body Water Range"; } else if( strlen($_POST['musclemass'])<1) //no musclemass { print "You did not enter a Muscle Mass"; } else if (strlen ($_POST['physiqueratt'])<1) //no physiqueratt { print "You did not enter a Physique Ratings"; } else if (strlen ($_POST['bonemass'])<1) //no bonemass { print "You did not enter a Bone Mass"; } else if (strlen ($_POST['bmr'])<1) //no bmr { print "You did not enter a BMR"; } else if (strlen ($_POST['basalmetabolic'])<1) //no basalmetabolic { print "You did not enter a Basal Metabolic Age"; } else if (strlen ($_POST['visceralfat'])<1) //no visceralfat { print "You did not enter a Visceral Fat"; } else if(strlen($_POST['registrationmonth'] && $_POST['registrationday'] && $_POST['registrationyear'])<1) // no date { print "You did not enter a date of birth"; } else //all fields met { $id=$_GET['id']; $height=$_POST['height']; $weight=$_POST['weight']; $bodyfat=$_POST['bodyfat']; $bodywater=$_POST['bodywater']; $musclemass=$_POST['musclemass']; $physiqueratt=$_POST['physiqueratt']; $bonemass=$_POST['bonemass']; $bmr=$_POST['bmr']; $basalmetabolic=$_POST['basalmetabolic']; $visceralfat=$_POST['visceralfat']; $date=$_POST['registrationyear'] . '-' . $_POST['registrationmonth'] . '-' . $_POST['registrationday']; $insertadmin="INSERT into personalwelness (m_id,height,weight,body_fat,body_water,muscle_mas s,physique_ratt,bone_mass,bmr,basal_metabolic,visc eral_fat,evaluation_date) values ('$id','$height','$weight','$bodyfat','$bodywater','$mus clemass','$physiqueratt','$bonemass','$bmr','$basa lmetabolic','$visceralfat','$date')"; //registering admin in databae echo $insertadmin; $insertadmin2=mysql_query($insertadmin) or die("Could not insert admin"); print "Personal Wellness Successfully Submitted"; } } ?> <form method="post" class="form" action="<?php echo $_SERVER['PHP_SELF'];?>"> <fieldset><legend>Enter Personal Wellness Information in the form below:</legend> <table width="80%" border="0"> <tr> <td width="16%">Height(CM)</td> <td width="2%">:</td> <td width="82%"><label for="height"></label> <input type="text" name="height" id="height" value="<?php if (isset($_POST['height'])) echo $_POST['height'];?>" /></td> </tr> <tr> <td>Weight(KG)</td> <td>:</td> <td><label for="weight"></label> <input type="text" name="weight" id="weight" value="<?php if (isset($_POST['weight'])) echo $_POST['weight'];?>" /></td> </tr> <tr> <td >Body Fat Range</td> <td>:</td> <td><label for="body fat"></label> <input type="text" name="bodyfat" id="bodyfat" value="<?php if (isset($_POST['bodyfat'])) echo $_POST['bodyfat'];?>" ></td> </tr> <tr> <td>Body Water Range(%)</td> <td>:</td> <td><label for="bodywater"></label> <input type="text" name="bodywater" id="bodywater" value="<?php if (isset($_POST['bodywater'])) echo $_POST['bodywater'];?>"/></td> </tr> <tr> <td>Muscle Mass</td> <td>:</td> <td><label for="musclemass"></label> <input type="text" name="musclemass" id="musclemass" value="<?php if (isset($_POST['musclemass'])) echo $_POST['musclemass'];?>"></td> </tr> <tr> <td>Physique Ratings</td> <td>:</td> <td><label for="physiqueratt"></label> <input type="text" name="physiqueratt" id="physiqueratt" value="<?php if (isset($_POST['physiqueratt'])) echo $_POST['physiqueratt'];?>"></td> </tr> <tr> <td>Bone Mass</td> <td>:</td> <td><label for="bonemass"></label> <input type="text" name="bonemass" id="bonemass" value="<?php if (isset($_POST['bonemass'])) echo $_POST['bonemass'];?>" /></td> </tr> <tr> <td>BMR</td> <td>:</td> <td><label for="bmr"></label> <input type="text" name="bmr" id="bmr" value="<?php if (isset($_POST['bmr'])) echo $_POST['bmr'];?>"/></td> </tr> <tr> <td>Basal Metabolic Age</td> <td>:</td> <td><label for="basalmetabolic"></label> <input type="text" name="basalmetabolic" id="basalmetabolic" value="<?php if (isset($_POST['basalmetabolic'])) echo $_POST['basalmetabolic'];?>"></td> </tr> <tr> <td>Visceral Fat</td> <td>:</td> <td><label for="visceralfat"></label> <input type="text" name="visceralfat" id="visceralfat" value="<?php if (isset($_POST['visceralfat'])) echo $_POST['visceralfat'];?>"></td> </tr> <tr> <td>Evaluation Date</td> <td>:</td> <td> <?php echo date_picker("registration")?></td> </tr> </table> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /> </div> </form> <?php function date_picker($name, $startyear=NULL, $endyear=NULL) { if($startyear==NULL) $startyear = date("Y")-100; if($endyear==NULL) $endyear=date("Y")+50; $months=array('','January','February','March','Apr il','May', 'June','July','August', 'September','October','November','December'); // Month dropdown $html="<select name=\"".$name."month\">"; for($i=1;$i<=12;$i++) { $html.="<option value='$i'>$months[$i]</option>"; } $html.="</select> "; // Day dropdown $html.="<select name=\"".$name."day\">"; for($i=1;$i<=31;$i++) { $html.="<option $selected value='$i'>$i</option>"; } $html.="</select> "; // Year dropdown $html.="<select name=\"".$name."year\">"; for($i=$startyear;$i<=$endyear;$i++) { $html.="<option value='$i'>$i</option>"; } $html.="</select> "; return $html; } ?> <?php include ('template/footer.inc'); ?> How can i insert a image in a database and in my images folder using php? 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! Hello Friends, Now i m stuck with simple insert query . here's the code Code: [Select] <?php include_once("conf.php"); $firstName=$_POST['fname']; $lastName=$_POST['lname']; $email=$_POST['email']; $dob=$_POST['dob']; $password=$_POST['pass']; $fname= stripslashes($firstName); $lname=stripslashes($lastName); $mail= mysql_real_escape_string($email); $password= mysql_real_escape_string($password); mysql_select_db('site'); $statement="Insert into Accounts(Name,lastName,emailId,DOB,password) VALUES($fname,$lname,$mail,$dob,$password)"; $query=mysql_real_escape_string($statement); mysql_query($query) or die("Cannot save data:</br> ".mysql_error()); echo "Data Saved Successfully"; ?> Now please explain me why i m getting the following error Cannot save data: 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 '@gmail.com,1988/12/20,password)' at line 1 Any help will be highly appreciated! I've got Code: [Select] for ($i=1; $i<=5; $i++) { if(isset($_POST['partsusedqty'.$i]) && $_POST['partsusedqty'.$i] != "" && $_POST['partsusedqty'.$i] != "0.00") { mysql_query("INSERT INTO partsused (ptnumber, partqty, partdesc, partprice) VALUES ($ticket, '$partsusedqty'.$i, '$partsuseddesc'.$i, '$partsusedprice'.$i)") or die(mysql_error()); } } I need to know the correct formatting to put these variable variables as values in the mysql query. With this particular code, I get the error "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 '.1, ''.1, ''.1)' at line 2" I've tried formatting this an endless number of ways, but I used this particular example because its the one I really thought should work. Everything I've tried that doesn't throw an error put the $partsusedqty in the partqty, partdesc, and partprice fields. Thanks for any help! Hey guys for some reason this code is not working i can't see a problem myself could someone please have a look and point the issue out to me. what i mean by it not working is it won't insert into the database or show a mysql_error. thanks in advance Code: [Select] $guestip = $_SERVER['REMOTE_ADDR']; $time = date('G:i'); $date = date("y-m-d"); $query = mysql_query("SELECT * FROM IP_Address") or die(mysql_error()); while($row = mysql_fetch_assoc($query)){ if($guestip != $row['ip']){ //insert into db. mysql_query("INSERT INTO IP_Address(id, ip, date, time) VALUES(NULL,'$questip','$date','$time')") or die(mysql_error()); echo "inserted in to database"; echo mysql_error(); }else{ // add hit count and update time and date. echo "already in db"; } } guys, im having a problem here thats making me crazy im making a system and i want to insert the current date in the mysql. I have the field called 'data' in the DB, but when i make the code to insert all the other fields, including the 'data', its work perfectly... unless that damn date! $query = "INSERT INTO news (id, titulo, mensagem, data) VALUES (NULL, '$titulo', '$mensagem', 'date(\"d/m/Y\")')"; whats wrong with that? its stores in DB as '0000-00-00'.
Array ( [data] => Array ( [0] => Array ( [latitude] => 22.934566 [longitude] => 79.08728 [type] => county [distance] => 44.328 [name] => Narsinghpur [number] => [postal_code] => [street] => [confidence] => 0.5 [region] => Madhya Pradesh [region_code] => MP [county] => Narsinghpur [locality] => [administrative_area] => [neighbourhood] => [country] => India [country_code] => IND [continent] => Asia [label] => Narsinghpur, India ) ) ) |