Re: Insert MySQL/PHP

From: Date: Sun, 04 Aug 2002 21:27:49 +0000
Subject: Re: Insert MySQL/PHP
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-20984@lists.php.net to get a copy of this message
Here both pages, the View and the Insert. www.idahobydesign.com/asta.php I thought it was a permission error in MySQL or file error but now after 8 hours of this I have no clue. It should error out if there is no connection or it the insert fails but I get neither. Many thanks Mike <p>Sites Uploaded to are below</p> <p>To add to the list <a href="astainsert.php">astainsert</a></p> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <p>&nbsp;</p> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> <?php // create connection $connection = mysql_connect("localhost","me","mypass"); // test connection if (!$connection) { echo "Couldn't make a connection!"; exit; } // select database $db = mysql_select_db("asta", $connection); // test selection if (!$db) { echo "Couldn't select database!"; exit; } // create SQL statement $sql = "SELECT * FROM skywire"; // execute SQL query and get result $sql_result = mysql_query($sql,$connection); // start results formatting echo "<TABLE BORDER=1>"; echo "<TR><TH>Site name</TH><TH>Sent_link</TH><TH>Notes</TH><TH>Day</TH><TH>ASTA</TH><TH>astawireless</TH><TH>astaio</TH></TR>"; // format results by row while ($row = mysql_fetch_array($sql_result)) { $sitename = $row["sitename"]; $sent_link = $row["sent_link"]; $notes = $row["notes"]; $day = $row["day"]; $asta = $row["asta"]; $astawireless = $row["astawireless"]; $astaio = $row["astaio"]; echo "<TR><TD>$sitename</TD><TD>$sent_link</TD><TD>$notes</TD><TD>$day</TD><TD>$asta</TD><TD>$astawireless</TD><TD>$astaio</TD></TR>"; } echo "</TABLE>"; // free resources and close connection mysql_free_result($sql_result); mysql_close($connection); ?> ------Next page <? // if form has not been submitted, display form if (!$submit) { ?> <html> <head> <basefont face=Arial> <h3>Enter the upload sites:</h3> <form method="POST" action="astainsert.php"> <table> <tr> <td> sitename </td> <td> <input name="sitename" length="10" maxlength="50"> </td> </tr> <tr> <td> sent link </td> <td> <input name="sent_link" length="30" maxlength="30"> </td> </tr> <tr> <td> notes </td> <td> <input name="notes" length="60"> </td> <tr> <td> asta </td> <td> <input name="asta" length="30"> </td> </tr> <tr> <td> astawireless </td> <td> <input name="astawireless" length="30" maxlength="30"> </td> </tr> <tr> <td> astaio </td> <td> <input name="astaio" length="30" maxlength="30"> </td> </tr> <tr> <td> day 2001-07-01 </td> <td> <input name="day" length="11" maxlength="11"> </td> </tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="Submit"> </td> </tr> </table> </form> </body> </html> <? } // or process form input else { ?> <?php // connect to database $connection = mysql_connect("localhost", "me", "mypass") or die("Invalid server or user"); // select database mysql_select_db("asta",$connection); // formulate and run query $query = "insert into skywire(sitename,sent_link,notes,asta,astawireless,astaio,day) values('$sitename','$sent_link','$notes','$asta','$astawireless','$astaio','$day')"; $result = mysql_query($query,$connection) or die("Error in query"); ?> <html> <head> <basefont face=Arial> </head> <body> <center> <P>Success!</43> <table> <tr> <td> <?php echo $username; ?> uploads have been saved. </td> </tr> <p>Return to the list <a href="asta.php">asta list</a></p> </center> </body> </html> <? } ?> On Sun, 2002-08-04 at 14:51, Jason Wong wrote: > On Monday 05 August 2002 04:55, Mike wrote: > > Using RH 7.3 PHP 4.2.2 MySQL 3.23.51 MySQL Client 3.23.29 Apache 1.3.26 > > > > I used the LAMP script to compile and build all and all of the PHP works > > except for inserts. > > > > I can insert from MyCC, phpMyAdmin, command line just fine but when > > trying to use a php file that I used to use it will not insert or show > > any errors.PS I like MyCC!!! Very nice!! > > > > I made the file chmod 666 and tried both my root and my normal user > > accounts. > > > > Here's the code.Note: I changed the names to post so one might be > > wrong<G> > > When posting code you should always copy & paste and try not to change > anything unless absolutely necessary (stuff like passwords). > > [snip] > > > // formulate and run query > > $query = "insert into > > skywire(sitename,sent_link,notes,home,wireless,wired,day) > > > > values('$sitename','$sent_link','$notes','$home','$wireless','$wired','$day > >')"; > > > > $result = mysql_query($query,$connection) or die("Error in > > query"); > > What does $query contain? > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > > > /* > I always wake up at the crack of ice. > -- Joe E. Lewis > */ > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.db (#20984) next »