Jump to content

rebeat

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rebeat's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. yes, but does the statement mysql_close(); close all database connections? or do i need to specify the connection, ie: mysql_close(db); ?
  2. does mysql_connect() close the mysql connection? do i need to enter any value between () ? thx.
  3. HI, I am wondering if it is possible to dynamically insert data from a simple data file as the database (not using mysql). Basically there are 10 items with 3 variables per item (there may be additional fields), ie: ITEM, Value 1, Value 2. Part# 1 - 100 125 AHDYE5 2 - 125 150 KIERYT 3 - 250 275 KDHDIE 4 - 350 375 IYWE62 5 - 400 450 MNAITY etc. I would like to dynamically insert say Value 2 for Item 3 on a php page, so any changes made to the datafile are updated dynamically. Any ideas? Regards.
  4. Hi, Just wondering what the best method to insert a value from a database is. Does it need to include the username/password to grab the value, because my site has a lot of items, each page would need to update the price for that item from the database, so one visitor could visit 30 pages, each page has to open the database to extract. Does this slow the server down? this is the method i am looking at: <?php $db = mysql_connect("localhost", "user", "pass"); mysql_select_db("products",$db); $result = mysql_query("SELECT * FROM products WHERE id=4", $db); $myrow = mysql_fetch_array($result); ?> <?php echo "Our Special Price is <b>$".$myrow["special2"]."</b>" ?> <?php mysql_close() ?> Is this the best way? also is it a good idea to include <?php mysql_close() ?> in the footer to prevent it remaining open? Cheers.
  5. I used $id=$_POST['id'] which found the id, i still have problems tho but i need to move on as it is a time sensitive issue. cheers.
  6. the database ($db) is "dbname" and the table is "products", executed as mysql_db_query($db,"$SQL",$cid); i also tried mysql_select_db($db, $cid); but sadly that didn't help. i'm still lost. :-\ really hope i get some progress, ive been days now on this issue.
  7. H, i have a simple database i wish to UPDATE via a form using php 5 / mysql 5. The way i call the item to edit is via: /manageedit.php?id=3 (example <a href=http://agtrac.com.au/test1/manageedit.php?id=3>here</a>) this should display the current values from the database but is not showing anything and upon submit returns: ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'special2 = '' WHERE id =' at line 1 UPDATE products SET title = '', description = '', retail = '', special = '' special2 = '' WHERE id = I need the valued service of an expert to point out to me what the missing link is. I have spent days going around in circles trying various methods from database tutorials, with no success. If someone can assist i would be very greatful, hope i have included enough info. The current source code is below: <a href=http://agtrac.com.au/test1/manageedit.php?id=3>manageedit.php</a> <?php $usr = "user"; $pwd = "pass"; $db = "dbname"; $host = "localhost"; #connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> <HTML> <HEAD> <TITLE>Update Link</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"> <TABLE WIDTH="100%"> <TR><TD><FONT SIZE=5><B> Update Link </B> </FONT></TD> <TD VALIGN=TOP ALIGN=RIGHT><FONT SIZE="-1"><A HREF="javascript: self.close()">Close Window</A></FONT></TD> </TR></TABLE> <? # processed when form is submitted back onto itself if (isset($_POST['submit'])) { # setup SQL statement $SQL = " UPDATE products SET"; $SQL = $SQL . " title = '$title', "; $SQL = $SQL . " description = '$description', "; $SQL = $SQL . " retail = '$retail', "; $SQL = $SQL . " special = '$special' "; $SQL = $SQL . " special2 = '$special2' "; $SQL = $SQL . " WHERE id = $id "; # execute SQL statement $result = mysql_db_query($db,"$SQL",$cid); # check for errors if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo ("<P><B> Link Updated</B></P>\n"); } else { # display edit form (not post method) # setup SQL statement to retrieve link # that we want to edit $SQL = " SELECT * FROM products "; $SQL = $SQL . " WHERE id = $id "; # execute SQL statement $ret = mysql_select_db($db,$SQL,$cid); # retrieve values $row = mysql_fetch_array($ret); $title = $row["title"]; $description = $row["description"]; $retail = $row["retail"]; $special = $row["special"]; $special2 = $row["special2"]; ?> <FORM NAME="fa" ACTION="manageedit.php" METHOD="POST"> <INPUT TYPE="hidden" NAME="id" VALUE="<?php echo("$id"); ?>"> <TABLE> <TR><TD><B>Title: </B> </TD><TD><INPUT TYPE="text" NAME="category" VALUE="<?php echo("$title"); ?>" SIZE=70></TD></TR> <TR><TD><B>Description:</B> </TD><TD><TEXTAREA NAME="description" ROWS=5 COLS=40><?php echo("$description"); ?></TEXTAREA></TD></TR> <TR><TD><B>Retail: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$retail"); ?>" SIZE=40></TD></TR> <TR><TD><B>Special: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$special"); ?>" SIZE=40></TD></TR> <TR><TD><B>Special2: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$special2"); ?>" SIZE=40></TD></TR> <TR><TH COLSPAN=2><P><INPUT TYPE="submit" name="submit" VALUE="Update Link"></P></TH></TR> </TABLE> </FORM> <?php } mysql_close($cid); ?> </BODY> </HTML>
  8. i forgot to add, the delete link in "<a href=http://agtrac.com.au/test1/manage.php>manage.php</a> doesn't actually delete and once i click on an entry to jump to "<a href=http://agtrac.com.au/test1/manageedit.php>manageedit.php</a>" the "update" link returns an error. Feel free to use the submit button, it is all for testing purposes. the user/pass combinations i am using are all correct, i am able to add links <a href=http://agtrac.com.au/test1/insert_link.php>here</a>. Regards.
  9. i have another issue regarding the same database, i wish to edit the data, i have two files: http://agtrac.com.au/test1/manage.php (to select the entry to edit) http://agtrac.com.au/test1/manageedit.php (should display the current values) I am using PHP5, my problem is, the form is blank but should echo the database values. database table name is "products" Source for manage.php <?php $usr = "usr"; $pwd = "pass"; $db = "db"; $host = "localhost"; $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } if ($task=="del") { $SQL = " DELETE FROM products "; $SQL = $SQL . " WHERE id = $id "; mysql_db_query($db, $SQL, $cid); } ?> <HTML> <HEAD> <TITLE>Manage Links</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" > <H1>Edit Links</H1> <?php $SQL = " SELECT * FROM products "; $retid = mysql_db_query($db, $SQL, $cid); if (!$retid) { echo( mysql_error()); } else { echo ("<P><TABLE CELLPADDING=4>\n"); while ($row = mysql_fetch_array($retid)) { $title = $row["title"]; $id = $row["id"]; echo ("<TR>"); echo ("<TD>$title</TD>\n"); echo ("<TD><A HREF=\"manageedit.php?id=$id\">Edit</A></TD>"); echo ("<TD><A HREF=\"manage.php?id=$id&task=del\">Delete</A></TD>"); echo ("</TR>"); } echo ("</TABLE>"); } ?> </BODY> </HTML> Source for manageedit.php <?php $usr = "user"; $pwd = "pass"; $db = "dbname"; $host = "localhost"; #connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> <HTML> <HEAD> <TITLE>Update Link</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"> <TABLE WIDTH="100%"> <TR><TD><FONT SIZE=5><B> Update Link </B> </FONT></TD> <TD VALIGN=TOP ALIGN=RIGHT><FONT SIZE="-1"><A HREF="javascript: self.close()">Close Window</A></FONT></TD> </TR></TABLE> <? # processed when form is submitted back onto itself if (isset($_POST['submit'])) { # setup SQL statement $SQL = " UPDATE products SET"; $SQL = $SQL . " title = '$title', "; $SQL = $SQL . " description = '$description', "; $SQL = $SQL . " retail = '$retail', "; $SQL = $SQL . " special = '$special' "; $SQL = $SQL . " special2 = '$special2' "; $SQL = $SQL . " WHERE id = $id "; # execute SQL statement $result = mysql_db_query($db,"$SQL",$cid); # check for errors if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo ("<P><B> Link Updated</B></P>\n"); } else { # display edit form (not post method) # setup SQL statement to retrieve link # that we want to edit $SQL = " SELECT * FROM products "; $SQL = $SQL . " WHERE id = $id "; # execute SQL statement $ret = mysql_select_db($db,$SQL,$cid); # retrieve values $row = mysql_fetch_array($ret); $title = $row["title"]; $description = $row["description"]; $retail = $row["retail"]; $special = $row["special"]; $special2 = $row["special2"]; ?> <FORM NAME="fa" ACTION="manageedit.php" METHOD="POST"> <INPUT TYPE="hidden" NAME="id" VALUE="<?php echo("$id"); ?>"> <TABLE> <TR><TD><B>Title: </B> </TD><TD><INPUT TYPE="text" NAME="category" VALUE="<?php echo("$title"); ?>" SIZE=70></TD></TR> <TR><TD><B>Description:</B> </TD><TD><TEXTAREA NAME="description" ROWS=5 COLS=40><?php echo("$description"); ?></TEXTAREA></TD></TR> <TR><TD><B>Retail: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$retail"); ?>" SIZE=40></TD></TR> <TR><TD><B>Special: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$special"); ?>" SIZE=40></TD></TR> <TR><TD><B>Special2: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$special2"); ?>" SIZE=40></TD></TR> <TR><TH COLSPAN=2><P><INPUT TYPE="submit" name="submit" VALUE="Update Link"></P></TH></TR> </TABLE> </FORM> <?php } mysql_close($cid); ?> </BODY> </HTML> I would also like to combine the two pages into one if possible (add/edit and display all) but this isn't as important as getting the form to display the values from the database. Cheers.
  10. thanks valtido and thorpev, the line if (isset($_POST['submit'])) { did the trick. valtido, i wasn't asking people to guess the problem, as i stated, the code i used was "not submitting the data from the form to the database" its all ok now, you code thank you. As for security, i found some code, but how do i make this a single php code like the one valtido created? <?php // Define your username and password $username = "someuser"; $password = "somepassword"; if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { ?> <h1>Login</h1> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><label for="txtUsername">Username:</label> <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> <p><label for="txtpassword">Password:</label> <br /><input type="password" title="Enter your password" name="txtPassword" /></p> <p><input type="submit" name="Submit" value="Login" /></p> </form> <?php } else { ?> <p>This is the protected page. Your private content goes here.</p> <?php } ?> Thank you
  11. HI, i used <?php in my code. I don't get any error, i just submit the form then it returns a new form, nothing is added to the database, if you see the code, you will see there should be a confirmation note after successful addition of an entry... echo ("<P><B>New Link Added</B></P>\n"); but i don't get that, just a loop that never adds the entry.
  12. Hi, i posted this on the php section but no one replied so i am thinking it may be more suitable to mysql.. rather than do a repost, the topic is here: http://www.phpfreaks.com/forums/index.php/topic,138113.0.html Hope someone can assist me. I don't think it would be hard to anyone who knows a little about php5/mysql5 Cheers.
  13. can anyone help me? the source php can be found at: http://blazonry.com/scripting/linksdb/insert_link.phps
  14. Hi, I am new to php and mysql, so am going the php tutorial route. I found a nice tutorial but i think it is old and doesn't seem to be working with my PHP5 server.. ie: it is not submitting the data from the form to the database and incrementing. The tutorial i am using is: http://blazonry.com/scripting/linksdb/insert_data.php Could someone please advise why the code is not working in PHP5/mysql5. I created the table (as shown) and used the register_globals vlues as they are off (ie: $anyvaluehere = $_POST['anyvaluehere'] My phpinfo file: http://yournetworth.org/phpinfo.php Hope someone can assist, i am only after a simple database i can add, edit values to so i can call them into a page dynamically. Regards, Wayne.
×
×
  • 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.