Closed Thread Icon

Topic awaiting preservation: problems inserting into MySQL table Pages that link to <a href="https://ozoneasylum.com/backlink?for=12598" title="Pages that link to Topic awaiting preservation: problems inserting into MySQL table" rel="nofollow" >Topic awaiting preservation: problems inserting into MySQL table\

 
Author Thread
norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 01-30-2003 02:47

I have made a database called survey and a table called results. The results table has 7 fields: degree, relevance, level, convienence, recommend, add

I'm having problems with the following block of code-

<?php
$degree=4;
$link=mysql_connect("localhost","mysql")
or die("could not connect");

mysql_select_db("survey") or die("could not open database");



function hup(){
$link;
$query="INSERT INTO results (degree,relevance,level,convienence,recommend,add)
VALUES('1','2','3','4','5','6')";
$query or die ("wrong");
echo "ok";

$result=mysql_query("select * from results") or
die(mysql_error());
while ($row=mysql_fetch_array($result)){
echo "<b>Degree:</b>";
echo $row["degree"];
echo "<b>\n";
echo "<b> Course Relevance:</b>";
echo $row["relevance"];
echo "<b>\n";
echo "<b>Level of instrution:</b>";
echo $row["level"];
echo "<b>\n";
echo "<b>Convienence of class times:</b>";
echo $row["convienence"];
echo "<b>\n";
echo "<b>Would recommend courses at SSCC to others:</b>";
echo $row["recommend"];
echo "<br><br>";
echo "<b>Suggested additions to course offerings:</b>";
echo $row["add"];
}
mysql_free_result($result);
}
hup();
?>
When I run this, instead of seeing the values 1,2,3,4,5,6 printed to the browser, all I see is "ok". Also, when I look at my database with PHP MyAdmin nothing has been inserted to results.

Any clues as to where I've gone wrong with this? I'm connecting to the db just fine, but not much seems to happen after that.



/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 01-30-2003 03:07

I think you need to make $link global in your function like so:

global $link;

You also need to change this line:

$query or die ("wrong");

to

$result = mysql_query($query) or die ("wrong");

so the top part of your function would look like this:

function hup(){
global $link;
$query="INSERT INTO results (degree,relevance,level,convienence,recommend,add)
VALUES('1','2','3','4','5','6')";
$result = mysql_query($query) or die ("wrong");
echo "ok";


-Butcher-


[This message has been edited by butcher (edited 01-30-2003).]

norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 01-30-2003 04:27

added the changes . No luck. It's still broken.

Well, thanks for the help, I think you have pointed me in the right direction.
I'm going to walk away from this for a brief time, to get centered, and then attack this little problem once again.

/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 01-30-2003 21:05

Try putting a mysql_error() in your die statement where you currently have ("wrong") and see what it tells you.

-Butcher-

« BackwardsOnwards »

Show Forum Drop Down Menu