Jump to content

[SOLVED] Cannot INSERT data


ShaolinF

Recommended Posts

Hi Guys

 

I am trying to insert some data into the database but its not working. The db connects and everything and I receive no errors. See code below:

 

$id = $_POST['id'];

$name = $_POST['name'];

 

//Connect to DB

connect();

$insert = mysql_query("INSERT INTO petition values('','".$id."','".$name.")");

 

function connect() {

$link = mysql_connect('localhost', 'petitUsr', '12345678a');

if (!$link) {

die('Could not connect to database: ' . mysql_error());

}

$selected = mysql_select_db('petition',$link) or die(mysql_error());

}

 

 

Anyone know what Im doing wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/142290-solved-cannot-insert-data/
Share on other sites

add or die

 

Lol... Read it aloud and listen how it sounds. Better yet shout it out: ADD OR DIE!!! :D

 

Heh... anyway...

What Blade meant was

add

or die(mysql_error()); 

after your query

 

$insert = mysql_query("INSERT INTO petition values('','".$id."','".$name.")") or die(mysql_error());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.