Php/mysql Insert Issues - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Php/mysql Insert Issues (1180 Views)
1 Reply
| Php/mysql Insert Issues by IronFist(op): 11:18am On Mar 20, 2007 |
PHP/MySQL gurus.I need help with PHP/MySQL. I created a form but every time i send stuff through the form it doesn't insert nothing.I'm attaching the SQL for my table CREATE TABLE `albion`.`article` ( Here's the code for my PHP form
What exactly am i getting wrong?Appreciate the help fellaz. |
| Re: Php/mysql Insert Issues by oleku(m): 4:01pm On Mar 26, 2007 |
I have been able to edit your code. Try this : <? if(isset($_POST['Save Article'])) { $db = mysql_connect($host,$username,$password); // Databse Host Username and password mysql_select_db($database,$db); // Database name $Query = sprintf("INSERT INTO article (topic,author,article) VALUES('%s','%s','%s')",$_POST['Topic'],$_POST['Author'],$_POST['Article']); if ($result = mysql_query($Query)) { echo '<center><b>Article added to the database</b></center><br>'; } else { exit('<center>Sorry, there was an error saving to the database</center>'); } } ?> oleku www.oleku.org |
| Re: Php/mysql Insert Issues by naijaguru(m): 4:41pm On Mar 27, 2007 |
The code posted by Oleku should work but. However one needs to clarify somethings here. IronFist. You were trying to use the DBconnect object from PEAR, but u didnt seem to understand how it works. You should try avoiding using PEAR if u are a rookie in PHP. Use the 'native' mysql_ functions in php 1. To create table/database in PHP, use PhpMyAdmin - as a starter. 2. To Insert data, I'd advice u to run your queries this way. $sql = "INSERT INTO table SET field1='value1', field2 = 'value2', field3='value3'"; instead of $sql = "INSERT INTO table (field1, field2, field3) VALUES (value1, value2, value3)"; 3. And make sure u always use the addslashes() function for your queries and stripslashes() for output |
How To Make a DESKTOP Executable Software Using PHP,MYSQL,SQLITE • Insert Image Into Mysql • Php/mysql Help:how To Run Sql Query From A Link • 2 • 3 • 4
C#.net Fans: • Computer Networking Guys Take A Look At This Android App • Has Anyone Tried The New Sublime-text 3 Beta version?
;?></center></td>