Jump to content

Problem with submission


PhdJB

Recommended Posts

<?

// run query 1-16

$result = mysql_query($query);

 

// run query 17

$result = mysql_query($query17);

 

// run query 18

$result = mysql_query($query18);

 

// run query 19

$result = mysql_query($query19);

 

// run query 20

$result = mysql_query($query20);

 

// run query 21

$result = mysql_query($query21);

 

// run query 22

$result = mysql_query($query22);

 

// run query 23

$result = mysql_query($query23);

 

// run query 24

$result = mysql_query($query24);

 

// run query 25

$result = mysql_query($query25);

 

// connect to database //

$dbh = mysql_connect($host, $username, $password, $db);

if (!$dbh) {

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

}

// close transaction //

mysql_close();

?>

 

and than my variables

Here is my actual code now:

 

<?

mysql_query($query);

mysql_query($query17);

mysql_query($query18);

mysql_query($query19);

mysql_query($query20);

mysql_query($query21);

mysql_query($query22);

mysql_query($query23);

mysql_query($query24);

mysql_query($query25);

 

mysql_connect($host, $username, $password, $db);

mysql_close()

?>

a mysql query along with the connection should look something like this:

<?php
mysql_connect($host, $username, $password, $db); //this connects to thte database

$sql = "INSERT INTO TABLENAME (`CELL1`, `CELL2`, `CELL3`, `CELL4`) VALUES ('VALUE1', 'VALUE2', 'VALUE3', 'VALUE3') WHERE `CELL1` = 'VALUE' LIMIT 1"; //this inserts data
if($result = mysql_query($sql)){ //this checks if the insert worked, if so echos to say so
	echo "mysql query successfull";
}else{
	echo "Query failed<br />\n".mysql_error()."\n"; //otherwise it throws up an error
}

mysql_close() //this closes thte connection
?>

you need to change TABLENAME to the name of the table and CELL1, CELL2 etc to thte corresp[onding cel names in thte table for the values.

 

I hope that helps.

What are you actually trying to do? add to a database or remove? or even just read from it?

setup your querys as an array

 

 

$querys[0] = "INSERT INTO table (id) VALUES (null)";
$querys[1] = "INSERT INTO table (id) VALUES (null)";
$querys[2] = "INSERT INTO table (id) VALUES (null)";
$querys[3] = "INSERT INTO table (id) VALUES (null)";

foreach($querys as $query => $structure){
       mysql_query($structure) or die(mysql_error());
}

 

that off the top of my head but i think it will work

yeah, that should work..

Just a slight edit, to how I'd prefer to do it ;)

<?php
mysql_connect($host, $username, $password, $db); //this connects to the database

$querys[0] = "INSERT INTO table (id) VALUES (null)";
$querys[1] = "INSERT INTO table (id) VALUES (null)";
$querys[2] = "INSERT INTO table (id) VALUES (null)";
$querys[3] = "INSERT INTO table (id) VALUES (null)";

foreach($querys as $query => $structure){
if($result = mysql_query($structure)){ //this checks if the insert worked, if so echos to say so
	echo "mysql query successfull";
}else{
	echo "Query failed<br />\n".mysql_error()."\n"; //otherwise it throws up an error
}
}

mysql_close() //this closes thte connection

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.